diff mbox series

PCI/PM: Only read PCI_PM_CTRL register when available

Message ID 20230822094136.621740-1-chenfeiyang@loongson.cn
State New
Headers show
Series PCI/PM: Only read PCI_PM_CTRL register when available | expand

Commit Message

Feiyang Chen Aug. 22, 2023, 9:41 a.m. UTC
If the pm_cap of the PCI device is unset, do not read the
PCI_PM_CTRL register in pci_set_full_power_state().

Fixes: e200904b275c ("PCI/PM: Split pci_power_up()")
Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
---
 drivers/pci/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Rafael J. Wysocki Aug. 22, 2023, 10:23 a.m. UTC | #1
On Tue, Aug 22, 2023 at 11:41 AM Feiyang Chen <chenfeiyang@loongson.cn> 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@loongson.cn>
> ---
>  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
>
Feiyang Chen Aug. 22, 2023, 11:48 a.m. UTC | #2
On Tue, Aug 22, 2023 at 6:23 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Tue, Aug 22, 2023 at 11:41 AM Feiyang Chen <chenfeiyang@loongson.cn> 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.
>

OK.

> > Fixes: e200904b275c ("PCI/PM: Split pci_power_up()")
> > Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
> > ---
> >  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.
>

OK.

> >
> > -       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
> >
diff mbox series

Patch

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;
 
-	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));