[PATCH v2] hwmon: (ads7871) Fix incorrect error code in voltage_show

From: Tabrez Ahmed

Date: Sat Mar 07 2026 - 06:52:51 EST


The voltage_show() function returns -1 when the A/D conversion
fails to complete within the polling loop. -1 maps to -EPERM
(operation not permitted), which does not describe the actual
failure.

Replace this -1 error code with -ETIMEDOUT to better indicate
the timeout condition to userspace.

Drop the else block after return.

Note: not runtime tested due to lack of hardware.

Signed-off-by: Tabrez Ahmed <tabreztalks@xxxxxxxxx>
---
Changes in v2:
- Dropped unnecessary 'else' block after return as suggested by Guenter Roeck.

Note: This patch applies on top of my previously submitted patch:
"hwmon: (ads7871) Replace sprintf() with sysfs_emit()"

drivers/hwmon/ads7871.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/ads7871.c b/drivers/hwmon/ads7871.c
index b84426c940c5e..753bf77ce19b4 100644
--- a/drivers/hwmon/ads7871.c
+++ b/drivers/hwmon/ads7871.c
@@ -125,9 +125,9 @@ static ssize_t voltage_show(struct device *dev, struct device_attribute *da,
/*result in volts*10000 = (val/8192)*2.5*10000*/
val = ((val >> 2) * 25000) / 8192;
return sysfs_emit(buf, "%d\n", val);
- } else {
- return -1;
}
+
+ return -ETIMEDOUT;
}

static SENSOR_DEVICE_ATTR_RO(in0_input, voltage, 0);
--
2.43.0