From 53a945a89df8fea7a4946e4a20b7bc8c57d2b787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Thu, 30 Jul 2026 17:12:26 +0200 Subject: [PATCH] hwmon: (cros_ec) Avoid threshold temperature conversion overflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the EC returns non-sensical values the temperature conversions might overflow on 32-bit systems. As these values wouldn't make sense, clamp them to 255 degrees celsius. The machine would die before reaching that limit anyways. Suggested-by: Guenter Roeck Link: https://lore.kernel.org/lkml/0fbf7f69-bb90-4209-b9d5-258759711496@roeck-us.net/ Signed-off-by: Thomas Weißschuh Link: https://lore.kernel.org/r/20260730-cros_ec-hwmon-overflow-v3-1-c7198ba034ad@weissschuh.net Signed-off-by: Guenter Roeck --- drivers/hwmon/cros_ec_hwmon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c index 1337b646e022..27af13f0941c 100644 --- a/drivers/hwmon/cros_ec_hwmon.c +++ b/drivers/hwmon/cros_ec_hwmon.c @@ -236,8 +236,13 @@ static int cros_ec_hwmon_read(struct device *dev, enum hwmon_sensor_types type, ret = cros_ec_hwmon_read_temp_threshold(priv->cros_ec, channel, cros_ec_hwmon_attr_to_thres(attr), &threshold); - if (ret == 0) - *val = cros_ec_hwmon_kelvin_to_millicelsius(threshold); + if (ret == 0) { + /* Limit to sensible, non-overflowing values. */ + if (threshold > 255 + 273) + *val = 255000; + else + *val = cros_ec_hwmon_kelvin_to_millicelsius(threshold); + } } }