Skip to contentSkip to conversation

ACPI: TAD: Improve runtime PM handling during driver removal

PATCH In review Rafael J. Wysocki 2 participants 3 messages Nov 19 – Nov 20 ACPI

lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 ACPI: TAD: Improve runtime PM handling during driver removal

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

In acpi_tad_remove(), instead of attempting a runtime suspend of the device which may be blocked by user space via "power/control", change the device's runtime PM status to "suspended" after disabling runtime PM for it to potentially unblock the runtime suspend of its parent and suppliers (if any).

Since pm_runtime_suspend() is not called in acpi_tad_remove() any more, the latter need not drop the runtime PM reference to the device held by it, so make it use guard()() instead of scoped_guard() for acquiring that reference and reduce the indentation level.

---
 drivers/acpi/acpi_tad.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/acpi/acpi_tad.c +12 -10
@@ -850,19 +850,21 @@ static void acpi_tad_remove(void *data)
 
 	device_init_wakeup(dev, false);
 
-	scoped_guard(pm_runtime_noresume, dev) {
-		if (dd->capabilities & ACPI_TAD_AC_WAKE) {
-			acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
-			acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
-		}
-		if (dd->capabilities & ACPI_TAD_DC_WAKE) {
-			acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
-			acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
-		}
+	guard(pm_runtime_noresume)(dev);
+
+	if (dd->capabilities & ACPI_TAD_AC_WAKE) {
+		acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
+		acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
+	}
+	if (dd->capabilities & ACPI_TAD_DC_WAKE) {
+		acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
+		acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
 	}
 
-	pm_runtime_suspend(dev);
 	pm_runtime_disable(dev);
+	/* Allow the parent and suppliers (if any) to suspend. */
+	pm_runtime_set_suspended(dev);
+	/* No need to power down, the PM domain detach will take care of it. */
 }
 
 static int acpi_tad_probe(struct platform_device *pdev)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 39 lines · Rafael J. Wysocki

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

In acpi_tad_remove(), instead of attempting a runtime suspend of the device which may be blocked by user space via "power/control", change the device's runtime PM status to "suspended" after disabling runtime PM for it to potentially unblock the runtime suspend of its parent and suppliers (if any).

Since pm_runtime_suspend() is not called in acpi_tad_remove() any more, the latter need not drop the runtime PM reference to the device held by it, so make it use guard()() instead of scoped_guard() for acquiring that reference and reduce the indentation level.

---
 drivers/acpi/acpi_tad.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/acpi/acpi_tad.c +6 -9
@@ -850,19 +850,21 @@ static void acpi_tad_remove(void *data)
 
 	device_init_wakeup(dev, false);
 
-	scoped_guard(pm_runtime_noresume, dev) {
-		if (dd->capabilities & ACPI_TAD_AC_WAKE) {
-			acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
-			acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
-		}
-		if (dd->capabilities & ACPI_TAD_DC_WAKE) {
-			acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
-			acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
-		}
+	guard(pm_runtime_noresume)(dev);
+
+	if (dd->capabilities & ACPI_TAD_AC_WAKE) {
+		acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
+		acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
+	}

drivers/acpi/acpi_tad.c static void acpi_tad_remove(void *data) · line 867

Quoted 10 lines
drivers/acpi/acpi_tad.c +6 -1
+	if (dd->capabilities & ACPI_TAD_DC_WAKE) {
+		acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
+		acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
 	}
 
-	pm_runtime_suspend(dev);
 	pm_runtime_disable(dev);
+	/* Allow the parent and suppliers (if any) to suspend. */
+	pm_runtime_set_suspended(dev);
+	/* No need to power down, the PM domain detach will take care of it. */

Personally, I think it's a little odd to require coding patterns like this (and comments, because it's admittedly subtle!) that assume .runtime_suspend() is a no-op. But it works for simple drivers like this, where the real work is done by others.

Anyway, that's just a general observation, and more of a framework thing. This patch looks fine:

BTW, should we drop pm_runtime_suspend() from probe() too? It's susceptible to the same sort of problem, although it's a benign one there. It's also a bit redundant, since there will be a post-probe() idle request anyway.

Brian

Quoted 6 lines
drivers/acpi/acpi_tad.c +0 -0
 }
 
 static int acpi_tad_probe(struct platform_device *pdev)
author maintainer
#2 lore raw
Quoted 57 lines · Brian Norris
Quoted 39 lines · Rafael J. Wysocki

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

In acpi_tad_remove(), instead of attempting a runtime suspend of the device which may be blocked by user space via "power/control", change the device's runtime PM status to "suspended" after disabling runtime PM for it to potentially unblock the runtime suspend of its parent and suppliers (if any).

Since pm_runtime_suspend() is not called in acpi_tad_remove() any more, the latter need not drop the runtime PM reference to the device held by it, so make it use guard()() instead of scoped_guard() for acquiring that reference and reduce the indentation level.

---
 drivers/acpi/acpi_tad.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/acpi/acpi_tad.c +6 -9
@@ -850,19 +850,21 @@ static void acpi_tad_remove(void *data)
 
      device_init_wakeup(dev, false);
 
-     scoped_guard(pm_runtime_noresume, dev) {
-             if (dd->capabilities & ACPI_TAD_AC_WAKE) {
-                     acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
-                     acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
-             }
-             if (dd->capabilities & ACPI_TAD_DC_WAKE) {
-                     acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
-                     acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
-             }
+     guard(pm_runtime_noresume)(dev);
+
+     if (dd->capabilities & ACPI_TAD_AC_WAKE) {
+             acpi_tad_disable_timer(dev, ACPI_TAD_AC_TIMER);
+             acpi_tad_clear_status(dev, ACPI_TAD_AC_TIMER);
+     }

drivers/acpi/acpi_tad.c static void acpi_tad_remove(void *data) · line 867

Quoted 10 lines
drivers/acpi/acpi_tad.c +6 -1
+     if (dd->capabilities & ACPI_TAD_DC_WAKE) {
+             acpi_tad_disable_timer(dev, ACPI_TAD_DC_TIMER);
+             acpi_tad_clear_status(dev, ACPI_TAD_DC_TIMER);
      }
 
-     pm_runtime_suspend(dev);
      pm_runtime_disable(dev);
+     /* Allow the parent and suppliers (if any) to suspend. */
+     pm_runtime_set_suspended(dev);
+     /* No need to power down, the PM domain detach will take care of it. */

Personally, I think it's a little odd to require coding patterns like this (and comments, because it's admittedly subtle!) that assume .runtime_suspend() is a no-op. But it works for simple drivers like this, where the real work is done by others.

Quoted 4 lines

Anyway, that's just a general observation, and more of a framework thing. This patch looks fine:

Thanks!

Quoted 4 lines

BTW, should we drop pm_runtime_suspend() from probe() too? It's susceptible to the same sort of problem, although it's a benign one there. It's also a bit redundant, since there will be a post-probe() idle request anyway.

Right, it is redundant.

Thanks for pointing this out to me!