From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A2D463DBD7E; Tue, 5 May 2026 07:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777966308; cv=none; b=LDmfBUbMov9h1f/gT82hFfi+W3brp0KmPsKfbXe6RKQWMknJALVgvgxDJ111ddk7WDd8PpeiX6FFnAwZn3jD8anUrEGeK8juV2h9w/4RcZopqHeSGyGIKRAni2QUvc4Xt2hvliGBqNO6uBg/CmGnBaTpyEPPYzupZjtFs443H6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777966308; c=relaxed/simple; bh=wqz0bKGlNUuLDdzAuyBaUgHWch1GriKqzUUO2K+OxAk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sFt7A6yBFaVsLaYOziaDMvrY1FhiTZl0PFXxTF5Us4nprNZXL04BClEqPhcsjT+mF3GljyWWqFH/gCrEdtO1yyEjcq7MB9SqOf1H2xTkcQm8tRvA8H6PkBqFWd/HEEYut3UqSnMOYFEmnS70LKNGN4dCvvrifAdhnHFmmnBs05w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q41P0PKZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q41P0PKZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6D533C2BCF4; Tue, 5 May 2026 07:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777966308; bh=wqz0bKGlNUuLDdzAuyBaUgHWch1GriKqzUUO2K+OxAk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=q41P0PKZe541hRyG1Uy5hUVArCjrITCsXSqOMLclIV/ms0FkoO+TO7K+Q2RfjNpeb kLgkoUi56h8CHvFk6lAi2pvHUqeqTPD3D24knQ2ZxKZjC2dLHhUscJ0OGqWMayw9Ne BBObiuX5XVDWXlIE+NwbDmvPljhz4ZQdITkaOaNOPTnfLWWJOU31GcuYmrYMMb+bkZ V487j6pHzxZThurZM3rmdZwOo/41q0789CF/xGcQ9EZdRSW6oY121F0XOHstOtpVvR MAB/kkbmVWsHzA321Xapwwxdt7cdRvGRcKSgklFqf1IUONtp5RmhnsPY0Hxa4AlfaE v0mA807RibiyA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60B2CFF885A; Tue, 5 May 2026 07:31:48 +0000 (UTC) From: Joshua Crofts via B4 Relay Date: Tue, 05 May 2026 09:31:27 +0200 Subject: [PATCH v5 2/8] iio: light: si1133: prevent race condition on timeout Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260505-si1133-checkup-v5-2-5df86a9024ed@gmail.com> References: <20260505-si1133-checkup-v5-0-5df86a9024ed@gmail.com> In-Reply-To: <20260505-si1133-checkup-v5-0-5df86a9024ed@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Jean-Francois Dagenais , =?utf-8?q?Maxime_Roussin-B=C3=A9langer?= Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Joshua Crofts , Jonathan Cameron , sashiko-bot X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777966306; l=2070; i=joshua.crofts1@gmail.com; s=20260422; h=from:subject:message-id; bh=oL3iK2flDthV/Ohs5rDoVs2xKZo+kx/muq+vmqyUtqM=; b=yHWDw1Q0Rl0UeV0q07guyZThgbvIeEqn7zPX2iJNzNUoXq2304o7wqde7xNZP9wyI5ZlOa4TQ 81EgZephMKUDOXoS8RgDWcs0LiXmn8qht7451R3pk7eSONNNFDiGF0C X-Developer-Key: i=joshua.crofts1@gmail.com; a=ed25519; pk=Xd+UVoRPiiI0K3LHQ2XIcXmO0jvVuFTv9eTx3lgBphI= X-Endpoint-Received: by B4 Relay for joshua.crofts1@gmail.com/20260422 with auth_id=746 X-Original-From: Joshua Crofts Reply-To: joshua.crofts1@gmail.com From: Joshua Crofts 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 --- 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 c88c79202be2e21abb72067426e31b6bf97c61cf..bf7bf0f1631d49a1d04b89f172646e4afaf46438 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.47.3