summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorInno.Park <ih.yoo.park@samsung.corp-partner.google.com>2020-10-13 15:17:13 +0900
committerCommit Bot <commit-bot@chromium.org>2020-10-14 11:55:50 +0000
commit95e90b8132568e3872137d8649168816c8ece46a (patch)
treee3628760e39a6d2ecc892a2802fd377cff6dc277 /driver
parent47ad9dc4f65380d1c55d8d046c3fd44dc445ee3e (diff)
downloadchrome-ec-95e90b8132568e3872137d8649168816c8ece46a.tar.gz
driver: lis2ds: set up the minimum value for set_range
Current lis2ds driver is vulnerable to unrestrained input for range setting. The system gets rebooted as setting a range to 0 or negative. This CL set up minimum range in set_range() to filter input 0 or below. BUG=b:170688359 BRANCH=none TEST=run 'ectool motionsense range 0 0' and check if device rebooted Signed-off-by: Inno.Park <ih.yoo.park@samsung.corp-partner.google.com> Change-Id: I24e68635584ecddab415df8d7af0250a62f28d40 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2467416 Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/accel_lis2ds.c2
-rw-r--r--driver/accel_lis2ds.h1
2 files changed, 3 insertions, 0 deletions
diff --git a/driver/accel_lis2ds.c b/driver/accel_lis2ds.c
index a055d533b9..c064cba03c 100644
--- a/driver/accel_lis2ds.c
+++ b/driver/accel_lis2ds.c
@@ -190,6 +190,8 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd)
if (newrange > LIS2DS_ACCEL_FS_MAX_VAL)
newrange = LIS2DS_ACCEL_FS_MAX_VAL;
+ else if (newrange < LIS2DS_ACCEL_FS_MIN_VAL)
+ newrange = LIS2DS_ACCEL_FS_MIN_VAL;
reg_val = LIS2DS_FS_REG(newrange);
diff --git a/driver/accel_lis2ds.h b/driver/accel_lis2ds.h
index b8e7f544f4..e25bc5954f 100644
--- a/driver/accel_lis2ds.h
+++ b/driver/accel_lis2ds.h
@@ -143,6 +143,7 @@ enum lis2ds_fs {
};
#define LIS2DS_ACCEL_FS_MAX_VAL 16
+#define LIS2DS_ACCEL_FS_MIN_VAL 2
/* Reg value from Full Scale */
#define LIS2DS_FS_REG(_fs) \