Skip to content

Commit

Permalink
iio: accel: mma9553: fix endianness issue when reading status
Browse files Browse the repository at this point in the history
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: Irina Tirdea <irina.tirdea@intel.com>
Reported-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
  • Loading branch information
Irina Tirdea authored and Jonathan Cameron committed Apr 26, 2015
1 parent 8e71c04 commit cd62322
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions drivers/iio/accel/mma9553.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
u8 *activity, u16 *stepcnt)
{
u32 status_stepcnt;
u16 status;
u16 buf[2];
int ret;

ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER,
MMA9553_REG_STATUS, sizeof(u32),
(u16 *) &status_stepcnt);
MMA9553_REG_STATUS, sizeof(u32), buf);
if (ret < 0) {
dev_err(&data->client->dev,
"error reading status and stepcnt\n");
return ret;
}

status = status_stepcnt & MMA9553_MASK_CONF_WORD;
*activity = mma9553_get_bits(status, MMA9553_MASK_STATUS_ACTIVITY);
*stepcnt = status_stepcnt >> 16;
*activity = mma9553_get_bits(buf[0], MMA9553_MASK_STATUS_ACTIVITY);
*stepcnt = buf[1];

return 0;
}
Expand Down

0 comments on commit cd62322

Please sign in to comment.