aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-05-08 18:18:32 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-05-10 10:50:26 -0400
commitcfcadfaad7251d8b640713724b388164d75465b2 (patch)
tree7884aafbceb05c029aef956448a55c60fe6a5b36
parent8feaec33b9868582654cd3d5355225dcb79aeca6 (diff)
PCI / PM: Check device_may_wakeup() in pci_enable_wake()
Commit 0847684cfc5f0 (PCI / PM: Simplify device wakeup settings code) went too far and dropped the device_may_wakeup() check from pci_enable_wake() which causes wakeup to be enabled during system suspend, hibernation or shutdown for some PCI devices that are not allowed by user space to wake up the system from sleep (or power off). As a result of this, excessive power is drawn by some of the affected systems while in sleep states or off. Restore the device_may_wakeup() check in pci_enable_wake(), but make sure that the PCI bus type's runtime suspend callback will not call device_may_wakeup() which is about system wakeup from sleep and not about device wakeup from runtime suspend. Fixes: 0847684cfc5f0 (PCI / PM: Simplify device wakeup settings code) Reported-by: Joseph Salisbury <joseph.salisbury@canonical.com> Cc: 4.13+ <stable@vger.kernel.org> # 4.13+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r--drivers/pci/pci.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index c2616cad3a1d..dbfe7c4f3776 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1910,7 +1910,7 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
1910EXPORT_SYMBOL(pci_pme_active); 1910EXPORT_SYMBOL(pci_pme_active);
1911 1911
1912/** 1912/**
1913 * pci_enable_wake - enable PCI device as wakeup event source 1913 * __pci_enable_wake - enable PCI device as wakeup event source
1914 * @dev: PCI device affected 1914 * @dev: PCI device affected
1915 * @state: PCI state from which device will issue wakeup events 1915 * @state: PCI state from which device will issue wakeup events
1916 * @enable: True to enable event generation; false to disable 1916 * @enable: True to enable event generation; false to disable
@@ -1928,7 +1928,7 @@ EXPORT_SYMBOL(pci_pme_active);
1928 * Error code depending on the platform is returned if both the platform and 1928 * Error code depending on the platform is returned if both the platform and
1929 * the native mechanism fail to enable the generation of wake-up events 1929 * the native mechanism fail to enable the generation of wake-up events
1930 */ 1930 */
1931int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable) 1931static int __pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable)
1932{ 1932{
1933 int ret = 0; 1933 int ret = 0;
1934 1934
@@ -1969,6 +1969,23 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable)
1969 1969
1970 return ret; 1970 return ret;
1971} 1971}
1972
1973/**
1974 * pci_enable_wake - change wakeup settings for a PCI device
1975 * @pci_dev: Target device
1976 * @state: PCI state from which device will issue wakeup events
1977 * @enable: Whether or not to enable event generation
1978 *
1979 * If @enable is set, check device_may_wakeup() for the device before calling
1980 * __pci_enable_wake() for it.
1981 */
1982int pci_enable_wake(struct pci_dev *pci_dev, pci_power_t state, bool enable)
1983{
1984 if (enable && !device_may_wakeup(&pci_dev->dev))
1985 return -EINVAL;
1986
1987 return __pci_enable_wake(pci_dev, state, enable);
1988}
1972EXPORT_SYMBOL(pci_enable_wake); 1989EXPORT_SYMBOL(pci_enable_wake);
1973 1990
1974/** 1991/**
@@ -1981,9 +1998,9 @@ EXPORT_SYMBOL(pci_enable_wake);
1981 * should not be called twice in a row to enable wake-up due to PCI PM vs ACPI 1998 * should not be called twice in a row to enable wake-up due to PCI PM vs ACPI
1982 * ordering constraints. 1999 * ordering constraints.
1983 * 2000 *
1984 * This function only returns error code if the device is not capable of 2001 * This function only returns error code if the device is not allowed to wake
1985 * generating PME# from both D3_hot and D3_cold, and the platform is unable to 2002 * up the system from sleep or it is not capable of generating PME# from both
1986 * enable wake-up power for it. 2003 * D3_hot and D3_cold and the platform is unable to enable wake-up power for it.
1987 */ 2004 */
1988int pci_wake_from_d3(struct pci_dev *dev, bool enable) 2005int pci_wake_from_d3(struct pci_dev *dev, bool enable)
1989{ 2006{
@@ -2114,7 +2131,7 @@ int pci_finish_runtime_suspend(struct pci_dev *dev)
2114 2131
2115 dev->runtime_d3cold = target_state == PCI_D3cold; 2132 dev->runtime_d3cold = target_state == PCI_D3cold;
2116 2133
2117 pci_enable_wake(dev, target_state, pci_dev_run_wake(dev)); 2134 __pci_enable_wake(dev, target_state, pci_dev_run_wake(dev));
2118 2135
2119 error = pci_set_power_state(dev, target_state); 2136 error = pci_set_power_state(dev, target_state);
2120 2137