]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: light: si1133: reset counter to prevent race condition
authorJoshua Crofts <joshua.crofts1@gmail.com>
Tue, 5 May 2026 07:31:26 +0000 (09:31 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sun, 31 May 2026 09:59:34 +0000 (10:59 +0100)
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>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/light/si1133.c

index 44fa152dbd24c26c97cc778cbe641d92ecd56afa..c88c79202be2e21abb72067426e31b6bf97c61cf 100644 (file)
@@ -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;
                }
        }