Skip to contentSkip to conversation

ACPI: PM: Fix device wakeup power reference counting error

PATCH In review Rafael J. Wysocki 2 participants 3 messages Nov 4, 2021 – Nov 5, 2021 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: PM: Fix device wakeup power reference counting error

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

Fix a device wakeup power reference counting error introduced by commit a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources").

Fixes a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources")
---
 drivers/acpi/power.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/acpi/power.c +1 -3
Index: linux-pm/drivers/acpi/power.c
===================================================================
@@ -757,10 +757,8 @@ int acpi_disable_wakeup_device_power(str
 
 	mutex_lock(&acpi_device_lock);
 
-	if (dev->wakeup.prepare_count > 1) {
+	if (dev->wakeup.prepare_count >= 1)
 		dev->wakeup.prepare_count--;
-		goto out;
-	}
 
 	/* Do nothing if wakeup power has not been enabled for this device. */
 	if (!dev->wakeup.prepare_count)
#1 lore raw
Quoted 18 lines · CET Rafael J. Wysocki

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

Fix a device wakeup power reference counting error introduced by commit a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources").

Fixes a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources")
---
 drivers/acpi/power.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================

drivers/acpi/power.c +0 -0
@@ -757,10 +757,8 @@ int acpi_disable_wakeup_device_power(str
 

drivers/acpi/power.c int acpi_disable_wakeup_device_power(str · line 764

Quoted 10 lines
drivers/acpi/power.c +1 -3
 	mutex_lock(&acpi_device_lock);
 
-	if (dev->wakeup.prepare_count > 1) {
+	if (dev->wakeup.prepare_count >= 1)
 		dev->wakeup.prepare_count--;
-		goto out;
-	}
 
 	/* Do nothing if wakeup power has not been enabled for this device. */
 	if (!dev->wakeup.prepare_count)

This is still not good. It should be something like the patch below, but I need to test that one.

---
From: Rafael J. Wysocki <[email protected]>
Subject: [PATCH v2] ACPI: PM: Fix device wakeup power reference counting error

Fix a device wakeup power reference counting error introduced by commit a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources").

Fixes a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources")

---

-> v2: Actually disable wakeup power when the reference count becomes zero.

---
 drivers/acpi/power.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/acpi/power.c +3 -5
Index: linux-pm/drivers/acpi/power.c
===================================================================
@@ -757,13 +757,11 @@ int acpi_disable_wakeup_device_power(str
 
 	mutex_lock(&acpi_device_lock);
 
-	if (dev->wakeup.prepare_count > 1) {
-		dev->wakeup.prepare_count--;
+	/* Do nothing if wakeup power has not been enabled for this device. */
+	if (dev->wakeup.prepare_count <= 0)
 		goto out;
-	}
 
-	/* Do nothing if wakeup power has not been enabled for this device. */
-	if (!dev->wakeup.prepare_count)
+	if (--dev->wakeup.prepare_count > 0)
 		goto out;
 
 	err = acpi_device_sleep_wake(dev, 0, 0, 0);
#2 lore raw
Quoted 28 lines · Rafael J. Wysocki
Quoted 26 lines · CET Rafael J. Wysocki

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

Fix a device wakeup power reference counting error introduced by commit a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources").

Fixes a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources")
---
 drivers/acpi/power.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================

drivers/acpi/power.c +1 -3
@@ -757,10 +757,8 @@ int acpi_disable_wakeup_device_power(str
 
      mutex_lock(&acpi_device_lock);
 
-     if (dev->wakeup.prepare_count > 1) {
+     if (dev->wakeup.prepare_count >= 1)
              dev->wakeup.prepare_count--;
-             goto out;
-     }
 
Quoted 5 lines

drivers/acpi/power.c int acpi_disable_wakeup_device_power(str · line 764

Quoted 2 lines
drivers/acpi/power.c +0 -0
      /* Do nothing if wakeup power has not been enabled for this device. */
      if (!dev->wakeup.prepare_count)

This is still not good. It should be something like the patch below, but I need to test that one.

Tested now, so applying as 5.16-rc material.

Quoted 43 lines

---
From: Rafael J. Wysocki <[email protected]>
Subject: [PATCH v2] ACPI: PM: Fix device wakeup power reference counting error

Fix a device wakeup power reference counting error introduced by commit a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources").

Fixes a2d7b2e004af ("ACPI: PM: Fix sharing of wakeup power resources")

---

-> v2: Actually disable wakeup power when the reference count becomes zero.

---
 drivers/acpi/power.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================

drivers/acpi/power.c +3 -5
@@ -757,13 +757,11 @@ int acpi_disable_wakeup_device_power(str
 
        mutex_lock(&acpi_device_lock);
 
-       if (dev->wakeup.prepare_count > 1) {
-               dev->wakeup.prepare_count--;
+       /* Do nothing if wakeup power has not been enabled for this device. */
+       if (dev->wakeup.prepare_count <= 0)
                goto out;
-       }
 
-       /* Do nothing if wakeup power has not been enabled for this device. */
-       if (!dev->wakeup.prepare_count)
+       if (--dev->wakeup.prepare_count > 0)
                goto out;
 
        err = acpi_device_sleep_wake(dev, 0, 0, 0);