linux/drivers/iio/accel
Matti Vaittinen 1344ff89fe 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:41: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 iio: accel: adxl313: simplify with spi_get_device_match_data() 2024-06-13 19:19:23 +01:00
adxl345.h iio: accel: adxl345: Add spi-3wire option 2024-04-06 16:18:39 +01:00
adxl345_core.c iio: accel: adxl345: Add comment to probe 2024-04-06 16:18:39 +01:00
adxl345_i2c.c iio: accel: adxl345: Pass function pointer to core 2024-04-06 16:18:39 +01:00
adxl345_spi.c iio: accel: adxl345: Add spi-3wire option 2024-04-06 16:18:39 +01:00
adxl355.h drivers: iio: accel: Add support for ADXL359 device 2022-11-23 19:44:04 +00:00
adxl355_core.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
adxl355_i2c.c iio: accel: adxl355: Simplify probe() 2023-07-22 17:24:51 +01:00
adxl355_spi.c iio: accel: adxl355: simplify with spi_get_device_match_data() 2024-06-13 19:19:23 +01:00
adxl367.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
adxl367.h iio: accel: add ADXL367 driver 2022-02-21 19:33:06 +00:00
adxl367_i2c.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
adxl367_spi.c iio: accel: adxl367: Constify struct regmap_bus 2024-07-29 20:31:09 +01:00
adxl372.c iio: accel: adxl372: make use of iio_get_masklength() 2024-07-29 20:31:07 +01:00
adxl372.h iio: adxl372: Add support for I2C communication 2018-09-08 15:54:38 +01:00
adxl372_i2c.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
adxl372_spi.c iio: accel: adxl372: Switch from linux/of.h to linux/mod_devicetable.h 2024-02-28 19:26:35 +00:00
adxl380.c iio: accel: adxl380: fix raw sample read 2024-12-05 14:02:37 +01:00
adxl380.h iio: accel: add ADXL380 driver 2024-08-03 10:13:36 +01:00
adxl380_i2c.c iio: accel: add ADXL380 driver 2024-08-03 10:13:36 +01:00
adxl380_spi.c iio: accel: add ADXL380 driver 2024-08-03 10:13:36 +01:00
bma180.c iio: accel: bma180: make use of iio_for_each_active_channel() 2024-07-29 20:31:07 +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: 1st set of fixes for the 6.12 cycle. 2024-10-13 17:23:47 +02:00
bma400_i2c.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
bma400_spi.c iio: accel: bma400: Constify struct regmap_bus 2024-07-29 20:31:09 +01:00
bmc150-accel-core.c iio: accel: bmc150: Improve bmc150_apply_bosc0200_acpi_orientation() 2024-09-03 18:49:43 +01:00
bmc150-accel-i2c.c iio: accel: bmc150: Document duplicate ACPI entries with bmi323 driver 2024-02-19 19:34:44 +00:00
bmc150-accel-spi.c iio: accel: bmc150: Drop ACPI_PTR() 2024-01-23 22:06:54 +00: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 move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
bmi088-accel-i2c.c iio: accel: bmi088: add i2c support for bmi088 accel driver 2024-01-23 22:06:56 +00:00
bmi088-accel-spi.c iio: accel: bmi088: Constify struct regmap_bus 2024-07-29 20:31:10 +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: accel: cros_ec_accel_legacy: make use of iio_get_masklength() 2024-07-29 20:31:08 +01:00
da280.c iio: accel: da280: Stop using ACPI_PTR() 2024-01-23 22:06:54 +00:00
da311.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
dmard06.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
dmard09.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
dmard10.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
fxls8962af-core.c iio: accel: fxls8962af-core: make use of iio_for_each_active_channel() 2024-07-29 20:31:08 +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: Remove unused declarations 2023-09-12 10:42:03 +01:00
hid-sensor-accel-3d.c iio: accel: hid-sensor-accel-3d: Convert to platform remove callback returning void 2023-09-23 15:06:52 +01:00
Kconfig iio: accel: kx022a: add missing select IIO_(TRIGGERED_)BUFFER in Kconfig 2024-10-06 16:27:25 +01:00
kionix-kx022a-i2c.c iio: kx022a: Support ROHM KX132ACR-LBZ 2023-10-05 14:44:06 +01:00
kionix-kx022a-spi.c iio: kx022a: Support ROHM KX132ACR-LBZ 2023-10-05 14:44:06 +01:00
kionix-kx022a.c iio: accel: kx022a: Fix raw read format 2024-12-09 10:41:09 +01:00
kionix-kx022a.h iio: kx022a: Support ROHM KX132ACR-LBZ 2023-10-05 14:44:06 +01:00
kxcjk-1013.c iio: accel: kxcjk-1013: Add support for KX022-1020 2024-08-03 10:13:38 +01:00
kxsd9-i2c.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
kxsd9-spi.c iio: accel: kxsd9: Switch from linux/of.h to linux/mod_devicetable.h 2024-02-28 19:26:35 +00:00
kxsd9.c iio: accel: kxsd9: Make use of regmap_clear_bits() 2024-06-25 21:04:43 +01:00
kxsd9.h iio: accel: kxsd9: Make kxsd9_common_remove() return void 2021-10-19 08:30:45 +01:00
Makefile iio: accel: add ADXL380 driver 2024-08-03 10:13:36 +01:00
mc3230.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +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: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +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: accel: mma7660: add mount-matrix support 2024-06-13 19:19:22 +01:00
mma8452.c iio: accel: mma8452: Switch from of specific to fwnode property handling. 2024-03-25 19:50:10 +00:00
mma9551.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +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: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
msa311.c iio: accel: msa311: make use of iio_for_each_active_channel() 2024-07-29 20:31:08 +01:00
mxc4005.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
mxc6255.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
sca3000.c iio: accel: sca3000: Fix alignment for DMA safety 2022-06-14 11:53:12 +01:00
sca3300.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04: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: st_accel: add support for LIS2DS12 2024-06-25 21:04:49 +01:00
st_accel_buffer.c iio:st-sensors: Remove duplicate MODULE_* 2022-02-18 11:36:54 +00:00
st_accel_core.c iio: accel: st_accel: add support for LIS2DS12 2024-06-25 21:04:49 +01:00
st_accel_i2c.c iio: accel: st_accel: add support for LIS2DS12 2024-06-25 21:04:49 +01:00
st_accel_spi.c iio: accel: st_accel: add support for LIS2DS12 2024-06-25 21:04:49 +01:00
stk8ba50.c iio: accel: stk8ba50: make use of iio_for_each_active_channel() 2024-07-29 20:31:08 +01:00
stk8312.c iio: accel: stk8312: make use of iio_for_each_active_channel() 2024-07-29 20:31:08 +01:00