Re: [PATCH] PM: runtime: Return -EINPROGRESS from rpm_resume() in the RPM_NOWAIT case
From: Alan Stern
Date: Thu Sep 22 2022 - 15:32:18 EST
On Thu, Sep 22, 2022 at 08:04:40PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
>
> The prospective callers of rpm_resume() passing RPM_NOWAIT to it may
> be confused when it returns 0 without actually resuming the device
> which may happen if the device is suspending at the given time and it
> will only resume when the suspend in progress has completed. To avoid
> that confusion, return -EINPROGRESS from rpm_resume() in that case.
>
> Since none of the current callers passing RPM_NOWAIT to rpm_resume()
> check its return value, this change has no functional impact.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
> ---
> drivers/base/power/runtime.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> Index: linux-pm/drivers/base/power/runtime.c
> ===================================================================
> --- linux-pm.orig/drivers/base/power/runtime.c
> +++ linux-pm/drivers/base/power/runtime.c
> @@ -792,10 +792,13 @@ static int rpm_resume(struct device *dev
> DEFINE_WAIT(wait);
>
> if (rpmflags & (RPM_ASYNC | RPM_NOWAIT)) {
Hmmm, and what if a caller sets both of these flags? I guess in that
case he gets what he deserves.
> - if (dev->power.runtime_status == RPM_SUSPENDING)
> + if (dev->power.runtime_status == RPM_SUSPENDING) {
> dev->power.deferred_resume = true;
> - else
> + if (rpmflags & RPM_NOWAIT)
> + retval = -EINPROGRESS;
> + } else {
> retval = -EINPROGRESS;
> + }
> goto out;
> }
Acked-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>