提交 cd62322a 编写于 作者: I Irina Tirdea 提交者: Jonathan Cameron

iio: accel: mma9553: fix endianness issue when reading status

Refactor code for simplicity and clarity.

This also fixes an endianness issue with the original code.
When reading multiple registers, the received buffer of
16-bytes words is little endian (status, step count). On
big endian machines, casting them to u32 would result in
reversed order in the buffer (step count, status) leading
to incorrect values for step count and activity.
Signed-off-by: NIrina Tirdea <irina.tirdea@intel.com>
Reported-by: NHartmut Knaack <knaack.h@gmx.de>
Signed-off-by: NJonathan Cameron <jic23@kernel.org>
上级 8e71c04f
...@@ -316,22 +316,19 @@ static int mma9553_set_config(struct mma9553_data *data, u16 reg, ...@@ -316,22 +316,19 @@ static int mma9553_set_config(struct mma9553_data *data, u16 reg,
static int mma9553_read_activity_stepcnt(struct mma9553_data *data, static int mma9553_read_activity_stepcnt(struct mma9553_data *data,
u8 *activity, u16 *stepcnt) u8 *activity, u16 *stepcnt)
{ {
u32 status_stepcnt; u16 buf[2];
u16 status;
int ret; int ret;
ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER, ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER,
MMA9553_REG_STATUS, sizeof(u32), MMA9553_REG_STATUS, sizeof(u32), buf);
(u16 *) &status_stepcnt);
if (ret < 0) { if (ret < 0) {
dev_err(&data->client->dev, dev_err(&data->client->dev,
"error reading status and stepcnt\n"); "error reading status and stepcnt\n");
return ret; return ret;
} }
status = status_stepcnt & MMA9553_MASK_CONF_WORD; *activity = mma9553_get_bits(buf[0], MMA9553_MASK_STATUS_ACTIVITY);
*activity = mma9553_get_bits(status, MMA9553_MASK_STATUS_ACTIVITY); *stepcnt = buf[1];
*stepcnt = status_stepcnt >> 16;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册