Skip to content

Commit b500c08

Browse files
stephan-ghjic23
authored andcommitted
iio: magnetometer: ak8974: Fix negative raw values in sysfs
At the moment, reading from in_magn_*_raw in sysfs tends to return large values around 65000, even though the output of ak8974 is actually limited to ±32768. This happens because the value is never converted to the signed 16-bit integer variant. Add an explicit cast to s16 to fix this. Fixes: 7c94a8b ("iio: magn: add a driver for AK8974") Signed-off-by: Stephan Gerhold <[email protected]> Reviewed-by: Linus Waleij <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 29e8c82 commit b500c08

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/iio/magnetometer/ak8974.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ static int ak8974_read_raw(struct iio_dev *indio_dev,
564564
* We read all axes and discard all but one, for optimized
565565
* reading, use the triggered buffer.
566566
*/
567-
*val = le16_to_cpu(hw_values[chan->address]);
567+
*val = (s16)le16_to_cpu(hw_values[chan->address]);
568568

569569
ret = IIO_VAL_INT;
570570
}

0 commit comments

Comments
 (0)