summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalah Triki <salah.triki@gmail.com>2026-08-23 05:23:00 +0100
committerJonathan Cameron <jonathan.cameron@oss.qualcomm.com>2026-08-31 02:58:30 +0100
commit61fff9cebbfdf39bbd04d366882476d1def14047 (patch)
tree07be722b4b6ab1a8c6c8dc2c3a5c74afc8a6270a
parent034e8a7308e83b09a78f2642bfef37d272cf5f59 (diff)
downloadlinux-next-61fff9cebbfdf39bbd04d366882476d1def14047.tar.gz
linux-next-61fff9cebbfdf39bbd04d366882476d1def14047.zip
iio: temperature: tmp117: fix calibbias cache update on I2C write failure
The calibbias cache (data->calibbias) was updated before the I2C write to TMP117_REG_TEMP_OFFSET was known to succeed. If the write failed, the function correctly returned an error, but the driver's internal cache had already been updated to the new value. This causes the cache and the actual hardware register to go out of sync: a subsequent write of the same value would be silently skipped by the early "if (off == data->calibbias) return 0;" check, since the cache matches even though the register was never successfully updated. Update data->calibbias only after confirming the I2C write succeeded, so the cache always reflects the actual state of the device. Found by code inspection. Fixes: df041e737a38 ("iio: temperature: add driver support for ti tmp117") Signed-off-by: Salah Triki <salah.triki@gmail.com> Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
-rw-r--r--drivers/iio/temperature/tmp117.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/iio/temperature/tmp117.c b/drivers/iio/temperature/tmp117.c
index 74cb8d62bef3..3d8c97aa0d99 100644
--- a/drivers/iio/temperature/tmp117.c
+++ b/drivers/iio/temperature/tmp117.c
@@ -97,15 +97,20 @@ static int tmp117_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec
{
struct tmp117_data *data = iio_priv(indio_dev);
s16 off;
+ int ret;
switch (mask) {
case IIO_CHAN_INFO_CALIBBIAS:
off = clamp_t(int, val, S16_MIN, S16_MAX);
if (off == data->calibbias)
return 0;
+
+ ret = i2c_smbus_write_word_swapped(data->client, TMP117_REG_TEMP_OFFSET, off);
+ if (ret)
+ return ret;
+
data->calibbias = off;
- return i2c_smbus_write_word_swapped(data->client,
- TMP117_REG_TEMP_OFFSET, off);
+ return 0;
default:
return -EINVAL;