diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-11-15 15:38:56 -0500 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-11-15 15:38:56 -0500 |
commit | 61ec2da506ec6544873f0aba026164e4bdd21751 (patch) | |
tree | 4548b13c7d5457014b820cb2b52bf8e09713ffcb /drivers/hwmon/lm95241.c | |
parent | 2aa25c22c445df63b5961883f28767643122f935 (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/lm95241.c')
-rw-r--r-- | drivers/hwmon/lm95241.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c index 464340f25496..4546d82f024a 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, | |||
128 | { | 128 | { |
129 | struct i2c_client *client = to_i2c_client(dev); | 129 | struct i2c_client *client = to_i2c_client(dev); |
130 | struct lm95241_data *data = i2c_get_clientdata(client); | 130 | struct lm95241_data *data = i2c_get_clientdata(client); |
131 | unsigned long val; | ||
131 | 132 | ||
132 | strict_strtol(buf, 10, &data->interval); | 133 | if (strict_strtoul(buf, 10, &val) < 0) |
133 | data->interval = data->interval * HZ / 1000; | 134 | return -EINVAL; |
135 | |||
136 | data->interval = val * HZ / 1000; | ||
134 | 137 | ||
135 | return count; | 138 | return count; |
136 | } | 139 | } |
@@ -188,7 +191,9 @@ static ssize_t set_type##flag(struct device *dev, \ | |||
188 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 191 | struct lm95241_data *data = i2c_get_clientdata(client); \ |
189 | \ | 192 | \ |
190 | long val; \ | 193 | long val; \ |
191 | strict_strtol(buf, 10, &val); \ | 194 | \ |
195 | if (strict_strtol(buf, 10, &val) < 0) \ | ||
196 | return -EINVAL; \ | ||
192 | \ | 197 | \ |
193 | if ((val == 1) || (val == 2)) { \ | 198 | if ((val == 1) || (val == 2)) { \ |
194 | \ | 199 | \ |
@@ -227,7 +232,9 @@ static ssize_t set_min##flag(struct device *dev, \ | |||
227 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 232 | struct lm95241_data *data = i2c_get_clientdata(client); \ |
228 | \ | 233 | \ |
229 | long val; \ | 234 | long val; \ |
230 | strict_strtol(buf, 10, &val); \ | 235 | \ |
236 | if (strict_strtol(buf, 10, &val) < 0) \ | ||
237 | return -EINVAL;\ | ||
231 | \ | 238 | \ |
232 | mutex_lock(&data->update_lock); \ | 239 | mutex_lock(&data->update_lock); \ |
233 | \ | 240 | \ |
@@ -256,7 +263,9 @@ static ssize_t set_max##flag(struct device *dev, \ | |||
256 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 263 | struct lm95241_data *data = i2c_get_clientdata(client); \ |
257 | \ | 264 | \ |
258 | long val; \ | 265 | long val; \ |
259 | strict_strtol(buf, 10, &val); \ | 266 | \ |
267 | if (strict_strtol(buf, 10, &val) < 0) \ | ||
268 | return -EINVAL; \ | ||
260 | \ | 269 | \ |
261 | mutex_lock(&data->update_lock); \ | 270 | mutex_lock(&data->update_lock); \ |
262 | \ | 271 | \ |