Skip to contentSkip to conversation

i8k: Properly handle errors

PATCH In review Jean Delvare 2 participants 2 messages May 8, 2011 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i8k: Properly handle errors

My code originally didn't expect the temperature sensor to be missing, and also didn't properly handle run-time errors. This is fixed now.

Cc Guenter Roeck <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Massimo Dal Zotto <[email protected]>

---
I'll merge this fix in patch "i8k: Integrate with the hwmon subsystem".

 drivers/char/i8k.c |   26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
drivers/char/i8k.c +18 -8
@@ -473,6 +473,8 @@ static ssize_t i8k_hwmon_show_temp(struc
 	int cpu_temp;
 
 	cpu_temp = i8k_get_temp(0);
+	if (cpu_temp < 0)
+		return cpu_temp;
 	return sprintf(buf, "%d\n", cpu_temp * 1000);
 }
 
@@ -484,6 +486,8 @@ static ssize_t i8k_hwmon_show_fan(struct
 	int fan_speed;
 
 	fan_speed = i8k_get_fan_speed(index);
+	if (fan_speed < 0)
+		return fan_speed;
 	return sprintf(buf, "%d\n", fan_speed);
 }
 
@@ -541,14 +545,20 @@ static int __init i8k_init_hwmon(void)
 	if (err)
 		goto exit_unregister;
 
-	/* CPU temperature attributes */
-	err = device_create_file(i8k_hwmon_dev, &dev_attr_temp1_input);
-	if (err)
-		goto exit_remove_files;
-	err = device_create_file(i8k_hwmon_dev,
-				 &sensor_dev_attr_temp1_label.dev_attr);
-	if (err)
-		goto exit_remove_files;
+	/* CPU temperature attributes, if temperature reading is OK */
+	err = i8k_get_temp(0);
+	if (err < 0) {
+		dev_dbg(i8k_hwmon_dev,
+			"Not creating temperature attributes (%d)\n", err);
+	} else {
+		err = device_create_file(i8k_hwmon_dev, &dev_attr_temp1_input);
+		if (err)
+			goto exit_remove_files;
+		err = device_create_file(i8k_hwmon_dev,
+					 &sensor_dev_attr_temp1_label.dev_attr);
+		if (err)
+			goto exit_remove_files;
+	}
 
 	/* Left fan attributes, if left fan is present */
 	err = i8k_get_fan_status(I8K_FAN_LEFT);
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jean Delvare

My code originally didn't expect the temperature sensor to be missing, and also didn't properly handle run-time errors. This is fixed now.

Cc Guenter Roeck <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Massimo Dal Zotto <[email protected]>

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