Linux IIO development
 help / color / mirror / Atom feed
From: Joshua Crofts via B4 Relay <devnull+joshua.crofts1.gmail.com@kernel.org>
To: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Joshua Crofts <joshua.crofts1@gmail.com>,
	 sashiko-bot <sashiko-bot@kernel.org>
Subject: [PATCH v4 1/8] iio: light: si1133: reset counter to prevent race condition
Date: Thu, 30 Apr 2026 17:04:21 +0200	[thread overview]
Message-ID: <20260430-si1133-checkup-v4-1-fb3e9dce41bf@gmail.com> (raw)
In-Reply-To: <20260430-si1133-checkup-v4-0-fb3e9dce41bf@gmail.com>

From: Joshua Crofts <joshua.crofts1@gmail.com>

Sashiko reported a potential race condition happening when the driver
returns an errno after a timeout in the si1133_command() function. The
premature exit causes the hardware and software counters to become out
of sync by not updating data->rsp_seq, therefore the internal hardware
counter keeps incrementing.

Fix this by adding a call to si1133_cmd_reset_counter() before returning
from timeout.

Fixes: e01e7eaf37d8 ("iio: light: introduce si1133")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/message/20260428-si1133-checkup-v2-5-70ad14bfefe2%40gmail.com
Assisted-by: gemini:gemini-3.1-pro-preview
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
---
 drivers/iio/light/si1133.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index 44fa152dbd24c26c97cc778cbe641d92ecd56afa..c88c79202be2e21abb72067426e31b6bf97c61cf 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -427,6 +427,11 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
 			dev_warn(dev,
 				 "Failed to read command 0x%02x, ret=%d\n",
 				 cmd, err);
+			/*
+			 * Reset counter on err to prevent software and hardware
+			 * counters being out of sync.
+			 */
+			si1133_cmd_reset_counter(data);
 			goto out;
 		}
 	}

-- 
2.47.3



  reply	other threads:[~2026-04-30 15:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 15:04 [PATCH v4 0/8] iio: light: si1133: driver cleanup Joshua Crofts via B4 Relay
2026-04-30 15:04 ` Joshua Crofts via B4 Relay [this message]
2026-04-30 15:04 ` [PATCH v4 2/8] iio: light: si1133: prevent race condition on timeout Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 3/8] iio: light: si1133: remove unused macros Joshua Crofts via B4 Relay
2026-05-04  8:49   ` Andy Shevchenko
2026-04-30 15:04 ` [PATCH v4 4/8] iio: light: si1133: prefer complex macros enclosed in parenthesis Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 5/8] iio: light: si1133: add missing include headers Joshua Crofts via B4 Relay
2026-04-30 19:42   ` Joshua Crofts
2026-04-30 15:04 ` [PATCH v4 6/8] iio: light: si1133: group generic <linux/*> headers Joshua Crofts via B4 Relay
2026-04-30 15:04 ` [PATCH v4 7/8] iio: light: si1133: add local variable for timeout Joshua Crofts via B4 Relay
2026-05-04  8:53   ` Andy Shevchenko
2026-05-04  8:59     ` Joshua Crofts
2026-05-04  9:03       ` Andy Shevchenko
2026-05-05 12:25         ` Jonathan Cameron
2026-04-30 15:04 ` [PATCH v4 8/8] iio: light: si1133: use guard(mutex)() macro Joshua Crofts via B4 Relay
2026-05-04  8:55 ` [PATCH v4 0/8] iio: light: si1133: driver cleanup Andy Shevchenko
2026-05-04  9:09   ` Joshua Crofts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260430-si1133-checkup-v4-1-fb3e9dce41bf@gmail.com \
    --to=devnull+joshua.crofts1.gmail.com@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=joshua.crofts1@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sashiko-bot@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox