mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] spi: Fix runtime PM imbalance on pump transfer message error
@ 2026-11-10  0:41 Sebastian Reichel
  0 siblings, 0 replies; only message in thread
From: Sebastian Reichel @ 2026-11-10  0:41 UTC (permalink / raw)
  To: Mark Brown, Heiko Stuebner, Mark Hasemeyer
  Cc: linux-spi, linux-kernel, linux-arm-kernel, linux-rockchip,
	kernel, Alexander Shiyan, stable, Sebastian Reichel

The current SPI message pumping code may drop the runtime PM twice when
an SPI message cannot be sent:

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.

Cc: stable@vger.kernel.org
Fixes: bef4a48f4ef7 ("spi: Fix null dereference on suspend")
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
I noticed this with RK3588 system suspend/resume, which uses SPI based
PMIC and runs into SPI transmission problems when the PM domain driver
tries to disable regulators required by e.g. NPU or GPU domain. I've not
yet checked too closely, but suspect Heiko's atomic SPI transmission
support series might also help with fixing the actual failure.

My patch is not really a v2, but Alexander Shiyan probably ran into the
same issue before and came up with a way different patch and rationale:

https://lore.kernel.org/linux-rockchip/20260806191854.922530-1-eagle.alexander923@gmail.com/
---
 drivers/spi/spi.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ce257b3ec530..4d9c5d026ff6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1967,7 +1967,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);
 
@@ -1988,9 +1987,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);
 

---
base-commit: 059518f775baecc9803fc97787bd0b17558f8047
change-id: 20261110-spi-runtime-pm-fix-529325c25582

Best regards,
--  
Sebastian Reichel <sebastian.reichel@collabora.com>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-10  0:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10  0:41 [PATCH] spi: Fix runtime PM imbalance on pump transfer message error Sebastian Reichel

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®