Skip to contentSkip to conversation

hwmon: (ads7871) Fix incorrect error code in voltage_show

PATCH Superseded Tabrez Ahmed 2 participants 2 messages Mar 7 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (ads7871) Fix incorrect error code in voltage_show

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.

Note: not runtime tested due to lack of hardware.

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

 drivers/hwmon/ads7871.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ads7871.c +1 -1
index b84426c940c5e..4df54c86f786c 100644
@@ -126,7 +126,7 @@ static ssize_t voltage_show(struct device *dev, struct device_attribute *da,
 		val = ((val >> 2) * 25000) / 8192;
 		return sysfs_emit(buf, "%d\n", val);
 	} else {
-		return -1;
+		return -ETIMEDOUT;
 	}
 }
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi,

Quoted 23 lines · Tabrez Ahmed

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.

Note: not runtime tested due to lack of hardware.

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

  drivers/hwmon/ads7871.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/ads7871.c +0 -0
index b84426c940c5e..4df54c86f786c 100644

drivers/hwmon/ads7871.c static ssize_t voltage_show(struct device *dev, struct device_attribute *da, · line 132

Quoted 8 lines
drivers/hwmon/ads7871.c +1 -1
@@ -126,7 +126,7 @@ static ssize_t voltage_show(struct device *dev, struct device_attribute *da,
  		val = ((val >> 2) * 25000) / 8192;
  		return sysfs_emit(buf, "%d\n", val);
  	} else {
-		return -1;
+		return -ETIMEDOUT;
  	}
  }
 

Good find, but please also drop the else (else after return is unnecessary).

Thanks,
Guenter