Skip to contentSkip to conversation

thermal: ti-soc-thermal: avoid dereferencing ERR_PTR

PATCH In review Sudip Mukherjee 3 participants 3 messages Apr 24, 2020 – Apr 29, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 thermal: ti-soc-thermal: avoid dereferencing ERR_PTR

On error the function ti_bandgap_get_sensor_data() returns the error code in ERR_PTR() but we only checked if the return value is NULL or not. And, so we can dereference an error code inside ERR_PTR. While at it, convert a check to IS_ERR_OR_NULL.

---
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +3 -3
index d3e959d01606..85776db4bf34 100644
@@ -169,7 +169,7 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id,
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (!data || IS_ERR(data))
+	if (!IS_ERR_OR_NULL(data))
 		data = ti_thermal_build_data(bgp, id);
 
 	if (!data)
@@ -196,7 +196,7 @@ int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id)
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (data && data->ti_thermal) {
+	if (!IS_ERR_OR_NULL(data) && data->ti_thermal) {
 		if (data->our_zone)
 			thermal_zone_device_unregister(data->ti_thermal);
 	}
@@ -262,7 +262,7 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (data) {
+	if (!IS_ERR_OR_NULL(data)) {
 		cpufreq_cooling_unregister(data->cool_dev);
 		if (data->policy)
 			cpufreq_cpu_put(data->policy);
Signature · 1 line
2.11.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Sudip Mukherjee

On error the function ti_bandgap_get_sensor_data() returns the error code in ERR_PTR() but we only checked if the return value is NULL or not. And, so we can dereference an error code inside ERR_PTR. While at it, convert a check to IS_ERR_OR_NULL.

Quoted 38 lines
---
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +3 -4
index d3e959d01606..85776db4bf34 100644
@@ -169,7 +169,7 @@ int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id,
 
        data = ti_bandgap_get_sensor_data(bgp, id);
 
-       if (!data || IS_ERR(data))
+       if (!IS_ERR_OR_NULL(data))
                data = ti_thermal_build_data(bgp, id);
 
        if (!data)
@@ -196,7 +196,7 @@ int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id)
 
        data = ti_bandgap_get_sensor_data(bgp, id);
 
-       if (data && data->ti_thermal) {
+       if (!IS_ERR_OR_NULL(data) && data->ti_thermal) {
                if (data->our_zone)
                        thermal_zone_device_unregister(data->ti_thermal);
        }
@@ -262,7 +262,7 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
 
        data = ti_bandgap_get_sensor_data(bgp, id);
 
-       if (data) {
+       if (!IS_ERR_OR_NULL(data)) {
                cpufreq_cooling_unregister(data->cool_dev);
                if (data->policy)
                        cpufreq_cpu_put(data->policy);
--

2.11.0

#2 lore raw
In reply to Sudip Mukherjee
Quoted 7 lines · Sudip Mukherjee

On error the function ti_bandgap_get_sensor_data() returns the error code in ERR_PTR() but we only checked if the return value is NULL or not. And, so we can dereference an error code inside ERR_PTR. While at it, convert a check to IS_ERR_OR_NULL.

---

Applied thanks

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog