Skip to contentSkip to conversation

PCI: PM: Fix ordering of operations in pci_back_from_sleep()

PATCH In review Rafael J. Wysocki 3 participants 3 messages Oct 15, 2021 – Oct 21, 2021 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: PM: Fix ordering of operations in pci_back_from_sleep()

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

The ordering of operations in pci_back_from_sleep() is incorrect, because the device may be in D3cold when it runs and pci_enable_wake() needs to access the device's configuration space which cannot be done in D3cold.

Fix this by calling pci_set_power_state() to put the device into D0 before calling pci_enable_wake() for it.

---
 drivers/pci/pci.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/pci/pci.c +6 -1
Index: linux-pm/drivers/pci/pci.c
===================================================================
@@ -2638,8 +2638,13 @@ EXPORT_SYMBOL(pci_prepare_to_sleep);
  */
 int pci_back_from_sleep(struct pci_dev *dev)
 {
+	int ret = pci_set_power_state(dev, PCI_D0);
+
+	if (ret)
+		return ret;
+
 	pci_enable_wake(dev, PCI_D0, false);
-	return pci_set_power_state(dev, PCI_D0);
+	return 0;
 }
 EXPORT_SYMBOL(pci_back_from_sleep);
 
#1 lore raw
Quoted 8 lines · Rafael J. Wysocki

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

The ordering of operations in pci_back_from_sleep() is incorrect, because the device may be in D3cold when it runs and pci_enable_wake() needs to access the device's configuration space which cannot be done in D3cold.

Quoted 4 lines

Fix this by calling pci_set_power_state() to put the device into D0 before calling pci_enable_wake() for it.

If there are no concerns about this one, I will queue it up for 5.16.

Quoted 26 lines
---
 drivers/pci/pci.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Index: linux-pm/drivers/pci/pci.c
===================================================================

drivers/pci/pci.c +6 -1
@@ -2638,8 +2638,13 @@ EXPORT_SYMBOL(pci_prepare_to_sleep);
  */
 int pci_back_from_sleep(struct pci_dev *dev)
 {
+       int ret = pci_set_power_state(dev, PCI_D0);
+
+       if (ret)
+               return ret;
+
        pci_enable_wake(dev, PCI_D0, false);
-       return pci_set_power_state(dev, PCI_D0);
+       return 0;
 }
 EXPORT_SYMBOL(pci_back_from_sleep);
 
Acked-by on v1 1/1
#2 lore raw
In reply to Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki

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

The ordering of operations in pci_back_from_sleep() is incorrect, because the device may be in D3cold when it runs and pci_enable_wake() needs to access the device's configuration space which cannot be done in D3cold.

Fix this by calling pci_set_power_state() to put the device into D0 before calling pci_enable_wake() for it.

Thanks!

Quoted 26 lines
---
 drivers/pci/pci.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Index: linux-pm/drivers/pci/pci.c
===================================================================

drivers/pci/pci.c +6 -1
@@ -2638,8 +2638,13 @@ EXPORT_SYMBOL(pci_prepare_to_sleep);
  */
 int pci_back_from_sleep(struct pci_dev *dev)
 {
+	int ret = pci_set_power_state(dev, PCI_D0);
+
+	if (ret)
+		return ret;
+
 	pci_enable_wake(dev, PCI_D0, false);
-	return pci_set_power_state(dev, PCI_D0);
+	return 0;
 }
 EXPORT_SYMBOL(pci_back_from_sleep);