iio: magnetometer: ak8974: Fix negative raw values in sysfs
authorStephan Gerhold <stephan@gerhold.net>
Fri, 14 Feb 2020 11:03:24 +0000 (12:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Apr 2020 14:34:17 +0000 (16:34 +0200)
commit7934f5c57db8927fad85ed09a9c2df9d7aab0459
tree6ec672d8035e97aa12e585efcdd461c985dcb2fe
parent5d777b76b2eddd3887c57a635643aacab3e437ce
iio: magnetometer: ak8974: Fix negative raw values in sysfs

commit b500c086e4110829a308c23e83a7cdc65b26228a upstream.

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: 7c94a8b2ee8c ("iio: magn: add a driver for AK8974")
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Reviewed-by: Linus Waleij <linus.walleij@linaro.org>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/magnetometer/ak8974.c