On Thu, Aug 24, 2023 at 09:37:38AM +0800, Feiyang Chen wrote: > When the current state is already PCI_D0, pci_power_up() will return > 0 even though dev->pm_cap is not set. In that case, we should not > read the PCI_PM_CTRL register in pci_set_full_power_state(). > > There is nothing more needs to be done below in that case. > Additionally, pci_power_up() has two callers only and the other one > ignores the return value, so we can safely move the current state > check from pci_power_up() to pci_set_full_power_state(). Does this fix a bug? I guess it does, because previously pci_set_full_power_state() did a config read at 0 + PCI_PM_CTRL, i.e., offset 4, which is actually PCI_COMMAND, and set dev->current_state based on that. So dev->current_state is now junk, right? This might account for some "Refused to change power state from %s to D0" messages. How did you find this? It's nice if we can mention a symptom so people can connect the problem with this fix. This sounds like something that probably should have a stable tag? > Fixes: e200904b275c ("PCI/PM: Split pci_power_up()") > Signed-off-by: Feiyang Chen <chenfeiyang@xxxxxxxxxxx> > Reviewed-by: Rafael J. Wysocki <rafael@xxxxxxxxxx> > --- > drivers/pci/pci.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 60230da957e0..7e90ab7b47a1 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -1242,9 +1242,6 @@ int pci_power_up(struct pci_dev *dev) > else > dev->current_state = state; > > - if (state == PCI_D0) > - return 0; > - > return -EIO; > } > > @@ -1302,8 +1299,12 @@ static int pci_set_full_power_state(struct pci_dev *dev) > int ret; > > ret = pci_power_up(dev); > - if (ret < 0) > + if (ret < 0) { > + if (dev->current_state == PCI_D0) > + return 0; > + > return ret; > + } > > pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); > dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK; > -- > 2.39.3 >