* [PATCH] thermal: ti-soc-thermal: avoid dereferencing ERR_PTR
@ 2020-04-23 12:57 Sudip Mukherjee
2020-04-23 14:31 ` Amit Kucheria
0 siblings, 1 reply; 2+ messages in thread
From: Sudip Mukherjee @ 2020-04-23 12:57 UTC (permalink / raw)
To: Eduardo Valentin, Keerthy, Zhang Rui, Daniel Lezcano, Amit Kucheria
Cc: linux-kernel, linux-pm, linux-omap, 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 a error code inside ERR_PTR.
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
---
drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
index d3e959d01606..1e2bf1f22dd1 100644
--- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
+++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
@@ -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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] thermal: ti-soc-thermal: avoid dereferencing ERR_PTR
2020-04-23 12:57 [PATCH] thermal: ti-soc-thermal: avoid dereferencing ERR_PTR Sudip Mukherjee
@ 2020-04-23 14:31 ` Amit Kucheria
0 siblings, 0 replies; 2+ messages in thread
From: Amit Kucheria @ 2020-04-23 14:31 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Eduardo Valentin, Keerthy, Zhang Rui, Daniel Lezcano, LKML,
Linux PM list, linux-omap
On Thu, Apr 23, 2020 at 6:27 PM Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:
>
> 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.
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, possibly
ti_thermal_report_sensor_temperature?
>
> Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
> ---
> drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> index d3e959d01606..1e2bf1f22dd1 100644
> --- a/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> +++ b/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
> @@ -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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-23 14:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 12:57 [PATCH] thermal: ti-soc-thermal: avoid dereferencing ERR_PTR Sudip Mukherjee
2020-04-23 14:31 ` Amit Kucheria
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).