Skip to contentSkip to conversation

Make the writing to sysfs more robust.

RFC PATCH In review Shubhrajyoti D 2 participants 2 messages Aug 26, 2010 – Aug 27, 2010 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Make the writing to sysfs more robust.

Currently we get the checkpatch warning
consider using strict_strtol in preference to simple_strtol Also we should not allow any partially numeric values

---
 drivers/hwmon/lm75.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/hwmon/lm75.c +5 -1
index a86f2e0..9f23dfc 100644
@@ -103,7 +103,11 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm75_data *data = i2c_get_clientdata(client);
 	int nr = attr->index;
-	long temp = simple_strtol(buf, NULL, 10);
+	long temp;
+	int error;
+	error = strict_strtol(buf, 10, &temp);
+	if (error)
+		return error;
 
 	mutex_lock(&data->update_lock);
 	data->temp[nr] = LM75_TEMP_TO_REG(temp);
Signature · 7 lines
1.7.0.4


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 14 lines · Shubhrajyoti D

Currently we get the checkpatch warning
consider using strict_strtol in preference to simple_strtol Also we should not allow any partially numeric values

---
 drivers/hwmon/lm75.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/hwmon/lm75.c +0 -0
index a86f2e0..9f23dfc 100644

drivers/hwmon/lm75.c static ssize_t set_temp(struct device *dev, struct device_attribute *da, · line 107

Quoted 6 lines
drivers/hwmon/lm75.c +2 -1
@@ -103,7 +103,11 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
 	struct i2c_client *client = to_i2c_client(dev);
 	struct lm75_data *data = i2c_get_clientdata(client);
 	int nr = attr->index;
-	long temp = simple_strtol(buf, NULL, 10);
+	long temp;
+	int error;

Except for the missing blank line here, which I've added myself, it looks good. Patch applied, thanks!

Quoted 6 lines
drivers/hwmon/lm75.c +3 -0
+	error = strict_strtol(buf, 10, &temp);
+	if (error)
+		return error;
 
 	mutex_lock(&data->update_lock);
 	data->temp[nr] = LM75_TEMP_TO_REG(temp);
Signature · 6 lines
Jean Delvare

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