diff options
author | Paul Ma <magf@bitland.corp-partner.google.com> | 2018-06-19 16:44:04 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-22 02:39:43 -0700 |
commit | 286faa5e78ef2f6768ae6eb06a7a54024f87e7d5 (patch) | |
tree | 952da0a44ce172451fd0f482c44a4a3670b16058 | |
parent | 8032e90ccbceaf799eeabf6709ab66981b6cf720 (diff) | |
download | chrome-ec-286faa5e78ef2f6768ae6eb06a7a54024f87e7d5.tar.gz |
FIXUP: fix lsm6dsm driver specific data type declaration
accelgyro_lsm6dsm driver use lsm6dsm_data as its driver specific
data type rather than stprivate_data. Wrong data type will lead
to random corrupted runtime data.
Signed-off-by: Paul Ma <magf@bitland.corp-partner.google.com>
BRANCH=none
BUG=b:110013316
TEST=make buildall -j
Change-Id: I50e0da293921c2662e97aa6f47c83519609186b5
Reviewed-on: https://chromium-review.googlesource.com/1105797
Commit-Ready: Paul Ma <magf@bitland.corp-partner.google.com>
Tested-by: Paul Ma <magf@bitland.corp-partner.google.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | board/fleex/board.c | 4 | ||||
-rw-r--r-- | board/yorp/board.c | 4 | ||||
-rw-r--r-- | board/zoombini/board.c | 4 | ||||
-rw-r--r-- | driver/accelgyro_lsm6dsm.c | 32 | ||||
-rw-r--r-- | driver/accelgyro_lsm6dsm.h | 8 |
5 files changed, 45 insertions, 7 deletions
diff --git a/board/fleex/board.c b/board/fleex/board.c index 715ce7501b..d4887f9e83 100644 --- a/board/fleex/board.c +++ b/board/fleex/board.c @@ -116,8 +116,8 @@ const matrix_3x3_t base_standard_ref = { /* sensor private data */ static struct kionix_accel_data g_kx022_data; -static struct stprivate_data lsm6dsm_g_data; -static struct stprivate_data lsm6dsm_a_data; +static struct lsm6dsm_data lsm6dsm_g_data; +static struct lsm6dsm_data lsm6dsm_a_data; /* Drivers */ struct motion_sensor_t motion_sensors[] = { diff --git a/board/yorp/board.c b/board/yorp/board.c index a2cf80976a..77eb5cd5f1 100644 --- a/board/yorp/board.c +++ b/board/yorp/board.c @@ -116,8 +116,8 @@ const matrix_3x3_t base_standard_ref = { /* sensor private data */ static struct kionix_accel_data g_kx022_data; -static struct stprivate_data lsm6dsm_g_data; -static struct stprivate_data lsm6dsm_a_data; +static struct lsm6dsm_data lsm6dsm_g_data; +static struct lsm6dsm_data lsm6dsm_a_data; /* Drivers */ struct motion_sensor_t motion_sensors[] = { diff --git a/board/zoombini/board.c b/board/zoombini/board.c index 2ff6b179a1..9d264b1fbf 100644 --- a/board/zoombini/board.c +++ b/board/zoombini/board.c @@ -219,8 +219,8 @@ static struct mutex g_base_mutex; */ struct lsm6dsm_data lsm6dsm_a_data; -struct stprivate_data lsm6dsm_g_data; -struct stprivate_data lsm6dsm_m_data; +struct lsm6dsm_data lsm6dsm_g_data; +struct lsm6dsm_data lsm6dsm_m_data; struct motion_sensor_t motion_sensors[] = { [LID_ACCEL] = { diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c index d0ef49b906..683b2ed616 100644 --- a/driver/accelgyro_lsm6dsm.c +++ b/driver/accelgyro_lsm6dsm.c @@ -337,6 +337,14 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd) { int err; uint8_t ctrl_reg, reg_val; + /* + * Since 'stprivate_data a_data;' is the first member of lsm6dsm_data, + * the address of lsm6dsm_data is the same as a_data's. Using this + * fact, we can do the following conversion. This conversion is equal + * to: + * struct lsm6dsm_data *lsm_data = s->drv_data; + * struct stprivate_data *data = &lsm_data->a_data; + */ struct stprivate_data *data = s->drv_data; int newrange = range; @@ -381,6 +389,14 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd) */ static int get_range(const struct motion_sensor_t *s) { + /* + * Since 'stprivate_data a_data;' is the first member of lsm6dsm_data, + * the address of lsm6dsm_data is the same as a_data's. Using this + * fact, we can do the following conversion. This conversion is equal + * to: + * struct lsm6dsm_data *lsm_data = s->drv_data; + * struct stprivate_data *data = &lsm_data->a_data; + */ struct stprivate_data *data = s->drv_data; if (s->type == MOTIONSENSE_TYPE_ACCEL) @@ -399,6 +415,14 @@ static int get_range(const struct motion_sensor_t *s) static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd) { int ret, normalized_rate; + /* + * Since 'stprivate_data a_data;' is the first member of lsm6dsm_data, + * the address of lsm6dsm_data is the same as a_data's. Using this + * fact, we can do the following conversion. This conversion is equal + * to: + * struct lsm6dsm_data *lsm_data = s->drv_data; + * struct stprivate_data *data = &lsm_data->a_data; + */ struct stprivate_data *data = s->drv_data; uint8_t ctrl_reg, reg_val; @@ -491,6 +515,14 @@ static int read(const struct motion_sensor_t *s, vector_3_t v) static int init(const struct motion_sensor_t *s) { int ret = 0, tmp; + /* + * Since 'stprivate_data a_data;' is the first member of lsm6dsm_data, + * the address of lsm6dsm_data is the same as a_data's. Using this + * fact, we can do the following conversion. This conversion is equal + * to: + * struct lsm6dsm_data *lsm_data = s->drv_data; + * struct stprivate_data *data = &lsm_data->a_data; + */ struct stprivate_data *data = s->drv_data; ret = st_raw_read8(s->port, s->addr, LSM6DSM_WHO_AM_I_REG, &tmp); diff --git a/driver/accelgyro_lsm6dsm.h b/driver/accelgyro_lsm6dsm.h index bb332f71b5..cc4b2eafc6 100644 --- a/driver/accelgyro_lsm6dsm.h +++ b/driver/accelgyro_lsm6dsm.h @@ -223,7 +223,13 @@ struct lsm6dsm_fifo_data { int total_samples_in_pattern; }; - +/* + * Please refer to b:110013316, motion_sensor_t.drv_data field should + * use this data type pointer rather than stprivate_data type pointer. + * Use stprivate_data type will lead to random corrupted runtime data + * since stprivate_data is smaller than required once CONFIG_ACCEL_FIFO + * is defined. + */ struct lsm6dsm_data { /* Must be first: ST generic accelerometer data. */ struct stprivate_data a_data; |