[PATCH 4/5] hwmon: (pmbus/ina233) Add error check for pmbus_read_word_data() return value

Pradhan, Sanman posted 5 patches 2 weeks, 6 days ago
Only 4 patches received!
[PATCH 4/5] hwmon: (pmbus/ina233) Add error check for pmbus_read_word_data() return value
Posted by Pradhan, Sanman 2 weeks, 6 days ago
From: Sanman Pradhan <psanman@juniper.net>

ina233_read_word_data() uses the return value of pmbus_read_word_data()
directly in a DIV_ROUND_CLOSEST() computation without first checking for
errors. If the underlying I2C transaction fails, a negative error code is
used in the arithmetic, producing a garbage sensor value instead of
propagating the error.

Add the missing error check before using the return value.

Fixes: b64b6cb163f16 ("hwmon: Add driver for TI INA233 Current and Power Monitor")
Cc: stable@vger.kernel.org
Signed-off-by: Sanman Pradhan <psanman@juniper.net>
---
 drivers/hwmon/pmbus/ina233.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwmon/pmbus/ina233.c b/drivers/hwmon/pmbus/ina233.c
index dde1e16783943..2d8b5a5347edc 100644
--- a/drivers/hwmon/pmbus/ina233.c
+++ b/drivers/hwmon/pmbus/ina233.c
@@ -67,6 +67,8 @@ static int ina233_read_word_data(struct i2c_client *client, int page,
 	switch (reg) {
 	case PMBUS_VIRT_READ_VMON:
 		ret = pmbus_read_word_data(client, 0, 0xff, MFR_READ_VSHUNT);
+		if (ret < 0)
+			return ret;
 
 		/* Adjust returned value to match VIN coefficients */
 		/* VIN: 1.25 mV VSHUNT: 2.5 uV LSB */
-- 
2.34.1

Re: [PATCH 4/5] hwmon: (pmbus/ina233) Add error check for pmbus_read_word_data() return value
Posted by Guenter Roeck 2 weeks, 5 days ago
On Tue, Mar 17, 2026 at 05:46:31PM +0000, Pradhan, Sanman wrote:
> From: Sanman Pradhan <psanman@juniper.net>
> 
> ina233_read_word_data() uses the return value of pmbus_read_word_data()
> directly in a DIV_ROUND_CLOSEST() computation without first checking for
> errors. If the underlying I2C transaction fails, a negative error code is
> used in the arithmetic, producing a garbage sensor value instead of
> propagating the error.
> 
> Add the missing error check before using the return value.
> 
> Fixes: b64b6cb163f16 ("hwmon: Add driver for TI INA233 Current and Power Monitor")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sanman Pradhan <psanman@juniper.net>

Applied.

Thanks,
Guenter
[PATCH 5/5] hwmon: (pmbus/isl68137) Fix unchecked return value and use sysfs_emit()
Posted by Pradhan, Sanman 2 weeks, 6 days ago
From: Sanman Pradhan <psanman@juniper.net>

isl68137_avs_enable_show_page() uses the return value of
pmbus_read_byte_data() without checking for errors. If the I2C transaction
fails, the negative error code is passed through the bitmask test and
sprintf, producing incorrect output instead of propagating the error.

Additionally, replace sprintf() with sysfs_emit() which is the preferred
API for sysfs show callbacks since v5.10.

Fixes: 038a9c3d1e424 ("hwmon: (pmbus/isl68137) Add driver for Intersil ISL68137 PWM Controller")
Cc: stable@vger.kernel.org
Signed-off-by: Sanman Pradhan <psanman@juniper.net>
---
 drivers/hwmon/pmbus/isl68137.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/isl68137.c b/drivers/hwmon/pmbus/isl68137.c
index 97b61836f53a4..739e7126be51c 100644
--- a/drivers/hwmon/pmbus/isl68137.c
+++ b/drivers/hwmon/pmbus/isl68137.c
@@ -98,8 +98,11 @@ static ssize_t isl68137_avs_enable_show_page(struct i2c_client *client,
 {
 	int val = pmbus_read_byte_data(client, page, PMBUS_OPERATION);
 
-	return sprintf(buf, "%d\n",
-		       (val & ISL68137_VOUT_AVS) == ISL68137_VOUT_AVS ? 1 : 0);
+	if (val < 0)
+		return val;
+
+	return sysfs_emit(buf, "%d\n",
+			  !!(val & ISL68137_VOUT_AVS));
 }
 
 static ssize_t isl68137_avs_enable_store_page(struct i2c_client *client,
-- 
2.34.1