Skip to contentSkip to conversation

hwmon: (atxp1) Set and use error code from vid_to_reg()

PATCH In review Guenter Roeck 2 participants 2 messages Sep 14, 2013 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 10/12 hwmon: (atxp1) Set and use error code from vid_to_reg()

vid_to_reg() returns -1 if it encounters an error. Return -EINVAL instead. Its only caller, atxp1_storevcore(), doesn't use the return code but returns -1 instead, which is wrong anyway as it means -EPERM. Use the return value from vid_to_reg() instead to report the error.

---
 drivers/hwmon/atxp1.c     |    3 +--
 include/linux/hwmon-vid.h |    2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/hwmon/atxp1.c +1 -2
index aecb9ea..ddff02e 100644
@@ -147,10 +147,9 @@ static ssize_t atxp1_storevcore(struct device *dev,
 
 	/* Calculate VID */
 	vid = vid_to_reg(vcore, data->vrm);
-
 	if (vid < 0) {
 		dev_err(dev, "VID calculation failed.\n");
-		return -1;
+		return vid;
 	}
 
 	/*
include/linux/hwmon-vid.h +1 -1
index f346e4d..da0a680 100644
@@ -38,7 +38,7 @@ static inline int vid_to_reg(int val, u8 vrm)
 		return ((val >= 1100) && (val <= 1850) ?
 			((18499 - val * 10) / 25 + 5) / 10 : -1);
 	default:
-		return -1;
+		return -EINVAL;
 	}
 }
 
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Reviewed-by on v1 10/12
#1 lore raw
Quoted 32 lines · Guenter Roeck

vid_to_reg() returns -1 if it encounters an error. Return -EINVAL instead. Its only caller, atxp1_storevcore(), doesn't use the return code but returns -1 instead, which is wrong anyway as it means -EPERM. Use the return value from vid_to_reg() instead to report the error.

---
 drivers/hwmon/atxp1.c     |    3 +--
 include/linux/hwmon-vid.h |    2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/hwmon/atxp1.c +1 -2
index aecb9ea..ddff02e 100644
@@ -147,10 +147,9 @@ static ssize_t atxp1_storevcore(struct device *dev,
 
 	/* Calculate VID */
 	vid = vid_to_reg(vcore, data->vrm);
-
 	if (vid < 0) {
 		dev_err(dev, "VID calculation failed.\n");
-		return -1;
+		return vid;
 	}
 
 	/*
include/linux/hwmon-vid.h +0 -0
index f346e4d..da0a680 100644

include/linux/hwmon-vid.h static inline int vid_to_reg(int val, u8 vrm) · line 44

Quoted 8 lines
include/linux/hwmon-vid.h +1 -1
@@ -38,7 +38,7 @@ static inline int vid_to_reg(int val, u8 vrm)
 		return ((val >= 1100) && (val <= 1850) ?
 			((18499 - val * 10) / 25 + 5) / 10 : -1);
 	default:
-		return -1;
+		return -EINVAL;
 	}
 }
 

Good catch.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors