[PATCH] thermal/drivers/mediatek/lvts_thermal: only update registered thermal zones

Chen-Yu Tsai wenst at chromium.org
Mon Mar 27 20:10:37 PDT 2023


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




More information about the linux-arm-kernel mailing list