Skip to contentSkip to conversation

spi hisi-kunpeng cleanup and fix

PATCH In review Pei Xiao 2 participants 5 messages Mar 19 – Mar 24

Subsystems (2)
lore
Share & tools
lore

Pei Xiao

author
#0 lore raw

cover 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

 drivers/spi/spi-hisi-kunpeng.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/2 spi: hisi-kunpeng: prevent infinite while() loop in hisi_spi_flush_fifo

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")
---
 drivers/spi/spi-hisi-kunpeng.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/spi/spi-hisi-kunpeng.c +11 -1
index 216a0a91fc47..c42d2a2cdf1e 100644
@@ -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--);
 }
 
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 2/2 spi: hisi-kunpeng: Add timeout warning in FIFO flush function

In reply to 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.

---
 drivers/spi/spi-hisi-kunpeng.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/spi/spi-hisi-kunpeng.c +4 -1
index c42d2a2cdf1e..046bd894040b 100644
@@ -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 */
Signature · 1 line
2.25.1
author
#3 lore raw
In reply to Pei Xiao
Quoted 4 lines · Pei Xiao

Hi Maintainer,
I might have wasted your valuable time again. Please help check the two
modifications. Thank you!

Quoted 8 lines

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.

maintainer
#4 lore raw
In reply to Pei Xiao
Quoted 6 lines · Pei Xiao

spi hisi-kunpeng cleanup and fix

Hi Maintainer,
I might have wasted your valuable time again. Please help check the two
modifications. Thank you!

Quoted 6 lines

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