summaryrefslogtreecommitdiff
path: root/driver/accelgyro_lsm6dsm.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2018-08-31 12:55:38 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-09-05 05:11:38 -0700
commitf932679e653a4b62fbe1fb28fba8a20d7a7e38c2 (patch)
tree91dab26624c7dffe72f3a0a797abfd0a1605c2e0 /driver/accelgyro_lsm6dsm.c
parent837c7609f290d4694c3912aaeb4562fbf4b59b8e (diff)
downloadchrome-ec-f932679e653a4b62fbe1fb28fba8a20d7a7e38c2.tar.gz
driver: accel: Prevent ODR from crashing the EC
For accelerometers which are interrupt driven, setting ODR too high may exhaust the EC and trigger the watchdog timer. Use config variable to verify the ODR requested is not too big. Return an error when setting unsupported parameters. BUG=b:112672627 BRANCH=nocturne,eve TEST=Without this change, ectool motionsense odr 0 500000 crashes the EC Now, it returns EC result 3 (INVALID_PARAM) Change-Id: I64a4e522dcad450d619a7fc48a1330479f1cf81f Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1200068 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/accelgyro_lsm6dsm.c')
-rw-r--r--driver/accelgyro_lsm6dsm.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c
index da445ec491..45c76e8068 100644
--- a/driver/accelgyro_lsm6dsm.c
+++ b/driver/accelgyro_lsm6dsm.c
@@ -446,7 +446,9 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
reg_val++;
normalized_rate = LSM6DSM_REG_TO_ODR(reg_val);
}
- if (normalized_rate == 0)
+ if (normalized_rate < LSM6DSM_ODR_MIN_VAL ||
+ normalized_rate > MIN(LSM6DSM_ODR_MAX_VAL,
+ CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ))
return EC_RES_INVALID_PARAM;
} else {
reg_val = 0;