Linux SPI subsystem development
 help / color / mirror / Atom feed
* [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure
@ 2026-07-10 10:12 Praveen Talari
  2026-07-10 10:12 ` [PATCH v4 1/2] PM: runtime: Only set runtime_error on suspend callback failures Praveen Talari
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Praveen Talari @ 2026-07-10 10:12 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Mark Brown, Alok Chauhan, Stephen Boyd,
	Douglas Anderson, Dilip Kota, Girish Mahadevan, bjorn.andersson,
	Konrad Dybcio
  Cc: Praveen Talari, linux-pm, driver-core, linux-kernel,
	linux-arm-msm, linux-spi, Mukesh Kumar Savaliya, aniket.randive,
	chandana.chiluveru

When a runtime PM resume callback returns an error, rpm_callback() sets
power.runtime_error on the device.  All subsequent rpm_resume() calls
then return -EINVAL immediately at the top of the function, permanently
blocking any future resume attempt — including those triggered by
consumers trying to power up their suppliers — until runtime PM is
explicitly re-initialized.

Unlike suspend failures, resume failures should be retryable.  The first
patch fixes this in the core by only setting power.runtime_error when a
suspend callback fails, leaving resume failures transient by nature.

The second patch fixes a pre-existing issue in the spi-geni-qcom driver
that this scenario exposed: pm_runtime_get_sync() was called in
spi_geni_init() without checking the return value, so a resume failure
would silently proceed to access hardware registers on a device that was
not powered up.

Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
Changes in v4:
- Added close brace to resolve build issue.
- Link to v3: https://patch.msgid.link/20260706-fix_sticky_-einval_after_pm_runtime_api_failure-v3-0-92feb5a7b926@oss.qualcomm.com

Changes in v3:
- Moved power.runtime_error assignment from rpm_callback() into
  rpm_suspend() at the fail label, per maintainer feedback.
- Link to v2: https://patch.msgid.link/20260703-fix_sticky_-einval_after_pm_runtime_api_failure-v2-0-578b78a0cf46@oss.qualcomm.com

Changes in v2:
- Reworked the fix per maintainer feedback: instead of calling
  pm_runtime_set_suspended() in rpm_get_suppliers(), fix the root cause
  in rpm_callback() by not setting power.runtime_error on resume
  callback failures.
- Link to v1: https://patch.msgid.link/20260702-fix_sticky_-einval_after_pm_runtime_api_failure-v1-0-6ddc317011c0@oss.qualcomm.com

To: "Rafael J. Wysocki" <rafael@kernel.org>
To: Pavel Machek <pavel@kernel.org>
To: Len Brown <lenb@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Danilo Krummrich <dakr@kernel.org>
To: Mark Brown <broonie@kernel.org>
To: Alok Chauhan <alokc@codeaurora.org>
To: Stephen Boyd <swboyd@chromium.org>
To: Douglas Anderson <dianders@chromium.org>
To: Dilip Kota <dkota@codeaurora.org>
To: Girish Mahadevan <girishm@codeaurora.org>
To: bjorn.andersson@oss.qualcomm.com
To: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Cc: linux-pm@vger.kernel.org
Cc: driver-core@lists.linux.dev
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: Mukesh Kumar Savaliya <mukesh.savaliya@oss.qualcomm.com>
Cc: aniket.randive@oss.qualcomm.com
Cc: chandana.chiluveru@oss.qualcomm.com

---
Praveen Talari (2):
      PM: runtime: Only set runtime_error on suspend callback failures
      spi: qcom-geni: Fix missing error check on pm_runtime_get_sync()

 drivers/base/power/runtime.c |  6 +++---
 drivers/spi/spi-geni-qcom.c  | 17 ++++++++++-------
 2 files changed, 13 insertions(+), 10 deletions(-)
---
base-commit: 34cf6dafc47441dfb6b356a095b89c3585a93714
change-id: 20260625-fix_sticky_-einval_after_pm_runtime_api_failure-6797d0a5c4d0

Best regards,
--  
Praveen Talari <praveen.talari@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/2] PM: runtime: Only set runtime_error on suspend callback failures
  2026-07-10 10:12 [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure Praveen Talari
@ 2026-07-10 10:12 ` Praveen Talari
  2026-07-10 10:14   ` Rafael J. Wysocki (Intel)
  2026-07-10 10:12 ` [PATCH v4 2/2] spi: qcom-geni: Fix missing error check on pm_runtime_get_sync() Praveen Talari
  2026-07-10 10:43 ` (subset) [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure Mark Brown
  2 siblings, 1 reply; 5+ messages in thread
From: Praveen Talari @ 2026-07-10 10:12 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Mark Brown, Alok Chauhan, Stephen Boyd,
	Douglas Anderson, Dilip Kota, Girish Mahadevan, bjorn.andersson,
	Konrad Dybcio
  Cc: Praveen Talari, linux-pm, driver-core, linux-kernel,
	linux-arm-msm, linux-spi, Mukesh Kumar Savaliya, aniket.randive,
	chandana.chiluveru

When a runtime resume callback returns an error, rpm_callback() sets
power.runtime_error on the device.  This causes all subsequent calls to
rpm_resume() to return -EINVAL immediately at the top of the function
without invoking the callback again, making the failure permanent until
runtime PM is explicitly re-initialized.

Unlike suspend failures, resume failures should be retryable.  If a
device's resume callback fails, there is no reason to permanently block
future resume attempts on that device and all of its consumers.

Fix this by moving the power.runtime_error assignment out of the generic
rpm_callback() and into rpm_suspend() at its fail label, where suspend
callback failures are handled.  Resume callback failures now return the
error to the caller but leave power.runtime_error clear, allowing the
next resume attempt to invoke the callback normally.

Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
 drivers/base/power/runtime.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 335288e8b5b3..fab38bc98113 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -469,9 +469,6 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev)
 	if (retval == -EACCES)
 		retval = -EAGAIN;
 
-	if (retval != -EAGAIN && retval != -EBUSY)
-		dev->power.runtime_error = retval;
-
 	return retval;
 }
 
@@ -751,6 +748,9 @@ static int rpm_suspend(struct device *dev, int rpmflags)
 	dev->power.deferred_resume = false;
 	wake_up_all(&dev->power.wait_queue);
 
+	if (retval != -EAGAIN && retval != -EBUSY)
+		dev->power.runtime_error = retval;
+
 	/*
 	 * On transient errors, if the callback routine failed an autosuspend,
 	 * and if the last_busy time has been updated so that there is a new

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/2] spi: qcom-geni: Fix missing error check on pm_runtime_get_sync()
  2026-07-10 10:12 [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure Praveen Talari
  2026-07-10 10:12 ` [PATCH v4 1/2] PM: runtime: Only set runtime_error on suspend callback failures Praveen Talari
@ 2026-07-10 10:12 ` Praveen Talari
  2026-07-10 10:43 ` (subset) [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure Mark Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Praveen Talari @ 2026-07-10 10:12 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Mark Brown, Alok Chauhan, Stephen Boyd,
	Douglas Anderson, Dilip Kota, Girish Mahadevan, bjorn.andersson,
	Konrad Dybcio
  Cc: Praveen Talari, linux-pm, driver-core, linux-kernel,
	linux-arm-msm, linux-spi, Mukesh Kumar Savaliya, aniket.randive,
	chandana.chiluveru

spi_geni_init() calls pm_runtime_get_sync() to power up the device
before accessing hardware registers, but never checks the return value.
If the runtime resume fails, the function silently proceeds to read and
write hardware registers on a device that may not be powered up, leading
to register access faults.

Fix this by replacing pm_runtime_get_sync() with the
PM_RUNTIME_ACQUIRE_IF_ENABLED() macro and checking the result via
PM_RUNTIME_ACQUIRE_ERR(), propagating any error back to the caller
immediately before any hardware access occurs.

Since the macro handles its own cleanup on failure, the out_pm label and
the corresponding pm_runtime_put() call are no longer needed. Replace
all goto out_pm paths with direct return ret statements and remove the
label entirely.

Fixes: 561de45f72bd ("spi: spi-geni-qcom: Add SPI driver support for GENI based QUP")
Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
 drivers/spi/spi-geni-qcom.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
index 88ac0833351c..2914d781dbf5 100644
--- a/drivers/spi/spi-geni-qcom.c
+++ b/drivers/spi/spi-geni-qcom.c
@@ -622,25 +622,30 @@ static int spi_geni_init(struct spi_geni_master *mas)
 	u32 spi_tx_cfg, fifo_disable;
 	int ret = -ENXIO;
 
-	pm_runtime_get_sync(mas->dev);
+	PM_RUNTIME_ACQUIRE_IF_ENABLED(mas->dev, pm);
+	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
+	if (ret < 0) {
+		dev_err(mas->dev, "Failed to resume and get %d\n", ret);
+		return ret;
+	}
 
 	proto = geni_se_read_proto(se);
 
 	if (spi->target) {
 		if (proto != GENI_SE_SPI_SLAVE) {
 			dev_err(mas->dev, "Invalid proto %d\n", proto);
-			goto out_pm;
+			return ret;
 		}
 		spi_slv_setup(mas);
 	} else if (proto == GENI_SE_INVALID_PROTO) {
 		ret = geni_load_se_firmware(se, GENI_SE_SPI);
 		if (ret) {
 			dev_err(mas->dev, "spi master firmware load failed ret: %d\n", ret);
-			goto out_pm;
+			return ret;
 		}
 	} else if (proto != GENI_SE_SPI) {
 		dev_err(mas->dev, "Invalid proto %d\n", proto);
-		goto out_pm;
+		return ret;
 	}
 	mas->tx_fifo_depth = geni_se_get_tx_fifo_depth(se);
 
@@ -673,7 +678,7 @@ static int spi_geni_init(struct spi_geni_master *mas)
 			dev_dbg(mas->dev, "Using GPI DMA mode for SPI\n");
 			break;
 		} else if (ret == -EPROBE_DEFER) {
-			goto out_pm;
+			return ret;
 		}
 		/*
 		 * in case of failure to get gpi dma channel, we can still do the
@@ -702,8 +707,6 @@ static int spi_geni_init(struct spi_geni_master *mas)
 		writel(spi_tx_cfg, se->base + SE_SPI_TRANS_CFG);
 	}
 
-out_pm:
-	pm_runtime_put(mas->dev);
 	return ret;
 }
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 1/2] PM: runtime: Only set runtime_error on suspend callback failures
  2026-07-10 10:12 ` [PATCH v4 1/2] PM: runtime: Only set runtime_error on suspend callback failures Praveen Talari
@ 2026-07-10 10:14   ` Rafael J. Wysocki (Intel)
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-07-10 10:14 UTC (permalink / raw)
  To: Praveen Talari
  Cc: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Mark Brown, Alok Chauhan, Stephen Boyd,
	Douglas Anderson, Dilip Kota, Girish Mahadevan, bjorn.andersson,
	Konrad Dybcio, linux-pm, driver-core, linux-kernel, linux-arm-msm,
	linux-spi, Mukesh Kumar Savaliya, aniket.randive,
	chandana.chiluveru

On Fri, Jul 10, 2026 at 12:13 PM Praveen Talari
<praveen.talari@oss.qualcomm.com> wrote:
>
> When a runtime resume callback returns an error, rpm_callback() sets
> power.runtime_error on the device.  This causes all subsequent calls to
> rpm_resume() to return -EINVAL immediately at the top of the function
> without invoking the callback again, making the failure permanent until
> runtime PM is explicitly re-initialized.
>
> Unlike suspend failures, resume failures should be retryable.  If a
> device's resume callback fails, there is no reason to permanently block
> future resume attempts on that device and all of its consumers.
>
> Fix this by moving the power.runtime_error assignment out of the generic
> rpm_callback() and into rpm_suspend() at its fail label, where suspend
> callback failures are handled.  Resume callback failures now return the
> error to the caller but leave power.runtime_error clear, allowing the
> next resume attempt to invoke the callback normally.
>
> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
> ---
>  drivers/base/power/runtime.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 335288e8b5b3..fab38bc98113 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -469,9 +469,6 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev)
>         if (retval == -EACCES)
>                 retval = -EAGAIN;
>
> -       if (retval != -EAGAIN && retval != -EBUSY)
> -               dev->power.runtime_error = retval;
> -
>         return retval;
>  }
>
> @@ -751,6 +748,9 @@ static int rpm_suspend(struct device *dev, int rpmflags)
>         dev->power.deferred_resume = false;
>         wake_up_all(&dev->power.wait_queue);
>
> +       if (retval != -EAGAIN && retval != -EBUSY)
> +               dev->power.runtime_error = retval;
> +
>         /*
>          * On transient errors, if the callback routine failed an autosuspend,
>          * and if the last_busy time has been updated so that there is a new
>
> --

This has been applied already.

Please provide a follow-up documentation update reflecting this change.

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: (subset) [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure
  2026-07-10 10:12 [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure Praveen Talari
  2026-07-10 10:12 ` [PATCH v4 1/2] PM: runtime: Only set runtime_error on suspend callback failures Praveen Talari
  2026-07-10 10:12 ` [PATCH v4 2/2] spi: qcom-geni: Fix missing error check on pm_runtime_get_sync() Praveen Talari
@ 2026-07-10 10:43 ` Mark Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2026-07-10 10:43 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, Stephen Boyd, Douglas Anderson, bjorn.andersson,
	Konrad Dybcio, Praveen Talari
  Cc: linux-pm, driver-core, linux-kernel, linux-arm-msm, linux-spi,
	Mukesh Kumar Savaliya, aniket.randive, chandana.chiluveru

On Fri, 10 Jul 2026 15:42:42 +0530, Praveen Talari wrote:
> PM: runtime: Fix sticky -EINVAL after resume callback failure
> 
> When a runtime PM resume callback returns an error, rpm_callback() sets
> power.runtime_error on the device.  All subsequent rpm_resume() calls
> then return -EINVAL immediately at the top of the function, permanently
> blocking any future resume attempt — including those triggered by
> consumers trying to power up their suppliers — until runtime PM is
> explicitly re-initialized.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.3

Thanks!

[2/2] spi: qcom-geni: Fix missing error check on pm_runtime_get_sync()
      https://git.kernel.org/broonie/spi/c/d8e9ea989acb

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-10 11:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-10 10:12 [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure Praveen Talari
2026-07-10 10:12 ` [PATCH v4 1/2] PM: runtime: Only set runtime_error on suspend callback failures Praveen Talari
2026-07-10 10:14   ` Rafael J. Wysocki (Intel)
2026-07-10 10:12 ` [PATCH v4 2/2] spi: qcom-geni: Fix missing error check on pm_runtime_get_sync() Praveen Talari
2026-07-10 10:43 ` (subset) [PATCH v4 0/2] PM: runtime: Fix sticky -EINVAL after resume callback failure Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox