* [PATCH 0/2] spi hisi-kunpeng cleanup and fix
@ 2026-03-19 3:06 Pei Xiao
2026-03-19 3:06 ` [PATCH 1/2] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo Pei Xiao
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Pei Xiao @ 2026-03-19 3:06 UTC (permalink / raw)
To: shenyang39, broonie, f.fangjian, linux-spi, linux-kernel; +Cc: Pei Xiao
Hi Maintainer,
I might have wasted your valuable time again. Please help check the two
modifications. Thank you!
Pei Xiao (2):
spi: hisi-kunpeng: prevent infinite while() loop in
hisi_spi_flush_fifo
spi: hisi-kunpeng: Add timeout warning in FIFO flush function
drivers/spi/spi-hisi-kunpeng.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo
2026-03-19 3:06 [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
@ 2026-03-19 3:06 ` Pei Xiao
2026-03-19 3:06 ` [PATCH 2/2] spi: hisi-kunpeng: Add timeout warning in FIFO flush function Pei Xiao
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Pei Xiao @ 2026-03-19 3:06 UTC (permalink / raw)
To: shenyang39, broonie, f.fangjian, linux-spi, linux-kernel; +Cc: Pei Xiao
The hisi_spi_flush_fifo()'s inner while loop that lacks any timeout
mechanism. Maybe the hardware never becomes empty, the loop will spin
forever, causing the CPU to hang.
Fix this by adding a inner_limit based on loops_per_jiffy. The inner loop
now exits after approximately one jiffy if the FIFO remains non-empty, logs
a ratelimited warning, and breaks out of the outer loop. Additionally, add
a cpu_relax() inside the busy loop to improve power efficiency.
Fixes: c770d8631e18 ("spi: Add HiSilicon SPI Controller Driver for Kunpeng SoCs")
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/spi/spi-hisi-kunpeng.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c
index 216a0a91fc47..c42d2a2cdf1e 100644
--- a/drivers/spi/spi-hisi-kunpeng.c
+++ b/drivers/spi/spi-hisi-kunpeng.c
@@ -196,8 +196,18 @@ static void hisi_spi_flush_fifo(struct hisi_spi *hs)
unsigned long limit = loops_per_jiffy << 1;
do {
- while (hisi_spi_rx_not_empty(hs))
+ unsigned long inner_limit = loops_per_jiffy;
+
+ while (hisi_spi_rx_not_empty(hs) && --inner_limit) {
readl(hs->regs + HISI_SPI_DOUT);
+ cpu_relax();
+ }
+
+ if (!inner_limit) {
+ dev_warn_ratelimited(hs->dev, "RX FIFO flush timeout\n");
+ break;
+ }
+
} while (hisi_spi_busy(hs) && limit--);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] spi: hisi-kunpeng: Add timeout warning in FIFO flush function
2026-03-19 3:06 [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
2026-03-19 3:06 ` [PATCH 1/2] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo Pei Xiao
@ 2026-03-19 3:06 ` Pei Xiao
2026-03-19 3:08 ` [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
2026-03-23 22:03 ` Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Pei Xiao @ 2026-03-19 3:06 UTC (permalink / raw)
To: shenyang39, broonie, f.fangjian, linux-spi, linux-kernel; +Cc: Pei Xiao
When flushing the FIFO, the driver waits for the busy flag to clear
with a timeout. Change the loop condition to use pre-decrement (--limit)
instead of post-decrement (limit--) so that warning message can show. Add a
ratelimited warning message to log SPI busy timeout events, aiding in
debugging.
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
drivers/spi/spi-hisi-kunpeng.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-hisi-kunpeng.c b/drivers/spi/spi-hisi-kunpeng.c
index c42d2a2cdf1e..046bd894040b 100644
--- a/drivers/spi/spi-hisi-kunpeng.c
+++ b/drivers/spi/spi-hisi-kunpeng.c
@@ -208,7 +208,10 @@ static void hisi_spi_flush_fifo(struct hisi_spi *hs)
break;
}
- } while (hisi_spi_busy(hs) && limit--);
+ } while (hisi_spi_busy(hs) && --limit);
+
+ if (!limit)
+ dev_warn_ratelimited(hs->dev, "SPI busy timeout\n");
}
/* Disable the controller and all interrupts */
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] spi hisi-kunpeng cleanup and fix
2026-03-19 3:06 [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
2026-03-19 3:06 ` [PATCH 1/2] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo Pei Xiao
2026-03-19 3:06 ` [PATCH 2/2] spi: hisi-kunpeng: Add timeout warning in FIFO flush function Pei Xiao
@ 2026-03-19 3:08 ` Pei Xiao
2026-03-23 22:03 ` Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Pei Xiao @ 2026-03-19 3:08 UTC (permalink / raw)
To: shenyang39, broonie, f.fangjian, linux-spi, linux-kernel
在 2026/3/19 11:06, Pei Xiao 写道:
> Hi Maintainer,
> I might have wasted your valuable time again. Please help check the two
> modifications. Thank you!
>
> Pei Xiao (2):
> spi: hisi-kunpeng: prevent infinite while() loop in
> hisi_spi_flush_fifo
> spi: hisi-kunpeng: Add timeout warning in FIFO flush function
>
> drivers/spi/spi-hisi-kunpeng.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
sorry for I didn't modify the verision number.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] spi hisi-kunpeng cleanup and fix
2026-03-19 3:06 [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
` (2 preceding siblings ...)
2026-03-19 3:08 ` [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
@ 2026-03-23 22:03 ` Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2026-03-23 22:03 UTC (permalink / raw)
To: shenyang39, f.fangjian, linux-spi, linux-kernel, Pei Xiao
On Thu, 19 Mar 2026 11:06:40 +0800, Pei Xiao wrote:
> spi hisi-kunpeng cleanup and fix
>
> Hi Maintainer,
> I might have wasted your valuable time again. Please help check the two
> modifications. Thank you!
>
> Pei Xiao (2):
> spi: hisi-kunpeng: prevent infinite while() loop in
> hisi_spi_flush_fifo
> spi: hisi-kunpeng: Add timeout warning in FIFO flush function
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.1
Thanks!
[1/2] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo
https://git.kernel.org/broonie/spi/c/9f61daf2c2de
[2/2] spi: hisi-kunpeng: Add timeout warning in FIFO flush function
https://git.kernel.org/broonie/spi/c/579a49aaab08
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-24 0:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19 3:06 [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
2026-03-19 3:06 ` [PATCH 1/2] spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo Pei Xiao
2026-03-19 3:06 ` [PATCH 2/2] spi: hisi-kunpeng: Add timeout warning in FIFO flush function Pei Xiao
2026-03-19 3:08 ` [PATCH 0/2] spi hisi-kunpeng cleanup and fix Pei Xiao
2026-03-23 22:03 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox