From: Rafael J. Wysocki Date: Thu, 29 Jul 2021 15:54:28 +0000 (+0200) Subject: PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently X-Git-Tag: accepted/tizen/unified/20230118.172025~6538^2^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da9f2150684ea684a7ddd6d7f0e38b2bdf43dcd8;p=platform%2Fkernel%2Flinux-rpi.git PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently It is inconsistent to return PCI_D0 from pci_target_state() instead of the original target state if 'wakeup' is true and the device cannot signal PME from D0. This only happens when the device cannot signal PME from the original target state and any shallower power states (including D0) and that case is effectively equivalent to the one in which PME singaling is not supported at all. Since the original target state is returned in the latter case, make the function do that in the former one too. Link: https://lore.kernel.org/linux-pm/3149540.aeNJFYEL58@kreacher/ Fixes: 666ff6f83e1d ("PCI/PM: Avoid using device_may_wakeup() for runtime PM") Reported-by: Mika Westerberg Reported-by: Utkarsh H Patel Reported-by: Koba Ko Signed-off-by: Rafael J. Wysocki Reviewed-by: Mika Westerberg Tested-by: Mika Westerberg --- diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 375d298..2806f0c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2595,16 +2595,20 @@ static pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup) if (dev->current_state == PCI_D3cold) target_state = PCI_D3cold; - if (wakeup) { + if (wakeup && dev->pme_support) { + pci_power_t state = target_state; + /* * Find the deepest state from which the device can generate * PME#. */ - if (dev->pme_support) { - while (target_state - && !(dev->pme_support & (1 << target_state))) - target_state--; - } + while (state && !(dev->pme_support & (1 << state))) + state--; + + if (state) + return state; + else if (dev->pme_support & 1) + return PCI_D0; } return target_state;