diff options
author | Eduardo Valentin <eduardo.valentin@ti.com> | 2013-05-29 11:07:43 -0400 |
---|---|---|
committer | Zhang Rui <rui.zhang@intel.com> | 2013-06-12 22:14:00 -0400 |
commit | 0c12b5ac82fbae6903237997677c228089569ace (patch) | |
tree | 8e5b4f2d22f90cdc8959d98796cc0110963d5a95 | |
parent | ba0049eacc59831f4018060dc30fb7c818421a75 (diff) |
thermal: ti-soc-thermal: remove usage of IS_ERR_OR_NULL
This patch changes the driver to avoid the usage of IS_ERR_OR_NULL()
macro. This macro can lead to dangerous results, like returning
success (0) during a failure scenario (NULL pointer handling).
For this reason this patch is changing the driver after
revisiting the code. These are the cases:
i. For cases in which IS_ERR_OR_NULL() is used for checking
return values of functions that returns either PTR_ERR()
or a valid pointer, it has been translated to IS_ERR() check only.
ii. For cases that a NULL check is still needed, it has been
translated to if (!ptr || IS_ERR(ptr)).
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
-rw-r--r-- | drivers/thermal/ti-soc-thermal/ti-bandgap.c | 10 | ||||
-rw-r--r-- | drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 15 |
2 files changed, 14 insertions, 11 deletions
diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c index 219c051d2e68..3f3c512445bb 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c | |||
@@ -469,7 +469,7 @@ static inline int ti_bandgap_validate(struct ti_bandgap *bgp, int id) | |||
469 | { | 469 | { |
470 | int ret = 0; | 470 | int ret = 0; |
471 | 471 | ||
472 | if (IS_ERR_OR_NULL(bgp)) { | 472 | if (!bgp || IS_ERR(bgp)) { |
473 | pr_err("%s: invalid bandgap pointer\n", __func__); | 473 | pr_err("%s: invalid bandgap pointer\n", __func__); |
474 | ret = -EINVAL; | 474 | ret = -EINVAL; |
475 | goto exit; | 475 | goto exit; |
@@ -1197,7 +1197,7 @@ int ti_bandgap_probe(struct platform_device *pdev) | |||
1197 | int clk_rate, ret = 0, i; | 1197 | int clk_rate, ret = 0, i; |
1198 | 1198 | ||
1199 | bgp = ti_bandgap_build(pdev); | 1199 | bgp = ti_bandgap_build(pdev); |
1200 | if (IS_ERR_OR_NULL(bgp)) { | 1200 | if (IS_ERR(bgp)) { |
1201 | dev_err(&pdev->dev, "failed to fetch platform data\n"); | 1201 | dev_err(&pdev->dev, "failed to fetch platform data\n"); |
1202 | return PTR_ERR(bgp); | 1202 | return PTR_ERR(bgp); |
1203 | } | 1203 | } |
@@ -1213,17 +1213,19 @@ int ti_bandgap_probe(struct platform_device *pdev) | |||
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | bgp->fclock = clk_get(NULL, bgp->conf->fclock_name); | 1215 | bgp->fclock = clk_get(NULL, bgp->conf->fclock_name); |
1216 | ret = IS_ERR_OR_NULL(bgp->fclock); | 1216 | ret = IS_ERR(bgp->fclock); |
1217 | if (ret) { | 1217 | if (ret) { |
1218 | dev_err(&pdev->dev, "failed to request fclock reference\n"); | 1218 | dev_err(&pdev->dev, "failed to request fclock reference\n"); |
1219 | ret = PTR_ERR(bgp->fclock); | ||
1219 | goto free_irqs; | 1220 | goto free_irqs; |
1220 | } | 1221 | } |
1221 | 1222 | ||
1222 | bgp->div_clk = clk_get(NULL, bgp->conf->div_ck_name); | 1223 | bgp->div_clk = clk_get(NULL, bgp->conf->div_ck_name); |
1223 | ret = IS_ERR_OR_NULL(bgp->div_clk); | 1224 | ret = IS_ERR(bgp->div_clk); |
1224 | if (ret) { | 1225 | if (ret) { |
1225 | dev_err(&pdev->dev, | 1226 | dev_err(&pdev->dev, |
1226 | "failed to request div_ts_ck clock ref\n"); | 1227 | "failed to request div_ts_ck clock ref\n"); |
1228 | ret = PTR_ERR(bgp->div_clk); | ||
1227 | goto free_irqs; | 1229 | goto free_irqs; |
1228 | } | 1230 | } |
1229 | 1231 | ||
diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c index 8e67ebf98404..4c5f55c37349 100644 --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c | |||
@@ -101,7 +101,7 @@ static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal, | |||
101 | 101 | ||
102 | pcb_tz = data->pcb_tz; | 102 | pcb_tz = data->pcb_tz; |
103 | /* In case pcb zone is available, use the extrapolation rule with it */ | 103 | /* In case pcb zone is available, use the extrapolation rule with it */ |
104 | if (!IS_ERR_OR_NULL(pcb_tz)) { | 104 | if (!IS_ERR(pcb_tz)) { |
105 | ret = thermal_zone_get_temp(pcb_tz, &pcb_temp); | 105 | ret = thermal_zone_get_temp(pcb_tz, &pcb_temp); |
106 | if (!ret) { | 106 | if (!ret) { |
107 | tmp -= pcb_temp; /* got a valid PCB temp */ | 107 | tmp -= pcb_temp; /* got a valid PCB temp */ |
@@ -124,7 +124,7 @@ static int ti_thermal_bind(struct thermal_zone_device *thermal, | |||
124 | struct ti_thermal_data *data = thermal->devdata; | 124 | struct ti_thermal_data *data = thermal->devdata; |
125 | int id; | 125 | int id; |
126 | 126 | ||
127 | if (IS_ERR_OR_NULL(data)) | 127 | if (!data || IS_ERR(data)) |
128 | return -ENODEV; | 128 | return -ENODEV; |
129 | 129 | ||
130 | /* check if this is the cooling device we registered */ | 130 | /* check if this is the cooling device we registered */ |
@@ -146,7 +146,7 @@ static int ti_thermal_unbind(struct thermal_zone_device *thermal, | |||
146 | { | 146 | { |
147 | struct ti_thermal_data *data = thermal->devdata; | 147 | struct ti_thermal_data *data = thermal->devdata; |
148 | 148 | ||
149 | if (IS_ERR_OR_NULL(data)) | 149 | if (!data || IS_ERR(data)) |
150 | return -ENODEV; | 150 | return -ENODEV; |
151 | 151 | ||
152 | /* check if this is the cooling device we registered */ | 152 | /* check if this is the cooling device we registered */ |
@@ -282,6 +282,7 @@ static struct ti_thermal_data | |||
282 | data->sensor_id = id; | 282 | data->sensor_id = id; |
283 | data->bgp = bgp; | 283 | data->bgp = bgp; |
284 | data->mode = THERMAL_DEVICE_ENABLED; | 284 | data->mode = THERMAL_DEVICE_ENABLED; |
285 | /* pcb_tz will be either valid or PTR_ERR() */ | ||
285 | data->pcb_tz = thermal_zone_get_zone_by_name("pcb"); | 286 | data->pcb_tz = thermal_zone_get_zone_by_name("pcb"); |
286 | INIT_WORK(&data->thermal_wq, ti_thermal_work); | 287 | INIT_WORK(&data->thermal_wq, ti_thermal_work); |
287 | 288 | ||
@@ -295,7 +296,7 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id, | |||
295 | 296 | ||
296 | data = ti_bandgap_get_sensor_data(bgp, id); | 297 | data = ti_bandgap_get_sensor_data(bgp, id); |
297 | 298 | ||
298 | if (IS_ERR_OR_NULL(data)) | 299 | if (!data || IS_ERR(data)) |
299 | data = ti_thermal_build_data(bgp, id); | 300 | data = ti_thermal_build_data(bgp, id); |
300 | 301 | ||
301 | if (!data) | 302 | if (!data) |
@@ -306,7 +307,7 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id, | |||
306 | OMAP_TRIP_NUMBER, 0, data, &ti_thermal_ops, | 307 | OMAP_TRIP_NUMBER, 0, data, &ti_thermal_ops, |
307 | NULL, FAST_TEMP_MONITORING_RATE, | 308 | NULL, FAST_TEMP_MONITORING_RATE, |
308 | FAST_TEMP_MONITORING_RATE); | 309 | FAST_TEMP_MONITORING_RATE); |
309 | if (IS_ERR_OR_NULL(data->ti_thermal)) { | 310 | if (IS_ERR(data->ti_thermal)) { |
310 | dev_err(bgp->dev, "thermal zone device is NULL\n"); | 311 | dev_err(bgp->dev, "thermal zone device is NULL\n"); |
311 | return PTR_ERR(data->ti_thermal); | 312 | return PTR_ERR(data->ti_thermal); |
312 | } | 313 | } |
@@ -343,7 +344,7 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) | |||
343 | struct ti_thermal_data *data; | 344 | struct ti_thermal_data *data; |
344 | 345 | ||
345 | data = ti_bandgap_get_sensor_data(bgp, id); | 346 | data = ti_bandgap_get_sensor_data(bgp, id); |
346 | if (IS_ERR_OR_NULL(data)) | 347 | if (!data || IS_ERR(data)) |
347 | data = ti_thermal_build_data(bgp, id); | 348 | data = ti_thermal_build_data(bgp, id); |
348 | 349 | ||
349 | if (!data) | 350 | if (!data) |
@@ -356,7 +357,7 @@ int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) | |||
356 | 357 | ||
357 | /* Register cooling device */ | 358 | /* Register cooling device */ |
358 | data->cool_dev = cpufreq_cooling_register(cpu_present_mask); | 359 | data->cool_dev = cpufreq_cooling_register(cpu_present_mask); |
359 | if (IS_ERR_OR_NULL(data->cool_dev)) { | 360 | if (IS_ERR(data->cool_dev)) { |
360 | dev_err(bgp->dev, | 361 | dev_err(bgp->dev, |
361 | "Failed to register cpufreq cooling device\n"); | 362 | "Failed to register cpufreq cooling device\n"); |
362 | return PTR_ERR(data->cool_dev); | 363 | return PTR_ERR(data->cool_dev); |