hwmon: (lm75) Fix write operations for negative temperatures
authorGuenter Roeck <linux@roeck-us.net>
Thu, 8 Aug 2019 19:00:18 +0000 (12:00 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Jan 2020 13:51:08 +0000 (14:51 +0100)
commit55027bf48126c3314c10ccaffe623833ec696adf
tree3f152397166308d6ca7876f61b791cbed13ff03b
parentd9711896dddfa9ba5257d8570124ab7e157f8cc9
hwmon: (lm75) Fix write operations for negative temperatures

[ Upstream commit 7d82fcc9d9e81241778aaa22fda7be753e237d86 ]

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 <iker.perez@codethink.co.uk>
Fixes: e65365fed87f ("hwmon: (lm75) Convert to use regmap")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hwmon/lm75.c