diff options
author | Irina Tirdea <irina.tirdea@intel.com> | 2015-04-13 11:40:48 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2015-04-26 14:39:42 -0400 |
commit | cd62322a9767f9a0bcf855123c478187e38a10f4 (patch) | |
tree | 436f350ed4fa9d57fa42a1320234b0c47875058b /drivers/iio | |
parent | 8e71c04f863a1754f21b27fb8ecb773d680a0a80 (diff) |
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: Irina Tirdea <irina.tirdea@intel.com>
Reported-by: Hartmut Knaack <knaack.h@gmx.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/accel/mma9553.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c index 2df1af7d43fc..607dbfcb49ab 100644 --- a/drivers/iio/accel/mma9553.c +++ b/drivers/iio/accel/mma9553.c | |||
@@ -316,22 +316,19 @@ static int mma9553_set_config(struct mma9553_data *data, u16 reg, | |||
316 | static int mma9553_read_activity_stepcnt(struct mma9553_data *data, | 316 | static int mma9553_read_activity_stepcnt(struct mma9553_data *data, |
317 | u8 *activity, u16 *stepcnt) | 317 | u8 *activity, u16 *stepcnt) |
318 | { | 318 | { |
319 | u32 status_stepcnt; | 319 | u16 buf[2]; |
320 | u16 status; | ||
321 | int ret; | 320 | int ret; |
322 | 321 | ||
323 | ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER, | 322 | ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER, |
324 | MMA9553_REG_STATUS, sizeof(u32), | 323 | MMA9553_REG_STATUS, sizeof(u32), buf); |
325 | (u16 *) &status_stepcnt); | ||
326 | if (ret < 0) { | 324 | if (ret < 0) { |
327 | dev_err(&data->client->dev, | 325 | dev_err(&data->client->dev, |
328 | "error reading status and stepcnt\n"); | 326 | "error reading status and stepcnt\n"); |
329 | return ret; | 327 | return ret; |
330 | } | 328 | } |
331 | 329 | ||
332 | status = status_stepcnt & MMA9553_MASK_CONF_WORD; | 330 | *activity = mma9553_get_bits(buf[0], MMA9553_MASK_STATUS_ACTIVITY); |
333 | *activity = mma9553_get_bits(status, MMA9553_MASK_STATUS_ACTIVITY); | 331 | *stepcnt = buf[1]; |
334 | *stepcnt = status_stepcnt >> 16; | ||
335 | 332 | ||
336 | return 0; | 333 | return 0; |
337 | } | 334 | } |