Skip to content

Commit 922e9be

Browse files
cjd8gregkh
authored andcommitted
iio: light: si1133: prevent race condition on timeout
[ Upstream commit 8c50a95 ] Sashiko reported a bug where the si1133_command exits on timeout without halting the sensor or masking the interrupt. If the sensor completes the command later, any subsequent command to the sensor will cause the IRQ handler to complete immediately, returning stale data to the driver all while the command hasn't finished yet, shifting all potential reads in the future. Fix this by masking the IRQ if wait_for_completion_timeout() fails. When initiating a new command, do a dummy read of the IRQ_STATUS register and turn the IRQ back on. Fixes: e01e7ea ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4799162 commit 922e9be

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

drivers/iio/light/si1133.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,14 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
395395

396396
expected_seq = (data->rsp_seq + 1) & SI1133_MAX_CMD_CTR;
397397

398-
if (cmd == SI1133_CMD_FORCE)
398+
if (cmd == SI1133_CMD_FORCE) {
399+
/* Flush pending IRQs from a previous timeout. */
400+
regmap_read(data->regmap, SI1133_REG_IRQ_STATUS, &resp);
401+
regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE,
402+
SI1133_IRQ_CHANNEL_ENABLE);
403+
399404
reinit_completion(&data->completion);
405+
}
400406

401407
err = regmap_write(data->regmap, SI1133_REG_COMMAND, cmd);
402408
if (err) {
@@ -409,6 +415,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd)
409415
/* wait for irq */
410416
if (!wait_for_completion_timeout(&data->completion,
411417
msecs_to_jiffies(SI1133_COMPLETION_TIMEOUT_MS))) {
418+
regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, 0);
412419
err = -ETIMEDOUT;
413420
goto out;
414421
}

0 commit comments

Comments
 (0)