From: Guenter Roeck Date: Thu, 8 Aug 2019 19:00:18 +0000 (-0700) Subject: hwmon: (lm75) Fix write operations for negative temperatures X-Git-Tag: for-5.4/post-2019-09-24~63^2~46 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=7d82fcc9d9e81241778aaa22fda7be753e237d86;p=linux-block.git 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 Fixes: e65365fed87f ("hwmon: (lm75) Convert to use regmap") Signed-off-by: Guenter Roeck --- diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index ce5ec403ec73..cbabab7ac788 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c @@ -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,