[PATCH v3 7/8] iio: light: si1133: reset counter to prevent race condition

From: Joshua Crofts via B4 Relay

Date: Wed Apr 29 2026 - 11:11:51 EST


From: Joshua Crofts <joshua.crofts1@xxxxxxxxx>

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 returing
from timeout.

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@xxxxxxxxx>
---
drivers/iio/light/si1133.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c
index 471692057b0f16c82946507bf7d23a0004f80bf0..842a59bc68c20b3206e0c826f86c913f6c66bd7c 100644
--- a/drivers/iio/light/si1133.c
+++ b/drivers/iio/light/si1133.c
@@ -430,6 +430,12 @@ 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 sofware and hardware
+ * counters being out of sync
+ */
+ si1133_cmd_reset_counter(data);
+
return err;
}
}

--
2.47.3