thermal: ti-soc-thermal: avoid dereferencing ERR_PTR
Subsystems (2)
PATCH 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 a error code inside ERR_PTR.
Signed-off-by Sudip Mukherjee <[email protected]>
--- drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +1 -1
@@ -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); }
Signature · 1 line
2.11.0
Quoted 4 lines · Sudip Mukherjee
On error the function
ti_bandgap_get_sensor_data()returns the error code inERR_PTR()but we only checked if the return value is NULL or not. And, so we can dereference a error code insideERR_PTR.
Typo, s/a error/an error/
I see other uses of ti_bandgap_set_sensor_data() in the same file that could use similar checks.
e.g. ti_thermal_unregister_cpu_cooling, possiblyti_thermal_report_sensor_temperature?
Quoted 24 lines
Signed-off-by Sudip Mukherjee <[email protected]>--- drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/thermal/ti-soc-thermal/ti-thermal-common.c +1
-2@@ -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); } --2.11.0