linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones
@ 2023-03-28  3:10 Chen-Yu Tsai
  2023-04-01 20:34 ` Daniel Lezcano
  0 siblings, 1 reply; 4+ messages in thread
From: Chen-Yu Tsai @ 2023-03-28  3:10 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria, Zhang Rui
  Cc: Chen-Yu Tsai, Matthias Brugger, AngeloGioacchino Del Regno,
	Balsam CHIHI, linux-pm, linux-arm-kernel, linux-mediatek

It's possible for some sensors or thermal zones to not be registered,
either because they are unused or not fully declared in the device tree.
Nevertheless the driver enables interrupts for all sensors. If an
interrupt happens for an not-registered sensor, the driver would end up
updating a non-existent thermal zone, which leads to a NULL pointer
dereference.

Change it so that only registered thermal zones get updated.

Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/thermal/mediatek/lvts_thermal.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index d87d3847c7d0..bf59174e18d3 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -415,9 +415,14 @@ static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl)
 		if (!(value & masks[i]))
 			continue;
 
+		iret = IRQ_HANDLED;
+
+		/* sensor might not exist (bogus interrupt) or not be registered */
+		if (!lvts_ctrl->sensors[i].tz)
+			continue;
+
 		thermal_zone_device_update(lvts_ctrl->sensors[i].tz,
 					   THERMAL_TRIP_VIOLATED);
-		iret = IRQ_HANDLED;
 	}
 
 	/*
-- 
2.40.0.348.gf938b09366-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones
  2023-03-28  3:10 [PATCH] thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones Chen-Yu Tsai
@ 2023-04-01 20:34 ` Daniel Lezcano
  2023-04-07  8:45   ` Chen-Yu Tsai
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Lezcano @ 2023-04-01 20:34 UTC (permalink / raw)
  To: Chen-Yu Tsai, Rafael J. Wysocki, Amit Kucheria, Zhang Rui
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, Balsam CHIHI,
	linux-pm, linux-arm-kernel, linux-mediatek

On 28/03/2023 05:10, Chen-Yu Tsai wrote:
> It's possible for some sensors or thermal zones to not be registered,
> either because they are unused or not fully declared in the device tree.
> Nevertheless the driver enables interrupts for all sensors. If an
> interrupt happens for an not-registered sensor, the driver would end up
> updating a non-existent thermal zone, which leads to a NULL pointer
> dereference.
> 
> Change it so that only registered thermal zones get updated.

Why not change the interrupt initialization ?

> Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
> ---
>   drivers/thermal/mediatek/lvts_thermal.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index d87d3847c7d0..bf59174e18d3 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -415,9 +415,14 @@ static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl)
>   		if (!(value & masks[i]))
>   			continue;
>   
> +		iret = IRQ_HANDLED;
> +
> +		/* sensor might not exist (bogus interrupt) or not be registered */
> +		if (!lvts_ctrl->sensors[i].tz)
> +			continue;
> +
>   		thermal_zone_device_update(lvts_ctrl->sensors[i].tz,
>   					   THERMAL_TRIP_VIOLATED);
> -		iret = IRQ_HANDLED;
>   	}
>   
>   	/*

-- 
<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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones
  2023-04-01 20:34 ` Daniel Lezcano
@ 2023-04-07  8:45   ` Chen-Yu Tsai
  2023-04-07  9:22     ` Daniel Lezcano
  0 siblings, 1 reply; 4+ messages in thread
From: Chen-Yu Tsai @ 2023-04-07  8:45 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Rafael J. Wysocki, Amit Kucheria, Zhang Rui, Matthias Brugger,
	AngeloGioacchino Del Regno, Balsam CHIHI, linux-pm,
	linux-arm-kernel, linux-mediatek

On Sun, Apr 2, 2023 at 4:34 AM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>
> On 28/03/2023 05:10, Chen-Yu Tsai wrote:
> > It's possible for some sensors or thermal zones to not be registered,
> > either because they are unused or not fully declared in the device tree.
> > Nevertheless the driver enables interrupts for all sensors. If an
> > interrupt happens for an not-registered sensor, the driver would end up
> > updating a non-existent thermal zone, which leads to a NULL pointer
> > dereference.
> >
> > Change it so that only registered thermal zones get updated.
>
> Why not change the interrupt initialization ?

I'll send another patch for that.

However I think the part in this patch should still be fixed?

ChenYu

> > Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
> > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
> > ---
> >   drivers/thermal/mediatek/lvts_thermal.c | 7 ++++++-
> >   1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> > index d87d3847c7d0..bf59174e18d3 100644
> > --- a/drivers/thermal/mediatek/lvts_thermal.c
> > +++ b/drivers/thermal/mediatek/lvts_thermal.c
> > @@ -415,9 +415,14 @@ static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl)
> >               if (!(value & masks[i]))
> >                       continue;
> >
> > +             iret = IRQ_HANDLED;
> > +
> > +             /* sensor might not exist (bogus interrupt) or not be registered */
> > +             if (!lvts_ctrl->sensors[i].tz)
> > +                     continue;
> > +
> >               thermal_zone_device_update(lvts_ctrl->sensors[i].tz,
> >                                          THERMAL_TRIP_VIOLATED);
> > -             iret = IRQ_HANDLED;
> >       }
> >
> >       /*
>
> --
> <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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones
  2023-04-07  8:45   ` Chen-Yu Tsai
@ 2023-04-07  9:22     ` Daniel Lezcano
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Lezcano @ 2023-04-07  9:22 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Rafael J. Wysocki, Amit Kucheria, Zhang Rui, Matthias Brugger,
	AngeloGioacchino Del Regno, Balsam CHIHI, linux-pm,
	linux-arm-kernel, linux-mediatek

On 07/04/2023 10:45, Chen-Yu Tsai wrote:
> On Sun, Apr 2, 2023 at 4:34 AM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>>
>> On 28/03/2023 05:10, Chen-Yu Tsai wrote:
>>> It's possible for some sensors or thermal zones to not be registered,
>>> either because they are unused or not fully declared in the device tree.
>>> Nevertheless the driver enables interrupts for all sensors. If an
>>> interrupt happens for an not-registered sensor, the driver would end up
>>> updating a non-existent thermal zone, which leads to a NULL pointer
>>> dereference.
>>>
>>> Change it so that only registered thermal zones get updated.
>>
>> Why not change the interrupt initialization ?
> 
> I'll send another patch for that.
> 
> However I think the part in this patch should still be fixed?

If you are receiving an unexpected interrupt, there is something wrong 
with the initialization. If only the monitored thermal zones have their 
interrupt enabled, then you should never enter in the interrupt handler 
for a thermal zone which is not monitored, or did I miss something ?

-- 
<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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-07  9:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-28  3:10 [PATCH] thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones Chen-Yu Tsai
2023-04-01 20:34 ` Daniel Lezcano
2023-04-07  8:45   ` Chen-Yu Tsai
2023-04-07  9:22     ` Daniel Lezcano

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).