Re: [PATCH] spi: Fix runtime PM imbalance on pump transfer message error
From: Alexander Shiyan
Date: Thu Nov 12 2026 - 08:24:29 EST
[root@diasom-evb ~]# rtcwake -s 15 -v -m freeze
rtcwake: assuming RTC uses UTC ...
Using UTC time.
delta = 39
tzone = 0
tzname = UTC
systime = 1773421897, (UTC) Fri Mar 13 17:11:37 2026
rtctime = 1773421858, (UTC) Fri Mar 13 17:10:58 2026
alarm 0, sys_time 1773421897, rtc_time 1773421858, seconds 15
rtcwake: wakeup from "freeze" using /dev/rtc0 at Fri Mar 13 17:11:14 2026
suspend mode: freeze; suspending system
[ 195.026100] PM: suspend entry (s2idle)
[ 195.026582] Filesystems sync: 0.000 seconds
[ 195.031059] Freezing user space processes
[ 195.032653] Freezing user space processes completed (elapsed 0.001 seconds)
[ 195.033266] OOM killer disabled.
[ 195.033547] Freezing remaining freezable tasks
[ 195.049016] Freezing remaining freezable tasks completed (elapsed
0.015 seconds)
[ 195.318497] xhci-hcd xhci-hcd.3.auto: xHC error in resume, USBSTS
0x401, Reinit
[ 195.319141] usb usb3: root hub lost power or was reset
[ 195.319588] usb usb4: root hub lost power or was reset
[ 195.321839] usb usb8: root hub lost power or was reset
[ 195.324626] usb usb7: root hub lost power or was reset
[ 195.338354] xhci-hcd xhci-hcd.0.auto: xHC error in resume, USBSTS
0x401, Reinit
[ 195.338996] usb usb1: root hub lost power or was reset
[ 195.339443] usb usb2: root hub lost power or was reset
[ 195.354495] xhci-hcd xhci-hcd.4.auto: xHC error in resume, USBSTS
0x401, Reinit
[ 195.355136] usb usb5: root hub lost power or was reset
[ 195.355584] usb usb6: root hub lost power or was reset
[ 195.359476] rk_gmac-dwmac fe1c0000.ethernet: init for RGMII_RXID
[ 195.384855] dwmac4: Master AXI performs any burst length
[ 195.387322] rk_gmac-dwmac fe1c0000.ethernet end3: No Safety
Features support found
[ 195.389691] rk_gmac-dwmac fe1c0000.ethernet end3: IEEE 1588-2008
Advanced Timestamp supported
[ 195.392178] rk_gmac-dwmac fe1c0000.ethernet end3: configuring for
phy/rgmii-rxid link mode
[ 195.442885] r8169 0004:41:00.0 end1: Link is Down
[ 195.484890] r8169 0002:21:00.0 end0: Link is Down
[ 195.490337] rk_gmac-dwmac fe1b0000.ethernet: init for RGMII_RXID
[ 195.522987] dwmac4: Master AXI performs any burst length
[ 195.524320] rk_gmac-dwmac fe1b0000.ethernet end2: No Safety
Features support found
[ 195.526697] rk_gmac-dwmac fe1b0000.ethernet end2: IEEE 1588-2008
Advanced Timestamp supported
[ 195.529185] rk_gmac-dwmac fe1b0000.ethernet end2: configuring for
phy/rgmii-rxid link mode
[ 195.656869] dwhdmiqp-rockchip fdea0000.hdmi: i2c read timed out
[ 195.760866] dwhdmiqp-rockchip fdea0000.hdmi: i2c read timed out
[ 195.864875] dwhdmiqp-rockchip fdea0000.hdmi: i2c read timed out
[ 195.968867] dwhdmiqp-rockchip fdea0000.hdmi: i2c read timed out
[ 196.072873] dwhdmiqp-rockchip fdea0000.hdmi: i2c read timed out
[ 196.073408] hdmi-audio-codec hdmi-audio-codec.9.auto: HDMI: Unknown
ELD version 0
[ 196.176872] dwhdmiqp-rockchip fdea0000.hdmi: i2c read timed out
[ 196.518457] OOM killer enabled.
[ 196.518736] Restarting tasks: Starting
[ 196.519279] pcieport 0000:00:00.0: no suspend buffer for LTR; ASPM
issues possible after resume
[ 196.522351] Restarting tasks: Done
[ 196.522832] random: crng reseeded on system resumption
[ 196.523321] PM: suspend exit
[root@diasom-evb ~]# [ 196.534793] mmc_host mmc1: Bus speed =
400000Hz (req 400000Hz, actual 400000HZ div = 0)
[ 196.697114] mmc_host mmc1: Bus speed = 148500000Hz (req
150000000Hz, actual 148500000HZ div = 0)
[ 197.068697] dwmmc_rockchip fe2c0000.mmc: Successfully tuned phase to 208
[root@diasom-evb ~]#
So,
Tested-by: Alexander Shiyan <eagle.alexander923@xxxxxxxxx>
>
> 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@xxxxxxxxxxxxxxx
> Fixes: bef4a48f4ef7 ("spi: Fix null dereference on suspend")
> Signed-off-by: Sebastian Reichel <sebastian.reichel@xxxxxxxxxxxxx>
> ---
> 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@xxxxxxxxx/
> ---
> 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@xxxxxxxxxxxxx>
>