mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, "Krzysztof Kozlowski" <krzk@kernel.org>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Uwe Kleine-König (The Capable Hub)"
	<u.kleine-koenig@baylibre.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Takashi Sakamoto" <o-takashi@sakamocchi.jp>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Thomas Bogendoerfer" <tbogendoerfer@suse.de>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop
Date: Wed,  2 Dec 2026 09:36:48 +0000	[thread overview]
Message-ID: <73bf707a95347961ea15d0cee241188f8c2b848d.1796204137.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796204137.git.lee@kernel.org>

sgi_w1_wait() busy-waits in an unbounded loop until MCR_DONE is set.
If the hardware fails to assert MCR_DONE due to a fault or missing
clock, the CPU hangs indefinitely.

Replace the open-coded loop with readl_poll_timeout_atomic() using a
10 ms timeout, and return 1 (no device present / bus idle) on timeout.

Fixes: 74ded38a8e18 ("w1: add 1-wire master driver for IP block found in SGI ASICs")
Closes: https://sashiko.dev/#/bug/linux-e5c06baa-f504-46e1-80df-e43a94a75fa1
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/w1/masters/sgi_w1.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/w1/masters/sgi_w1.c b/drivers/w1/masters/sgi_w1.c
index 2bc2459b3605..744a06741a7e 100644
--- a/drivers/w1/masters/sgi_w1.c
+++ b/drivers/w1/masters/sgi_w1.c
@@ -6,6 +6,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/jiffies.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -27,10 +28,12 @@ struct sgi_w1_device {
 static u8 sgi_w1_wait(u32 __iomem *mcr)
 {
 	u32 mcr_val;
+	int ret;
 
-	do {
-		mcr_val = readl(mcr);
-	} while (!(mcr_val & MCR_DONE));
+	ret = readl_poll_timeout_atomic(mcr, mcr_val, mcr_val & MCR_DONE,
+					0, 10 * USEC_PER_MSEC);
+	if (ret)
+		return 1;
 
 	return (mcr_val & MCR_RD_DATA) ? 1 : 0;
 }
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-02  9:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:36 [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-02  9:36 ` [PATCH 1/6] w1: Free slave structure in w1_slave_release() Lee Jones
2026-12-02 10:38   ` Krzysztof Kozlowski
2026-12-02 10:43     ` Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks Lee Jones
2026-12-02 10:38   ` Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 3/6] w1: Return actual bytes read from w1_read_block() and rw_read() Lee Jones
2026-12-02 10:54   ` Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal Lee Jones
2026-12-02 10:44   ` Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Lee Jones
2026-12-02 10:45   ` Krzysztof Kozlowski
2026-12-02  9:36 ` Lee Jones [this message]
2026-12-02 10:46   ` [PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop Krzysztof Kozlowski
2026-12-02  9:45 ` [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Greg Kroah-Hartman
2026-12-02 10:23   ` Lee Jones
2026-12-02 10:30     ` Greg Kroah-Hartman

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=73bf707a95347961ea15d0cee241188f8c2b848d.1796204137.git.lee@kernel.org \
    --to=lee@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=dakr@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=tbogendoerfer@suse.de \
    --cc=u.kleine-koenig@baylibre.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

all inboxes | Powered by JetHome®