Skip to contentSkip to conversation

hwmon: (pmbus) Fix return value from pmbus_update_byte_data()

PATCH New Guenter Roeck 2 participants 2 messages Jul 28 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (pmbus) Fix return value from pmbus_update_byte_data()

pmbus_update_byte_data() is supposed to return a negative error code or 0. However, if no change is made to the register, it actually returns the register value. This can result in problems if the calling code explicitly expects to see an error code or 0.

Fix it to return 0 on success or the error code as expected.

Fixes 11c119986f270 ("hwmon: (pmbus) add helpers for byte write and read modify write")
---
 drivers/hwmon/pmbus/pmbus_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus_core.c +1 -1
index 24c4d502733c..aac86d4f64b5 100644
@@ -513,7 +513,7 @@ int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
 	if (tmp != rv)
 		rv = _pmbus_write_byte_data(client, page, reg, tmp);
 
-	return rv;
+	return rv < 0 ? rv : 0;
 }
 EXPORT_SYMBOL_NS_GPL(pmbus_update_byte_data, "PMBUS");
 
Signature · 1 line
2.45.2
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

pmbus_update_byte_data() is supposed to return a negative error code or 0. However, if no change is made to the register, it actually returns the register value. This can result in problems if the calling code explicitly expects to see an error code or 0.

Fix it to return 0 on success or the error code as expected.

Fixes 11c119986f270 ("hwmon: (pmbus) add helpers for byte write and read modify write")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1