* [PATCH v1] PM: sleep: Unblock runtime PM when device prepare fails
@ 2026-08-18 16:18 Shibo Zhu
2026-08-25 2:00 ` Pengjie Zhang
0 siblings, 1 reply; 2+ messages in thread
From: Shibo Zhu @ 2026-08-18 16:18 UTC (permalink / raw)
To: Rafael J . Wysocki
Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, Danilo Krummrich,
Ulf Hansson, linux-pm, driver-core, linux-kernel
device_prepare() blocks runtime PM for a device with runtime PM disabled
before invoking its system-sleep ->prepare() callback. For a device that
has never enabled runtime PM, this changes dev->power.last_status from
RPM_INVALID to RPM_BLOCKED.
If the callback returns an error, dpm_prepare() does not move the device
to dpm_prepared_list. Consequently, the recovery path through
dpm_complete() never calls device_complete() for the failing device.
The error path drops the runtime PM usage reference, but does not clear
RPM_BLOCKED. A later legitimate pm_runtime_enable() then reports:
Attempt to enable runtime PM when it is blocked
before clearing the stale state.
Call pm_runtime_unblock() on the prepare error path before dropping the
runtime PM reference, matching the cleanup performed by device_complete().
The issue was reproduced with a platform test device whose ->prepare()
callback returns -EIO while runtime PM has never been enabled. Before
the fix, last_status remained RPM_BLOCKED after the failed suspend and
the first pm_runtime_enable() produced the warning above. With the fix,
last_status is restored to RPM_INVALID and the warning is absent.
Fixes: 3e5eee147b7b ("PM: Block enabling of runtime PM during system suspend")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.6-sol
Assisted-by: ChatGPT:GPT-5.6 Sol
Signed-off-by: Shibo Zhu <3499129952@qq.com>
---
drivers/base/power/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index f71467f6ada4..4ed2e9b7e99b 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -2234,6 +2234,7 @@ static int device_prepare(struct device *dev, pm_message_t state)
if (ret < 0) {
suspend_report_result(dev, callback, ret);
+ pm_runtime_unblock(dev);
pm_runtime_put(dev);
return ret;
}
base-commit: 0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] PM: sleep: Unblock runtime PM when device prepare fails
2026-08-18 16:18 [PATCH v1] PM: sleep: Unblock runtime PM when device prepare fails Shibo Zhu
@ 2026-08-25 2:00 ` Pengjie Zhang
0 siblings, 0 replies; 2+ messages in thread
From: Pengjie Zhang @ 2026-08-25 2:00 UTC (permalink / raw)
To: Shibo Zhu, Rafael J . Wysocki
Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, Danilo Krummrich,
Ulf Hansson, linux-pm, driver-core, linux-kernel
On 8/19/2026 12:18 AM, Shibo Zhu wrote:
> device_prepare() blocks runtime PM for a device with runtime PM disabled
> before invoking its system-sleep ->prepare() callback. For a device that
> has never enabled runtime PM, this changes dev->power.last_status from
> RPM_INVALID to RPM_BLOCKED.
>
> If the callback returns an error, dpm_prepare() does not move the device
> to dpm_prepared_list. Consequently, the recovery path through
> dpm_complete() never calls device_complete() for the failing device.
>
> The error path drops the runtime PM usage reference, but does not clear
> RPM_BLOCKED. A later legitimate pm_runtime_enable() then reports:
>
> Attempt to enable runtime PM when it is blocked
>
> before clearing the stale state.
>
> Call pm_runtime_unblock() on the prepare error path before dropping the
> runtime PM reference, matching the cleanup performed by device_complete().
>
> The issue was reproduced with a platform test device whose ->prepare()
> callback returns -EIO while runtime PM has never been enabled. Before
> the fix, last_status remained RPM_BLOCKED after the failed suspend and
> the first pm_runtime_enable() produced the warning above. With the fix,
> last_status is restored to RPM_INVALID and the warning is absent.
>
> Fixes: 3e5eee147b7b ("PM: Block enabling of runtime PM during system suspend")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:gpt-5.6-sol
> Assisted-by: ChatGPT:GPT-5.6 Sol
> Signed-off-by: Shibo Zhu <3499129952@qq.com>
> ---
> drivers/base/power/main.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index f71467f6ada4..4ed2e9b7e99b 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -2234,6 +2234,7 @@ static int device_prepare(struct device *dev, pm_message_t state)
>
> if (ret < 0) {
> suspend_report_result(dev, callback, ret);
> + pm_runtime_unblock(dev);
> pm_runtime_put(dev);
> return ret;
> }
LGTM.
Reviewed-by: Pengjie Zhang <zhangpengjie2@huawei.com>
> base-commit: 0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-25 2:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 16:18 [PATCH v1] PM: sleep: Unblock runtime PM when device prepare fails Shibo Zhu
2026-08-25 2:00 ` Pengjie Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox