diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2021-01-07 11:44:27 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-13 01:34:27 +0000 |
commit | ea99e40f31445e67659c09b32cab6857cad8b83e (patch) | |
tree | 76d2eb2b5306bc1ce7f886a9bd96681023350bbb | |
parent | 0bbf86f74a0cfb2155cac12864b126dbf7c0be0d (diff) | |
download | chrome-ec-ea99e40f31445e67659c09b32cab6857cad8b83e.tar.gz |
common: motion: fix races at shutdown
Do not use collection_rate blindly after a function may have slept:
the HOOK task could have run suspend() or suspend() call and set it to
0.
Fixes 104f5257 ("motion: Control on which task sensor setting functions are running on")
[CL:2553347]
BUG=b:176918310, b:170703322
BRANCH=kukui
TEST=unit test.
Change-Id: I9ef13ceca195db4b48866f1e53f9408fb2bbf595
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2616137
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r-- | common/motion_sense.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index f75332fafe..efb6552078 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -618,11 +618,8 @@ static void update_sense_data(uint8_t *lpc_status, int *psample_id) static int motion_sense_read(struct motion_sensor_t *sensor) { - if (sensor->state != SENSOR_INITIALIZED) - return EC_ERROR_UNKNOWN; - - if (sensor->drv->get_data_rate(sensor) == 0) - return EC_ERROR_NOT_POWERED; + ASSERT(sensor->state == SENSOR_INITIALIZED); + ASSERT(sensor->drv->get_data_rate(sensor) != 0); /* * If the sensor is in spoof mode, the readings are already present in @@ -723,8 +720,14 @@ static int motion_sense_process(struct motion_sensor_t *sensor, } if (motion_sensor_in_forced_mode(sensor)) { if (motion_sensor_time_to_read(ts, sensor)) { - ret = motion_sense_read(sensor); + /* + * Since motion_sense_read can sleep, other task may be + * scheduled. In particular if suspend is called by + * HOOKS task, it may set colleciton_rate to 0 and we + * would crash in increment_sensor_collection. + */ increment_sensor_collection(sensor, ts); + ret = motion_sense_read(sensor); } else { ret = EC_ERROR_BUSY; } @@ -823,7 +826,7 @@ static void check_and_queue_gestures(uint32_t *event) &motion_sensors[LID_ACCEL]; if (SENSOR_ACTIVE(sensor) && - (sensor->state == SENSOR_INITIALIZED)) { + (sensor->state == SENSOR_INITIALIZED)) { struct ec_response_motion_sensor_data vector = { .flags = 0, .activity_data.activity = |