diff options
author | Brian Masney <masneyb@onstation.org> | 2018-05-03 22:53:10 -0400 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2018-05-06 19:01:14 +0100 |
commit | 2a74090249ed2cf9c1e383c2b450efdce08159ab (patch) | |
tree | a6bd0220fc1f992b3c9f8c496718fc88f428996d | |
parent | 5a1f2de133a8d3ac575910295519572535034ae0 (diff) | |
download | linux-2a74090249ed2cf9c1e383c2b450efdce08159ab.tar.gz linux-2a74090249ed2cf9c1e383c2b450efdce08159ab.tar.bz2 linux-2a74090249ed2cf9c1e383c2b450efdce08159ab.zip |
staging: iio: tsl2x7x: add range checking to three sysfs attributes
The sysfs attributes in_illuminance0_target_input,
in_illuminance0_calibrate, and in_proximity0_calibrate did not have
proper range checking in place so this patch adds the correct range
checks.
Signed-off-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r-- | drivers/staging/iio/light/tsl2x7x.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 01bff4593640..b4d77f65ca12 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -814,15 +814,13 @@ static ssize_t in_illuminance0_target_input_store(struct device *dev, { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev); - unsigned long value; + u16 value; int ret; - if (kstrtoul(buf, 0, &value)) + if (kstrtou16(buf, 0, &value)) return -EINVAL; - if (value) - chip->settings.als_cal_target = value; - + chip->settings.als_cal_target = value; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) return ret; @@ -838,14 +836,12 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev, bool value; int ret; - if (strtobool(buf, &value)) + if (kstrtobool(buf, &value) || !value) return -EINVAL; - if (value) { - ret = tsl2x7x_als_calibrate(indio_dev); - if (ret < 0) - return ret; - } + ret = tsl2x7x_als_calibrate(indio_dev); + if (ret < 0) + return ret; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) @@ -932,14 +928,12 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev, bool value; int ret; - if (strtobool(buf, &value)) + if (kstrtobool(buf, &value) || !value) return -EINVAL; - if (value) { - ret = tsl2x7x_prox_cal(indio_dev); - if (ret < 0) - return ret; - } + ret = tsl2x7x_prox_cal(indio_dev); + if (ret < 0) + return ret; ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) |