linux/drivers/iio/magnetometer
Jakob Hauser f1ee5483e4 iio: magnetometer: yas530: use signed integer type for clamp limits
In the function yas537_measure() there is a clamp_val() with limits of
-BIT(13) and BIT(13) - 1.  The input clamp value h[] is of type s32.  The
BIT() is of type unsigned long integer due to its define in
include/vdso/bits.h.  The lower limit -BIT(13) is recognized as -8192 but
expressed as an unsigned long integer.  The size of an unsigned long
integer differs between 32-bit and 64-bit architectures.  Converting this
to type s32 may lead to undesired behavior.

Additionally, in the calculation lines h[0], h[1] and h[2] the unsigned
long integer divisor BIT(13) causes an unsigned division, shifting the
left-hand side of the equation back and forth, possibly ending up in large
positive values instead of negative values on 32-bit architectures.

To solve those two issues, declare a signed integer with a value of
BIT(13).

There is another omission in the clamp line: clamp_val() returns a value
and it's going nowhere here.  Self-assign it to h[i] to make use of the
clamp macro.

Finally, replace clamp_val() macro by clamp() because after changing the
limits from type unsigned long integer to signed integer it's fine that
way.

Link: https://lkml.kernel.org/r/11609b2243c295d65ab4d47e78c239d61ad6be75.1732914810.git.jahau@rocketmail.com
Fixes: 65f79b5010 ("iio: magnetometer: yas530: Add YAS537 variant")
Signed-off-by: Jakob Hauser <jahau@rocketmail.com>

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202411230458.dhZwh3TT-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202411282222.oF0B4110-lkp@intel.com/
Reviewed-by: David Laight <david.laight@aculab.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-12-05 19:54:48 -08:00
..
af8133j.c iio: magnetometer: fix if () scoped_guard() formatting 2024-11-11 11:49:47 +01:00
ak8974.c iio: magn: ak8974: use irq_get_trigger_type() 2024-09-30 09:20:59 +01:00
ak8975.c iio: magnetometer: ak8975: Add AK09118 support 2024-09-03 18:49:43 +01:00
als31300.c iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver 2024-11-03 20:33:44 +00:00
bmc150_magn_i2c.c iio: magnetometer: bmc150_magn: Drop most likely fake ACPI IDs 2024-10-21 19:19:24 +01:00
bmc150_magn_spi.c iio: magnetometer: bmc150_magn: Drop most likely fake ACPI IDs 2024-10-21 19:19:24 +01:00
bmc150_magn.c iio: magnetometer: bmc150: Drop dead code from the driver 2024-10-28 20:04:11 +00:00
bmc150_magn.h iio:magnetometer:mbc150: Make bmc150_magn_remove() return void 2022-06-11 14:35:27 +01:00
hid-sensor-magn-3d.c iio: Switch back to struct platform_driver::remove() 2024-10-10 19:31:50 +01:00
hmc5843_core.c iio: magn: hmc5843: Move struct dev_pm_ops out of header 2022-08-15 22:30:02 +01:00
hmc5843_i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
hmc5843_spi.c iio: magn: hmc5843: Move struct dev_pm_ops out of header 2022-08-15 22:30:02 +01:00
hmc5843.h iio: magn: hmc5843: Move struct dev_pm_ops out of header 2022-08-15 22:30:02 +01:00
Kconfig iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver 2024-11-03 20:33:44 +00:00
mag3110.c iio: Drop explicit initialization of struct i2c_device_id::driver_data to 0 2024-05-27 09:48:57 +01:00
Makefile iio: magnetometer: add Allegro MicroSystems ALS31300 3-D Linear Hall Effect driver 2024-11-03 20:33:44 +00:00
mmc35240.c iio: magnetometer: mmc35240: make use of regmap_set_bits() 2024-06-25 21:04:47 +01:00
rm3100-core.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
rm3100-i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
rm3100-spi.c iio:magnetometer:rm3100: Move exports to IIO_RM3100 namespace 2022-02-18 11:42:27 +00:00
rm3100.h iio: magnetometer: Add driver support for PNI RM3100 2018-11-16 18:32:31 +00:00
st_magn_buffer.c iio:st-sensors: Remove duplicate MODULE_* 2022-02-18 11:36:54 +00:00
st_magn_core.c iio: magnetometer: st_accel: Add LSM303D 2023-05-13 17:56:04 +01:00
st_magn_i2c.c iio: Switch i2c drivers back to use .probe() 2023-05-21 18:54:53 +01:00
st_magn_spi.c iio: magnetometer: st_magn: Add LSM303C 2023-01-08 13:01:02 +00:00
st_magn.h iio: magnetometer: st_magn: Add LSM303C 2023-01-08 13:01:02 +00:00
tmag5273.c iio: tmag5273: Remove some unused field in struct tmag5273_data 2024-05-27 09:48:56 +01:00
yamaha-yas530.c iio: magnetometer: yas530: use signed integer type for clamp limits 2024-12-05 19:54:48 -08:00