thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones
Subsystems (2)
PATCH 1/1 thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones
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.
--- drivers/thermal/mediatek/lvts_thermal.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/thermal/mediatek/lvts_thermal.c +6 -1
@@ -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 ; }/*
Signature · 1 line
2.40.0.348.gf938b09366-goog
Quoted 8 lines · Chen-Yu Tsai
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 ?
Quoted 26 lines
Fixes f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")Signed-off-by Chen-Yu Tsai <[email protected]>--- drivers/thermal/mediatek/lvts_thermal.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/thermal/mediatek/lvts_thermal.c +6
-1@@ -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 ; }/*
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
Quoted 9 lines · Daniel Lezcano
Quoted 7 lines · Chen-Yu Tsai
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.
Quoted 3 lines
Quoted 1 line
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
Quoted 34 lines
Quoted 16 lines
Fixes f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")Signed-off-by Chen-Yu Tsai <[email protected]>--- drivers/thermal/mediatek/lvts_thermal.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/thermal/mediatek/lvts_thermal.c +2
-0@@ -415,9 +415,14 @@ static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl)if (!(value & masks[i]))continue ; + iret =IRQ_HANDLED ; +drivers/thermal/mediatek/lvts_thermal.c static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl) · line 428
Quoted 10 lines
drivers/thermal/mediatek/lvts_thermal.c +4
-1+/* 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 SoCsFollow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
Quoted 10 lines · Chen-Yu Tsai
Quoted 9 lines · Daniel Lezcano
Quoted 7 lines · Chen-Yu Tsai
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.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
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 ?
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