[PATCH 3/4] iio: hid-sensor-attributes: Add input sample frequency check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Check the validity of the sampling frequency set by user.

Signed-off-by: Song Hongyan <hongyan.song@xxxxxxxxx>
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index ad30814..408c16e 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -221,12 +221,26 @@ int hid_sensor_read_max_samp_freq_value(struct hid_sensor_common *st,
 int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
 				int val1, int val2)
 {
+	int max_freq_int, max_freq_dec;
 	s32 value;
 	int ret;
 
 	if (val1 < 0 || val2 < 0)
 		ret = -EINVAL;
 
+	ret = hid_sensor_read_max_samp_freq_value(st, &max_freq_int,
+						&max_freq_dec);
+	if (ret >= 0) {
+		/*
+		 * check whether the input sample freqency value is larger than
+		 * the max_freq_value.
+		 */
+		if (val1 > max_freq_int || (val1 == max_freq_int &&
+				val2 > max_freq_dec))
+			return -EINVAL;
+	} else {
+		hid_info(st->hsdev->hdev, "No max_sample_frequency!!!\n");
+	}
 	value = val1 * pow_10(6) + val2;
 	if (value) {
 		if (st->poll.units == HID_USAGE_SENSOR_UNITS_MILLISECOND)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux