[PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop

From: Lee Jones

Date: Wed Dec 02 2026 - 04:38:49 EST


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@xxxxxxxxxx>
---
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