[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250730152128.311109-4-laura.nao@collabora.com>
Date: Wed, 30 Jul 2025 17:21:22 +0200
From: Laura Nao <laura.nao@...labora.com>
To: srini@...nel.org,
robh@...nel.org,
krzk+dt@...nel.org,
conor+dt@...nel.org,
rafael@...nel.org,
daniel.lezcano@...aro.org,
rui.zhang@...el.com,
lukasz.luba@....com,
matthias.bgg@...il.com,
angelogioacchino.delregno@...labora.com
Cc: wenst@...omium.org,
nfraprado@...labora.com,
arnd@...db.de,
colin.i.king@...il.com,
u.kleine-koenig@...libre.com,
andrew-ct.chen@...iatek.com,
lala.lin@...iatek.com,
bchihi@...libre.com,
frank-w@...lic-files.de,
devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-pm@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org,
kernel@...labora.com,
Laura Nao <laura.nao@...labora.com>
Subject: [PATCH v2 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp
Add a guard against zero temp_factor in lvts_raw_to_temp() to prevent
division by zero and ensure safe conversion.
Fixes: 6725a29321e4 ("thermal/drivers/mediatek/lvts_thermal: Make coeff configurable")
Reviewed-by: Chen-Yu Tsai <wenst@...omium.org>
Signed-off-by: Laura Nao <laura.nao@...labora.com>
---
drivers/thermal/mediatek/lvts_thermal.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 05aa8895ccce..8398af657ba2 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -284,11 +284,14 @@ static int lvts_raw_to_temp(u32 raw_temp, int temp_factor)
static u32 lvts_temp_to_raw(int temperature, int temp_factor)
{
- u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
+ u32 raw_temp;
- raw_temp = div_s64(raw_temp, -temp_factor);
+ if (temp_factor == 0)
+ return temperature;
- return raw_temp;
+ raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
+
+ return div_s64(raw_temp, -temp_factor);
}
static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
@@ -1346,6 +1349,9 @@ static int lvts_probe(struct platform_device *pdev)
if (irq < 0)
return irq;
+ if (!lvts_data->temp_factor)
+ dev_warn(dev, "temp_factor should never be zero; check platform data.\n");
+
golden_temp_offset = lvts_data->temp_offset;
ret = lvts_domain_init(dev, lvts_td, lvts_data);
--
2.39.5
Powered by blists - more mailing lists