mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: (lm87) Propagate analog output write errors
@ 2026-10-25 15:08 pocj8ur4in
  2026-10-26  0:17 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: pocj8ur4in @ 2026-10-25 15:08 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Baek Kyu, Kim, linux-hwmon, linux-kernel

From: "Baek Kyu, Kim" <pocj8ur4in@gmail.com>

The aout_output store path updates its cached value before writing the
register and ignores the SMBus result. A rejected write therefore returns
a successful byte count and reports the requested value until the cache
expires. With a cached 980 mV, a rejected write of 1960 mV returned 5 and
read back as 1960 mV although the register still held 980 mV.

Check the write result and update the cache only after success. Return the
bus error to the sysfs caller.

Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
---
Tested on ARM64 QEMU/KVM through the lm87 and adm1024 sysfs paths,
using an emulated SMBus adapter. With 980 mV cached, a pre-apply
-EIO rejection of a 1960 mV write returned 5 and read back 1960 mV
before the change; after the change, it returned -EIO and read back
980 mV. The same behavior was checked with -EREMOTEIO. No physical
chip or analog voltage was measured.

 drivers/hwmon/lm87.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index c09074f44708..ea23206b3c81 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -640,6 +640,7 @@ static ssize_t aout_output_store(struct device *dev,
 {
 	struct i2c_client *client = dev_get_drvdata(dev);
 	struct lm87_data *data = i2c_get_clientdata(client);
+	u8 reg;
 	long val;
 	int err;
 
@@ -647,11 +648,14 @@ static ssize_t aout_output_store(struct device *dev,
 	if (err)
 		return err;
 
+	reg = AOUT_TO_REG(val);
+
 	mutex_lock(&data->update_lock);
-	data->aout = AOUT_TO_REG(val);
-	lm87_write_value(client, LM87_REG_AOUT, data->aout);
+	err = lm87_write_value(client, LM87_REG_AOUT, reg);
+	if (!err)
+		data->aout = reg;
 	mutex_unlock(&data->update_lock);
-	return count;
+	return err < 0 ? err : count;
 }
 static DEVICE_ATTR_RW(aout_output);
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwmon: (lm87) Propagate analog output write errors
  2026-10-25 15:08 [PATCH] hwmon: (lm87) Propagate analog output write errors pocj8ur4in
@ 2026-10-26  0:17 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2026-10-26  0:17 UTC (permalink / raw)
  To: pocj8ur4in; +Cc: linux-hwmon, linux-kernel

On Mon, Oct 26, 2026 at 12:08:00AM +0900, pocj8ur4in wrote:
> From: "Baek Kyu, Kim" <pocj8ur4in@gmail.com>
> 
> The aout_output store path updates its cached value before writing the
> register and ignores the SMBus result. A rejected write therefore returns
> a successful byte count and reports the requested value until the cache
> expires. With a cached 980 mV, a rejected write of 1960 mV returned 5 and
> read back as 1960 mV although the register still held 980 mV.
> 
> Check the write result and update the cache only after success. Return the
> bus error to the sysfs caller.
> 
> Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>

NACK, for a simple reason:

This driver has 23 instances of unchecked I2C writes. This patch fixes
_one_ of them. I am not going to waste my time reviewing 23 separate
patches, each of them fixing one instance of an unchecked write, plus
another set of patches fixing all the unchecked read operations.

Guenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-26  0:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 15:08 [PATCH] hwmon: (lm87) Propagate analog output write errors pocj8ur4in
2026-10-26  0:17 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®