diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2018-08-31 12:55:38 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-09-05 05:11:38 -0700 |
commit | f932679e653a4b62fbe1fb28fba8a20d7a7e38c2 (patch) | |
tree | 91dab26624c7dffe72f3a0a797abfd0a1605c2e0 /driver/accel_lis2dh.c | |
parent | 837c7609f290d4694c3912aaeb4562fbf4b59b8e (diff) | |
download | chrome-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/accel_lis2dh.c')
-rw-r--r-- | driver/accel_lis2dh.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/driver/accel_lis2dh.c b/driver/accel_lis2dh.c index a8e8827acd..df0b7be7de 100644 --- a/driver/accel_lis2dh.c +++ b/driver/accel_lis2dh.c @@ -96,14 +96,10 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd) normalized_rate = LIS2DH_REG_TO_NORMALIZE(reg_val); } - /* Adjust rounded value */ - if (reg_val > LIS2DH_ODR_400HZ_VAL) { - reg_val = LIS2DH_ODR_400HZ_VAL; - normalized_rate = LIS2DH_ODR_MAX_VAL; - } else if (reg_val < LIS2DH_ODR_1HZ_VAL) { - reg_val = LIS2DH_ODR_1HZ_VAL; - normalized_rate = LIS2DH_ODR_MIN_VAL; - } + if (normalized_rate > MIN(LIS2DH_ODR_MAX_VAL, + CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ) || + normalized_rate < LIS2DH_ODR_MIN_VAL) + return EC_RES_INVALID_PARAM; /* * Lock accel resource to prevent another task from attempting |