Skip to contentSkip to conversation

PM: runtime: Return -EINPROGRESS from rpm_resume() in the RPM_NOWAIT case

PATCH In review Rafael J. Wysocki 5 participants 7 messages Sep 22, 2022 – Sep 26, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: runtime: Return -EINPROGRESS from rpm_resume() in the RPM_NOWAIT case

From: Rafael J. Wysocki <[email protected]>

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.

---
 drivers/base/power/runtime.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/base/power/runtime.c +5 -2
Index: 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)) {
-			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 on v1 1/1
#1 lore raw
Quoted 21 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

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.

---
 drivers/base/power/runtime.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c static int rpm_resume(struct device *dev · line 794

Quoted 3 lines
drivers/base/power/runtime.c +0 -0
@@ -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.

drivers/base/power/runtime.c static int rpm_resume(struct device *dev · line 803

Quoted 11 lines
drivers/base/power/runtime.c +5 -2
-			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;
 		}
#2 lore raw
Quoted 25 lines · Alan Stern
Quoted 23 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

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.

---
 drivers/base/power/runtime.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +0 -0
@@ -792,10 +792,13 @@ static int rpm_resume(struct device *dev
              DEFINE_WAIT(wait);
 
Quoted 4 lines

drivers/base/power/runtime.c static int rpm_resume(struct device *dev · line 794

Quoted 1 line
drivers/base/power/runtime.c +0 -0
              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.

Exactly.

Quoted 12 lines

drivers/base/power/runtime.c static int rpm_resume(struct device *dev · line 803

Quoted 11 lines
drivers/base/power/runtime.c +5 -2
-                     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;
              }
Quoted 1 line

Thanks!

Reviewed-by on v1 1/1
#3 lore raw
In reply to Rafael J. Wysocki

Hi,

Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

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.

Quoted 7 lines

Since none of the current callers passing RPM_NOWAIT to rpm_resume() check its return value, this change has no functional impact.

---
 drivers/base/power/runtime.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Seems reasonable to me.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

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.

Sounds like there are additional improvements that can be made around this, right?

Quoted 2 lines

Looks good to me!

Kind regards
Uffe

Quoted 27 lines
---
 drivers/base/power/runtime.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +5 -2
@@ -792,10 +792,13 @@ static int rpm_resume(struct device *dev
                DEFINE_WAIT(wait);
 
                if (rpmflags & (RPM_ASYNC | RPM_NOWAIT)) {
-                       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;
                }
 
#5 lore raw
Quoted 11 lines · Ulf Hansson
Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

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.

Quoted 5 lines
Quoted 2 lines

Since none of the current callers passing RPM_NOWAIT to rpm_resume() check its return value, this change has no functional impact.

Sounds like there are additional improvements that can be made around this, right?

This allows RPM_NOWAIT to be used in places where the caller doesn't want to wait, because it might deadlock or similar, but they still need to know whether or not the device can be accessed safely.

Or do you mean something else?

Quoted 6 lines
Quoted 2 lines

Looks good to me!

Thanks!

Quoted 27 lines
Quoted 27 lines
---
 drivers/base/power/runtime.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===================================================================

drivers/base/power/runtime.c +5 -2
@@ -792,10 +792,13 @@ static int rpm_resume(struct device *dev
                DEFINE_WAIT(wait);
 
                if (rpmflags & (RPM_ASYNC | RPM_NOWAIT)) {
-                       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;
                }
 
#6 lore raw
Quoted 16 lines · Rafael J. Wysocki
Quoted 14 lines · Ulf Hansson
Quoted 11 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

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.

Quoted 8 lines
Quoted 2 lines

Sounds like there are additional improvements that can be made around this, right?

This allows RPM_NOWAIT to be used in places where the caller doesn't want to wait, because it might deadlock or similar, but they still need to know whether or not the device can be accessed safely.

Or do you mean something else?

Nope, I was mostly wondering if you are planning to make those improvements too. Sooner or later.

[...]

Kind regards
Uffe