From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8178B2E7386 for ; Sat, 22 Aug 2026 00:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787359779; cv=none; b=TE2d9OF4OxDDVfk3RZtME1uc3qqKmqJpmruuiCsZTagVDoFCUuMYdAHVnlTPtwkpwkuX1cEmpAPe8o0uBXU+OpVkSz1B+ItSfg6l7FI3Q5v4dyutelJuUoSsZ7QfBhma8X/+fqxvFHutFZCC+0ScAj825097pVXT3Mkbe4Y/Ivo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787359779; c=relaxed/simple; bh=DiZtnae8GaRwNlIJox8oO2achnBh0mLin7iBy86DhtI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=m1lIGMNCWqoLg5+feotJ65J/e44cSId7j7FYRaWBaGUogzb/GoqyTDIOBtAwF4U5z8pp6/0q+98vXUN22OveQ/bhb9p8GCYAwTjIVuQ6dsHtFlwELx1M/hFD+OPVlKDp03GhCA9/YHhXYtonrfqegNAGQn65yg2hQWTM18QZe98= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G5s9gPt3; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G5s9gPt3" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-c20ce3c118aso303385966b.0 for ; Fri, 21 Aug 2026 17:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787359777; x=1787964577; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=FPUnz8OFDYXe3Sf5t4pEZ2F4toWxVvBDHTXITsiNgFk=; b=G5s9gPt38lh93h2DHAwFH8lupM4QLRSn1pgh7/VZYf/ESBLBn5cL+KtUgD6drRaoe8 9swWTaKyukQCmTHY9SQTziR75V1VXKpidgFFwbOt9OTCBVgAT9O66x1wpLM74eVjKdOc xiYBkvhf9yoJSO1DuGTR/gxqM6+wI3azXQJq7QyLTiwp26KBMESFNExEi3F/d05P94WD R0F9m47bPQwZ3h8lLyv72GBHVxf3XzPeZ64aD2r3n5aUrdXEfCkpZxyEVHfUO5JuMvrg ZWwB5CB9Uzn2dXaXOpCfGrhZS8a3n55Y5BLMNxIl/hEafLUCcHoBylHsAxMRPCfh5XK3 94Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787359777; x=1787964577; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FPUnz8OFDYXe3Sf5t4pEZ2F4toWxVvBDHTXITsiNgFk=; b=d72AAaH6cpTpivBwQqksT6TFcqrB7wvQZEQwY6afLKfkMHsEmkIcKecFysQIO+49dU DIaaayS8VOVfhtAKWSH402fVKs3g2DtH2hnSR9Jnm1Qexb3YsDhTuAtfibr30grZDuAo CABAfliZPvRO+WZLTJ9bgtX9CupedqcAwQ8znjMBy/6cDsuKJMc9eikeNj1AYmSgQ0we nbMlLq6XVpNm5FNSn9Aum3Y/ZEx3QuRfZGYigdmqS5fUQmQ6c0eJugYH4+zdVeCtKUSR ih9zQ5HiwkhORHfj7t3cWbLuekP0RhgMnJNBVzMuHm81NSaktOWkXerl6qUlQpbaxyUq uoMQ== X-Forwarded-Encrypted: i=1; AHgh+RqOU23JVoSiU6FbGdoJxjAAslSDpEMXVI026XKKdpnfcSDtHnOFu2NOOw4hq0MxabyUBCi0DyzTFcGbYUs=@vger.kernel.org X-Gm-Message-State: AFuF++nL/y3wE6UDpJOkOOW1ObO2PQaK9Vn8H8BKZAHHFg/RiPS4/LEj vakvZ6uZQqUl/MXmvV3QQsDCKyFf2s4og8xHc5SyhJdjB/qLWAH6ztPS X-Gm-Gg: AR+sD10/6ApgbAcIRLIAIeJVIsEWSOBbMJNFqazDKsg5Jm4ner5H3KFbgJLsbviA1jr ozfl3bQT72gyHfSj0PzdT4XTRqv8pObZx3WDUJftZJ6mNprJONpNGdq84TglC7PQY0C3FY04Bvw +YSjYEzZis08twcpaMkYy1B6jWfyEkrxt/3F2/wTtuOUn77drRkWykv8vmNEVMe2tRjVLG77Ixl q40H0PtC0Nb5PGPeIKoxZTVDSFminLWcXt9sp7P+WogpF5sPkEA78weR+ZUeeySTYBLNK3JH3MS v20e2pB+2CgE2N25DlsExMWZjIEm8BS+rFxz7M0hQCLpoHEh4WNS7O+Rb4RZd+R4C0jwrfoSor+ HoMa+RLVuf/yslUWHuo1zQ0taUfFLMuiCLCIlWcgsHZ2EKzR0t/zPelgzdoWudlfAd28B+x89nZ ScUGlsnNofneGbB66om/PW5jKWn6tQC61X5lvh7XavEBwLULrNQpqaSrnNh/4/8w9bNmG+UIeYO Q== X-Received: by 2002:a17:907:8dc9:b0:c16:6dac:a008 with SMTP id a640c23a62f3a-c246dc97d69mr876404266b.8.1787359776522; Fri, 21 Aug 2026 17:49:36 -0700 (PDT) Received: from localhost.localdomain ([196.235.229.7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c249629929dsm71104966b.23.2026.08.21.17.49.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 17:49:35 -0700 (PDT) From: Salah Triki To: Puranjay Mohan , Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Salah Triki Subject: [PATCH] iio: temperature: tmp117: fix calibbias cache update on I2C write failure Date: Sat, 22 Aug 2026 01:49:28 +0100 Message-ID: <20260822004929.13643-1-salah.triki@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Fixes: df041e737a38 ("iio: temperature: add driver support for ti tmp117") Signed-off-by: Salah Triki --- drivers/iio/temperature/tmp117.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iio/temperature/tmp117.c b/drivers/iio/temperature/tmp117.c index 6bc18616ad15..7d74f401bb80 100644 --- a/drivers/iio/temperature/tmp117.c +++ b/drivers/iio/temperature/tmp117.c @@ -95,15 +95,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; -- 2.43.0