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>
This commit is contained in:
parent
2aa25c22c4
commit
61ec2da506
@ -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); \
|
||||
\
|
||||
|
Loading…
Reference in New Issue
Block a user