Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CC5939733E; Tue, 21 Jul 2026 21:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669278; cv=none; b=BJvGRA3EmUjlJ7WaY4QqYUxv3S6Gwec5xcnBn7Tve1CAghlI5Ks3YoEbtWmWSKz1+++9p30Po2c0/bgB5LEBGb13RAlAI7TVBJmTPQZcEcwlaPicdJFo0Vk0p3fqVRISCbiPZZvvRbYNDn8eQwcHeV79RqWQucbIn5BO9GNj3Vg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669278; c=relaxed/simple; bh=l1CfAmkRGh4znWPasXmb3xpV/azYvqvWU+k8pvvmf+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AIK0XLrG77poZNUgZ9Vn7NDUIIz54nV81XIW0Ag07f5pSzBVoPQRme4L6IE9rfYWD/13qgalw3IrQITWzLPkq9MRikEsH08J+5bfEEBl/0ADLAIrUUCKiiUf3kwQZhtw37jctu/430ufnAaFZ0ExmAq4bm5rMS3OHawtwUk6VAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vi0hVP/4; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vi0hVP/4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 900C91F00A3A; Tue, 21 Jul 2026 21:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784669269; bh=u/c/IkzvGF8+5M2q/Pya2XhrW9OBvXPC4QLItcjlcK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vi0hVP/4ltHe+cabCBALZOS4zx6XGeUQLRBAT+aHVifBsaPoYXWZRCKFUhAer+DQ7 2KaFcOCuQQ5/JRO6xrCwdguk/OnNr50yoZi1iZRQRQytQVJPjyVA2LG9J9wxDrGl/L QJvRfcXWEsXaiZCY0tz5FDM/0XFpui4iNB+ivQGg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot , Joshua Crofts , Jonathan Cameron , Sasha Levin Subject: [PATCH 6.1 0491/1067] iio: light: si1133: prevent race condition on timeout Date: Tue, 21 Jul 2026 17:18:12 +0200 Message-ID: <20260721152435.598490258@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joshua Crofts [ Upstream commit 8c50a95ceb230d17801758a9e41ffbbbe46f8b4d ] 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: e01e7eaf37d8 ("iio: light: introduce si1133") Reported-by: sashiko-bot 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 Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/light/si1133.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iio/light/si1133.c b/drivers/iio/light/si1133.c index 17ee203d16a274..d207a928b1f823 100644 --- a/drivers/iio/light/si1133.c +++ b/drivers/iio/light/si1133.c @@ -395,8 +395,14 @@ static int si1133_command(struct si1133_data *data, u8 cmd) expected_seq = (data->rsp_seq + 1) & SI1133_MAX_CMD_CTR; - if (cmd == SI1133_CMD_FORCE) + if (cmd == SI1133_CMD_FORCE) { + /* Flush pending IRQs from a previous timeout. */ + regmap_read(data->regmap, SI1133_REG_IRQ_STATUS, &resp); + regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, + SI1133_IRQ_CHANNEL_ENABLE); + reinit_completion(&data->completion); + } err = regmap_write(data->regmap, SI1133_REG_COMMAND, cmd); if (err) { @@ -409,6 +415,7 @@ static int si1133_command(struct si1133_data *data, u8 cmd) /* wait for irq */ if (!wait_for_completion_timeout(&data->completion, msecs_to_jiffies(SI1133_COMPLETION_TIMEOUT_MS))) { + regmap_write(data->regmap, SI1133_REG_IRQ_ENABLE, 0); err = -ETIMEDOUT; goto out; } -- 2.53.0