summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-11-15 21:38:56 +0100
committerJean Delvare <khali@endymion.delvare>2010-11-15 21:38:56 +0100
commit61ec2da506ec6544873f0aba026164e4bdd21751 (patch)
tree4548b13c7d5457014b820cb2b52bf8e09713ffcb /drivers/hwmon
parent2aa25c22c445df63b5961883f28767643122f935 (diff)
hwmon: (lm95241) Check validity of input values
This clears the following build-time warnings I was seeing: drivers/hwmon/lm95241.c: In function "set_interval": drivers/hwmon/lm95241.c:132:15: warning: ignoring return value of "strict_strtol", declared with attribute warn_unused_result drivers/hwmon/lm95241.c: In function "set_max2": drivers/hwmon/lm95241.c:278:1: warning: ignoring return value of "strict_strtol", declared with attribute warn_unused_result drivers/hwmon/lm95241.c: In function "set_max1": drivers/hwmon/lm95241.c:277:1: warning: ignoring return value of "strict_strtol", declared with attribute warn_unused_result drivers/hwmon/lm95241.c: In function "set_min2": drivers/hwmon/lm95241.c:249:1: warning: ignoring return value of "strict_strtol", declared with attribute warn_unused_result drivers/hwmon/lm95241.c: In function "set_min1": drivers/hwmon/lm95241.c:248:1: warning: ignoring return value of "strict_strtol", declared with attribute warn_unused_result drivers/hwmon/lm95241.c: In function "set_type2": drivers/hwmon/lm95241.c:220:1: warning: ignoring return value of "strict_strtol", declared with attribute warn_unused_result drivers/hwmon/lm95241.c: In function "set_type1": drivers/hwmon/lm95241.c:219:1: warning: ignoring return value of "strict_strtol", declared with attribute warn_unused_result This also fixes a small race in set_interval() as a side effect: by working with a temporary local variable we prevent data->interval from being accessed at a time it contains the interval value in the wrong unit. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Davide Rizzo <elpa.rizzo@gmail.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm95241.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 464340f2549..4546d82f024 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -128,9 +128,12 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
{
struct i2c_client *client = to_i2c_client(dev);
struct lm95241_data *data = i2c_get_clientdata(client);
+ unsigned long val;
- strict_strtol(buf, 10, &data->interval);
- data->interval = data->interval * HZ / 1000;
+ if (strict_strtoul(buf, 10, &val) < 0)
+ return -EINVAL;
+
+ data->interval = val * HZ / 1000;
return count;
}
@@ -188,7 +191,9 @@ static ssize_t set_type##flag(struct device *dev, \
struct lm95241_data *data = i2c_get_clientdata(client); \
\
long val; \
- strict_strtol(buf, 10, &val); \
+\
+ if (strict_strtol(buf, 10, &val) < 0) \
+ return -EINVAL; \
\
if ((val == 1) || (val == 2)) { \
\
@@ -227,7 +232,9 @@ static ssize_t set_min##flag(struct device *dev, \
struct lm95241_data *data = i2c_get_clientdata(client); \
\
long val; \
- strict_strtol(buf, 10, &val); \
+\
+ if (strict_strtol(buf, 10, &val) < 0) \
+ return -EINVAL;\
\
mutex_lock(&data->update_lock); \
\
@@ -256,7 +263,9 @@ static ssize_t set_max##flag(struct device *dev, \
struct lm95241_data *data = i2c_get_clientdata(client); \
\
long val; \
- strict_strtol(buf, 10, &val); \
+\
+ if (strict_strtol(buf, 10, &val) < 0) \
+ return -EINVAL; \
\
mutex_lock(&data->update_lock); \
\