[PATCH] spi: rockchip: Fix runtime PM underflow on CS error paths
Sebastian Reichel
sebastian.reichel at collabora.com
Fri Nov 6 18:35:51 PST 2026
Hi,
On Fri, Nov 06, 2026 at 02:58:38PM +0000, Mark Brown wrote:
> > The Rockchip SPI driver manages runtime PM reference counting around
> > chip select (CS) assertion: pm_runtime_get_sync() is called when CS is
> > asserted, and pm_runtime_put() when deasserted. This balanced pair is
> > expected.
>
> > @@ -256,6 +257,7 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable)
> > if (cs_asserted) {
> > /* Keep things powered as long as CS is asserted */
> > pm_runtime_get_sync(rs->dev);
> > + rs->cs_claimed = true;
>
> This sort of boolean tracking of reference counts is extremely error
> prone, and note that there are two chip selects on the device. This
> should probably at least be per chip select.
I ran into the same symptom while working on RK3588 system suspend
and came up with a way different root cause.
I haven't found the time to investigate more closely, check for a
proper Fixes references e.t.c., hence it has not yet been send. So
take this with a grain of salt, but it seems to be not Rockchip
specific:
-----
From: Sebastian Reichel <sebastian.reichel at collabora.com>
Date: Sat, 5 Sep 2026 00:26:40 +0200
Subject: [PATCH] spi: Fix runtime PM imbalance on pump transfer message error
Cc: kernel at collabora.com
The current SPI message pumping code may drop the runtime PM twice when
an SPI message cannot be send:
spi_master spi2: noqueue transfer failed
rockchip-spi feb20000.spi: Runtime PM usage count underflow!
Fix the problem by always keeping the runtime PM count increased when
exiting __spi_pump_transfer_message(), as the caller handles decreasing
it.
Note, that the function already keeps the RPM usage counter increased
for the error paths following after the prepare_transfer_hardware step.
Signed-off-by: Sebastian Reichel <sebastian.reichel at collabora.com>
---
drivers/spi/spi.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 40cda0037ea5..9cd1cabfa0b3 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1951,7 +1951,6 @@ static int __spi_pump_transfer_message(struct spi_controller *ctlr,
if (!was_busy && ctlr->auto_runtime_pm) {
ret = pm_runtime_get_sync(ctlr->dev.parent);
if (ret < 0) {
- pm_runtime_put_noidle(ctlr->dev.parent);
dev_err(&ctlr->dev, "Failed to power device: %d\n",
ret);
@@ -1972,9 +1971,6 @@ static int __spi_pump_transfer_message(struct spi_controller *ctlr,
"failed to prepare transfer hardware: %d\n",
ret);
- if (ctlr->auto_runtime_pm)
- pm_runtime_put(ctlr->dev.parent);
-
msg->status = ret;
spi_finalize_current_message(ctlr);
--
2.53.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-rockchip/attachments/20261107/4d7e6ffc/attachment.sig>
More information about the Linux-rockchip
mailing list