mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Mark Brown <broonie@kernel.org>, Heiko Stuebner <heiko@sntech.de>,
	 Mark Hasemeyer <markhas@chromium.org>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org,  kernel@collabora.com,
	Alexander Shiyan <eagle.alexander923@gmail.com>,
	 stable@vger.kernel.org,
	Sebastian Reichel <sebastian.reichel@collabora.com>
Subject: [PATCH] spi: Fix runtime PM imbalance on pump transfer message error
Date: Tue, 10 Nov 2026 01:41:58 +0100	[thread overview]
Message-ID: <20261110-spi-runtime-pm-fix-v1-1-8601ebb2f6a8@collabora.com> (raw)

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>


                 reply	other threads:[~2026-11-10  0:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261110-spi-runtime-pm-fix-v1-1-8601ebb2f6a8@collabora.com \
    --to=sebastian.reichel@collabora.com \
    --cc=broonie@kernel.org \
    --cc=eagle.alexander923@gmail.com \
    --cc=heiko@sntech.de \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=markhas@chromium.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®