From: Martin Aberer <martin.aberer@bachmann.info>
To: <peter@korsgaard.com>, <andrew@lunn.ch>
Cc: <andi.shyti@kernel.org>, <linux-i2c@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Martin Aberer <martin.aberer@bachmann.info>
Subject: [PATCH] i2c: ocores: re-check status after poll timeout to avoid false errors
Date: Mon, 23 Mar 2026 14:52:49 +0100 [thread overview]
Message-ID: <20260323135249.550925-1-martin.aberer@bachmann.info> (raw)
The polling task can be preempted at any point inside ocores_wait(),
including just before the time_after() check. If the scheduler does
not resume the task until after the 1ms deadline, ocores_wait()
returns -ETIMEDOUT even though the hardware already cleared the
status bit.
Re-read the status register after a timeout before declaring failure.
This avoids spurious timeout warnings under high CPU load.
Signed-off-by: Martin Aberer <martin.aberer@bachmann.info>
---
drivers/i2c/busses/i2c-ocores.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 0f67e57cdeff..6f5aece94d57 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -313,12 +313,24 @@ static int ocores_poll_wait(struct ocores_i2c *i2c)
/*
* once we are here we expect to get the expected result immediately
* so if after 1ms we timeout then something is broken.
+ *
+ * The polling task can be preempted at any point inside ocores_wait(),
+ * including just before the time_after() check. If the scheduler does
+ * not resume the task until after the 1ms deadline, ocores_wait()
+ * returns -ETIMEDOUT even though the hardware already cleared the
+ * status bit.
+
+ * Re-read the status register after a timeout before declaring failure.
+ * This avoids spurious timeout warnings under high CPU load.
*/
err = ocores_wait(i2c, OCI2C_STATUS, mask, 0, msecs_to_jiffies(1));
- if (err)
+ if (err) {
+ if ((oc_getreg(i2c, OCI2C_STATUS) & mask) == 0)
+ return 0;
dev_warn(i2c->adap.dev.parent,
"%s: STATUS timeout, bit 0x%x did not clear in 1ms\n",
__func__, mask);
+ }
return err;
}
--
2.43.0
next reply other threads:[~2026-03-23 13:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 13:52 Martin Aberer [this message]
2026-03-23 14:34 ` [PATCH] i2c: ocores: re-check status after poll timeout to avoid false errors Christian Gmeiner
2026-03-23 15:12 ` Andrew Lunn
2026-03-24 14:05 ` [PATCH] i2c: ocores: Use read_poll_timeout_atomic to avoid false poll timeouts Martin Aberer
2026-03-26 22:34 ` Andi Shyti
2026-03-27 0:27 ` Andrew Lunn
2026-03-27 14:03 ` Andi Shyti
2026-03-27 14:05 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323135249.550925-1-martin.aberer@bachmann.info \
--to=martin.aberer@bachmann.info \
--cc=andi.shyti@kernel.org \
--cc=andrew@lunn.ch \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peter@korsgaard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox