Linux-Hwmon Archive on
 help / color / Atom feed
* [PATCH] hwmon: (lm75) Fix write operations for negative temperatures
@ 2019-08-08 19:13 Guenter Roeck
  0 siblings, 0 replies; only message in thread
From: Guenter Roeck @ 2019-08-08 19:13 UTC (permalink / raw)
  To: Hardware Monitoring
  Cc: Jean Delvare, Guenter Roeck, Iker Perez del Palomar Sustatxa

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 <>
 drivers/hwmon/lm75.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08 19:13 [PATCH] hwmon: (lm75) Fix write operations for negative temperatures Guenter Roeck

Linux-Hwmon Archive on

Archives are clonable:
	git clone --mirror linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ \
	public-inbox-index linux-hwmon

Newsgroup available over NNTP:

AGPL code for this site: git clone public-inbox