Linux-Hwmon Archive on
 help / color / Atom feed
From: Sasha Levin <>
Cc: Guenter Roeck <>,
	Iker Perez del Palomar Sustatxa  <>,
	Sasha Levin <>,
Subject: [PATCH AUTOSEL 4.9 190/251] hwmon: (lm75) Fix write operations for negative temperatures
Date: Thu, 16 Jan 2020 12:35:39 -0500
Message-ID: <> (raw)
In-Reply-To: <>

From: Guenter Roeck <>

[ 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 <>
Fixes: e65365fed87f ("hwmon: (lm75) Convert to use regmap")
Signed-off-by: Guenter Roeck <>
Signed-off-by: Sasha Levin <>
 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 eff3b24d8473..fc31669a86ba 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -164,7 +164,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,

  parent reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <>
2020-01-16 17:34 ` [PATCH AUTOSEL 4.9 115/251] hwmon: (w83627hf) Use request_muxed_region for Super-IO accesses Sasha Levin
2020-01-16 17:35 ` Sasha Levin [this message]
2020-01-16 17:35 ` [PATCH AUTOSEL 4.9 199/251] hwmon: (shtc1) fix shtc1 and shtw1 id mask Sasha Levin

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone