linux/drivers/iio/accel
Matti Vaittinen 8e5e63d6ca iio: accel: kx022a: Fix raw read format
commit b7d2bc99b3 upstream.

The KX022A provides the accelerometer data in two subsequent registers.
The registers are laid out so that the value obtained via bulk-read of
these registers can be interpreted as signed 16-bit little endian value.
The read value is converted to cpu_endianes and stored into 32bit integer.
The le16_to_cpu() casts value to unsigned 16-bit value, and when this is
assigned to 32-bit integer the resulting value will always be positive.

This has not been a problem to users (at least not all users) of the sysfs
interface, who know the data format based on the scan info and who have
converted the read value back to 16-bit signed value. This isn't
compliant with the ABI however.

This, however, will be a problem for those who use the in-kernel
interfaces, especially the iio_read_channel_processed_scale().

The iio_read_channel_processed_scale() performs multiplications to the
returned (always positive) raw value, which will cause strange results
when the data from the sensor has been negative.

Fix the read_raw format by casting the result of the le_to_cpu() to
signed 16-bit value before assigning it to the integer. This will make
the negative readings to be correctly reported as negative.

This fix will be visible to users by changing values returned via sysfs
to appear in correct (negative) format.

Reported-by: Kalle Niemi <kaleposti@gmail.com>
Fixes: 7c1d1677b3 ("iio: accel: Support Kionix/ROHM KX022A accelerometer")
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Tested-by: Kalle Niemi <kaleposti@gmail.com>
Cc: <Stable@vger.kernel.org>
Link: https://patch.msgid.link/ZyIxm_zamZfIGrnB@mva-rohm
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2024-12-09 10:33:09 +01:00
..
adis16201.c iio: accel: adis16201: Call '__adis_initial_startup()' in probe 2022-11-23 20:37:50 +00:00
adis16209.c iio: accel: adis16209: Call '__adis_initial_startup()' in probe 2022-11-23 20:37:50 +00:00
adxl313.h drivers: iio: accel: adxl312 and adxl314 support 2022-09-21 18:42:53 +01:00
adxl313_core.c drivers: iio: accel: adxl312 and adxl314 support 2022-09-21 18:42:53 +01:00
adxl313_i2c.c iio: accel: adxl313: Use i2c_get_match_data 2023-07-29 12:30:39 +01:00
adxl313_spi.c drivers: iio: accel: adxl312 and adxl314 support 2022-09-21 18:42:53 +01:00
adxl345.h iio: accel: adxl345: Make use of device properties 2022-02-26 19:11:13 +00:00
adxl345_core.c iio: accel: adxl345: use HZ macro from units.h 2022-08-28 16:57:37 +01:00
adxl345_i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
adxl345_spi.c iio: accel: adxl345: Remove unneeded blank lines 2022-02-26 19:11:39 +00:00
adxl355.h drivers: iio: accel: Add support for ADXL359 device 2022-11-23 19:44:04 +00:00
adxl355_core.c drivers: iio: accel: Add support for ADXL359 device 2022-11-23 19:44:04 +00:00
adxl355_i2c.c iio: accel: adxl355: Simplify probe() 2023-07-22 17:24:51 +01:00
adxl355_spi.c drivers: iio: accel: Add support for ADXL359 device 2022-11-23 19:44:04 +00:00
adxl367.c iio: accel: adxl367: fix DEVID read after reset 2024-04-03 15:28:45 +02:00
adxl367.h iio: accel: add ADXL367 driver 2022-02-21 19:33:06 +00:00
adxl367_i2c.c iio: accel: adxl367: fix I2C FIFO data register 2024-04-03 15:28:45 +02:00
adxl367_spi.c iio: accel: adxl367: Fix alignment for DMA safety 2022-06-14 11:53:11 +01:00
adxl372.c iio: Don't silently expect attribute types 2022-11-23 19:44:04 +00:00
adxl372.h iio: adxl372: Add support for I2C communication 2018-09-08 15:54:38 +01:00
adxl372_i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
adxl372_spi.c iio: adc: Explicitly include correct DT includes 2023-07-23 13:38:13 +01:00
bma180.c iio: adc: Explicitly include correct DT includes 2023-07-23 13:38:13 +01:00
bma220_spi.c iio: accel: bma220: Switch to DEFINE_SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() 2022-07-18 18:48:17 +01:00
bma400.h iio: accel: bma400: Use devm_regulator_bulk_get_enable() 2022-12-28 17:19:45 +00:00
bma400_core.c iio: accel: bma400: Fix uninitialized variable field_value in tap event handling. 2024-11-01 01:58:17 +01:00
bma400_i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
bma400_spi.c iio: accel: bma400: Add triggered buffer support 2022-06-11 14:35:26 +01:00
bmc150-accel-core.c iio: Don't silently expect attribute types 2022-11-23 19:44:04 +00:00
bmc150-accel-i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
bmc150-accel-spi.c Char/Misc and other driver updates for 5.18-rc1 2022-03-28 12:27:35 -07:00
bmc150-accel.h iio: accel: bmc150: Make bmc150_accel_core_remove() return void 2021-10-19 08:30:45 +01:00
bmi088-accel-core.c iio: accel: bmi088: Use EXPORT_NS_GPL_RUNTIME_DEV_PM_OPS() and pm_ptr() 2022-09-21 18:42:57 +01:00
bmi088-accel-spi.c iio: accel: bmi088: Use EXPORT_NS_GPL_RUNTIME_DEV_PM_OPS() and pm_ptr() 2022-09-21 18:42:57 +01:00
bmi088-accel.h iio: accel: bmi088: Add support for bmi090l accel 2022-06-11 14:35:28 +01:00
cros_ec_accel_legacy.c iio: cros: Register FIFO callback after sensor is registered 2022-07-18 18:29:13 +01:00
da280.c iio: accel: da280: Add support for the DA217 accelerometer 2023-07-20 19:21:29 +01:00
da311.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
dmard06.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
dmard09.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
dmard10.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
fxls8962af-core.c iio: accel: fxls8962af: errata bug only applicable for FXLS8962AF 2023-06-05 20:05:48 +01:00
fxls8962af-i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
fxls8962af-spi.c iio: accel: fxls8962af: Use new EXPORT_NS_GPL_DEV_PM_OPS() 2022-11-23 19:44:00 +00:00
fxls8962af.h iio: accel: fxls8962af: add padding to regmap for SPI 2022-01-23 18:23:48 +00:00
hid-sensor-accel-3d.c iio: hid: fix the retval in accel_3d_capture_sample 2023-01-14 16:31:20 +00:00
Kconfig iio: accel: kx022a: add missing select IIO_(TRIGGERED_)BUFFER in Kconfig 2024-10-22 15:46:31 +02:00
kionix-kx022a-i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
kionix-kx022a-spi.c iio: kx022a: Probe asynchronously 2023-05-13 17:56:06 +01:00
kionix-kx022a.c iio: accel: kx022a: Fix raw read format 2024-12-09 10:33:09 +01:00
kionix-kx022a.h iio: accel: Support Kionix/ROHM KX022A accelerometer 2022-11-23 19:44:03 +00:00
kxcjk-1013.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
kxsd9-i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
kxsd9-spi.c iio: adc: Explicitly include correct DT includes 2023-07-23 13:38:13 +01:00
kxsd9.c iio:accel:kxsd9: Switch from CONFIG_PM guards to pm_ptr() etc 2022-06-15 22:07:09 +01:00
kxsd9.h iio: accel: kxsd9: Make kxsd9_common_remove() return void 2021-10-19 08:30:45 +01:00
Makefile iio: accel: Support Kionix/ROHM KX022A accelerometer 2022-11-23 19:44:03 +00:00
mc3230.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
mma7455.h iio: accel: mma7455: Make mma7455_core_remove() return void 2021-10-19 08:30:45 +01:00
mma7455_core.c iio:accel:mma7455_core: Move exports into IIO_MMA7455 namespace 2022-02-18 11:36:53 +00:00
mma7455_i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
mma7455_spi.c Char/Misc and other driver updates for 5.18-rc1 2022-03-28 12:27:35 -07:00
mma7660.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
mma8452.c iio: adc: Explicitly include correct DT includes 2023-07-23 13:38:13 +01:00
mma9551.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
mma9551_core.c iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_config_word() 2023-01-28 17:40:17 +00:00
mma9551_core.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
mma9553.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
msa311.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
mxc4005.c iio: accel: mxc4005: Reset chip on probe() and resume() 2024-06-12 11:12:34 +02:00
mxc6255.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
sca3000.c iio: accel: sca3000: Fix alignment for DMA safety 2022-06-14 11:53:12 +01:00
sca3300.c iio: accel: sca3300: Silence no spi_device_id warning 2022-11-23 19:43:57 +00:00
ssp_accel_sensor.c iio: core: Simplify the registration of kfifo buffers 2022-04-10 16:25:46 +01:00
st_accel.h iio: accel: add support for IIS328DQ variant 2023-03-19 15:41:22 +00:00
st_accel_buffer.c iio:st-sensors: Remove duplicate MODULE_* 2022-02-18 11:36:54 +00:00
st_accel_core.c 1st set of IIO new device support, features and cleanup for the 6.5 cycle. 2023-06-15 13:01:55 +02:00
st_accel_i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
st_accel_spi.c iio: accel: add support for IIS328DQ variant 2023-03-19 15:41:22 +00:00
stk8ba50.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
stk8312.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00