summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSong Hongyan <hongyan.song@intel.com>2016-11-03 00:45:48 +0000
committerJonathan Cameron <jic23@kernel.org>2016-11-05 16:25:33 +0000
commitab54163190f236e30772e6e8b4efc56a319ed0a6 (patch)
treee367d162de3d6f512ceeca4626dbaa50d370c93a
parent43a07e48af44c153f960e4a204771d5911e10134 (diff)
downloadlinux-ab54163190f236e30772e6e8b4efc56a319ed0a6.tar.gz
linux-ab54163190f236e30772e6e8b4efc56a319ed0a6.tar.bz2
linux-ab54163190f236e30772e6e8b4efc56a319ed0a6.zip
iio: hid-sensor-attributes: Check sample_frequency/hysteresis write data legitimacy
Neither sample frequency value nor hysteresis value can be set to be a negative number, check and return "Invalid argument" if they are negative. If not do this change, sample_frequency will be set into some unknown value, read hysteresis value after write negative number will return "Invalid argument". Signed-off-by: Song Hongyan <hongyan.song@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-attributes.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index dc33c1dd5191..4509f8475c54 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -201,7 +201,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
int ret;
if (val1 < 0 || val2 < 0)
- ret = -EINVAL;
+ return -EINVAL;
value = val1 * pow_10(6) + val2;
if (value) {
@@ -250,6 +250,9 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
s32 value;
int ret;
+ if (val1 < 0 || val2 < 0)
+ return -EINVAL;
+
value = convert_to_vtf_format(st->sensitivity.size,
st->sensitivity.unit_expo,
val1, val2);