diff mbox series

[v2] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data

Message ID 20240604-mtk-thermal-calib-check-v2-1-8f258254051d@baylibre.com
State Accepted
Commit 72cacd06e47d86d89b0e7179fbc9eb3a0f39cd93
Headers show
Series [v2] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data | expand

Commit Message

Julien Panis June 4, 2024, 4:46 p.m. UTC
This patch prevents from registering thermal entries and letting the
driver misbehave if efuse data is invalid. A device is not properly
calibrated if the golden temperature is zero.

Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
Signed-off-by: Julien Panis <jpanis@baylibre.com>
---
Guard against invalid calibration data, following this discussion:
https://lore.kernel.org/all/ad047631-16b8-42ce-8a8d-1429e6af4517@collabora.com/
---
Changes in v2:
- Add Fixes tag.
- Link to v1: https://lore.kernel.org/r/20240603-mtk-thermal-calib-check-v1-1-5d6bf040414c@baylibre.com
---
 drivers/thermal/mediatek/lvts_thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)


---
base-commit: 632483ea8004edfadd035de36e1ab2c7c4f53158
change-id: 20240603-mtk-thermal-calib-check-ba2ec24a1c32

Best regards,

Comments

AngeloGioacchino Del Regno June 5, 2024, 11:04 a.m. UTC | #1
Il 04/06/24 18:46, Julien Panis ha scritto:
> This patch prevents from registering thermal entries and letting the
> driver misbehave if efuse data is invalid. A device is not properly
> calibrated if the golden temperature is zero.
> 
> Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
> Signed-off-by: Julien Panis <jpanis@baylibre.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Chen-Yu Tsai June 13, 2024, 9:27 a.m. UTC | #2
On Wed, Jun 5, 2024 at 1:45 AM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>
> On 04/06/2024 18:46, Julien Panis wrote:
> > This patch prevents from registering thermal entries and letting the
> > driver misbehave if efuse data is invalid. A device is not properly
> > calibrated if the golden temperature is zero.
> >
> > Fixes: f5f633b18234 ("thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver")
> > Signed-off-by: Julien Panis <jpanis@baylibre.com>
> > ---
> > Guard against invalid calibration data, following this discussion:
> > https://lore.kernel.org/all/ad047631-16b8-42ce-8a8d-1429e6af4517@collabora.com/
> > ---
>
> Applied for v6.10-rc3

(Dropped most recipients and mailing lists; added Stephen and linux-next ML)

This isn't showing up in linux-next.  Could we have linux-next track
the thermal tree's fixes branch [1] as well?

[1] http://git.kernel.org/thermal/h/thermal/fixes
diff mbox series

Patch

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 0bb3a495b56e..185d5a32711f 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -769,7 +769,11 @@  static int lvts_golden_temp_init(struct device *dev, u8 *calib,
 	 */
 	gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff;
 
-	if (gt && gt < LVTS_GOLDEN_TEMP_MAX)
+	/* A zero value for gt means that device has invalid efuse data */
+	if (!gt)
+		return -ENODATA;
+
+	if (gt < LVTS_GOLDEN_TEMP_MAX)
 		golden_temp = gt;
 
 	golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset;