On Tue, Aug 22, 2023 at 11:41 AM Feiyang Chen <chenfeiyang@xxxxxxxxxxx> wrote: > > If the pm_cap of the PCI device is unset, do not read the > PCI_PM_CTRL register in pci_set_full_power_state(). So this is the case when the current state is already 0 and so pci_power_up() returns 0 even though dev->pm_cap is not set. This should be mentioned in the changelog. > Fixes: e200904b275c ("PCI/PM: Split pci_power_up()") > Signed-off-by: Feiyang Chen <chenfeiyang@xxxxxxxxxxx> > --- > drivers/pci/pci.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 60230da957e0..d6671cefcfa7 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -1305,8 +1305,10 @@ static int pci_set_full_power_state(struct pci_dev *dev) > if (ret < 0) > return ret; IMO it would be better to move the dev->current_state == PCI_D0 check from pci_power_up() to this place, that is if (ret < 0) { if (dev->current_state == PCI_D0) return 0; return ret; } because nothing more needs to be done below in that case. > > - pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); > - dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK; > + if (dev->pm_cap) { > + pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); > + dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK; > + } > if (dev->current_state != PCI_D0) { > pci_info_ratelimited(dev, "Refused to change power state from %s to D0\n", > pci_power_name(dev->current_state)); > -- > 2.39.3 >