Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers: iio: adc: ltc2497: fix LSB shift

Correct the "sub_lsb" shift for the ltc2497 and drop the sub_lsb element
which is now constant.

An earlier version of the code shifted by 14 but this was a consequence
of reading three bytes into a __be32 buffer and using be32_to_cpu(), so
eight extra bits needed to be skipped. Now we use get_unaligned_be24()
and thus the additional skip is wrong.

Fixes: 2187cfeb3626 ("drivers: iio: adc: ltc2497: LTC2499 support")
Signed-off-by: Ian Ray <ian.ray@ge.com>
Link: https://lore.kernel.org/r/20230127125714.44608-1-ian.ray@ge.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Ian Ray and committed by
Jonathan Cameron
6327a930 701c875a

+2 -4
+2 -4
drivers/iio/adc/ltc2497.c
··· 28 28 struct ltc2497core_driverdata common_ddata; 29 29 struct i2c_client *client; 30 30 u32 recv_size; 31 - u32 sub_lsb; 32 31 /* 33 32 * DMA (thus cache coherency maintenance) may require the 34 33 * transfer buffers to live in their own cache lines. ··· 64 65 * equivalent to a sign extension. 65 66 */ 66 67 if (st->recv_size == 3) { 67 - *val = (get_unaligned_be24(st->data.d8) >> st->sub_lsb) 68 + *val = (get_unaligned_be24(st->data.d8) >> 6) 68 69 - BIT(ddata->chip_info->resolution + 1); 69 70 } else { 70 - *val = (be32_to_cpu(st->data.d32) >> st->sub_lsb) 71 + *val = (be32_to_cpu(st->data.d32) >> 6) 71 72 - BIT(ddata->chip_info->resolution + 1); 72 73 } 73 74 ··· 121 122 st->common_ddata.chip_info = chip_info; 122 123 123 124 resolution = chip_info->resolution; 124 - st->sub_lsb = 31 - (resolution + 1); 125 125 st->recv_size = BITS_TO_BYTES(resolution) + 1; 126 126 127 127 return ltc2497core_probe(dev, indio_dev);