Skip to contentSkip to conversation

hwmon: (lm75) Fix write operations for negative temperatures

PATCH New Guenter Roeck 1 participant 1 message Aug 8, 2019 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (lm75) Fix write operations for negative temperatures

Writes into limit registers fail if the temperature written is negative. The regmap write operation checks the value range, regmap_write accepts an unsigned int as parameter, and the temperature value passed to regmap_write is kept in a variable declared as long. Negative values are converted large unsigned integers, which fails the range check. Fix by type casting the temperature to u16 when calling regmap_write().

Cc Iker Perez del Palomar Sustatxa <[email protected]>
Fixes e65365fed87f ("hwmon: (lm75) Convert to use regmap")
---
 drivers/hwmon/lm75.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/lm75.c +1 -1
index ce5ec403ec73..cbabab7ac788 100644
@@ -154,7 +154,7 @@ static int lm75_write(struct device *dev, enum hwmon_sensor_types type,
 	temp = DIV_ROUND_CLOSEST(temp  << (resolution - 8),
 				 1000) << (16 - resolution);
 
-	return regmap_write(data->regmap, reg, temp);
+	return regmap_write(data->regmap, reg, (u16)temp);
 }
 
 static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type,
Signature · 1 line
2.7.4