diff mbox series

PCI: Check for the existence of 'dev.of_node' before calling of_platform_populate()

Message ID 20240716080418.34426-1-manivannan.sadhasivam@linaro.org (mailing list archive)
State Superseded
Headers show
Series PCI: Check for the existence of 'dev.of_node' before calling of_platform_populate() | expand

Commit Message

Manivannan Sadhasivam July 16, 2024, 8:04 a.m. UTC
Commit 50b040ef3732 ("PCI/pwrctl: only call of_platform_populate() if
CONFIG_OF is enabled") added the CONFIG_OF guard for the
of_platform_populate() API. But it missed the fact that the CONFIG_OF
platforms can also run on ACPI without devicetree. In those cases,
of_platform_populate() will fail with below error messages as seen on the
Ampere Altra box:

pci 000c:00:01.0: failed to populate child OF nodes (-22)
pci 000c:00:02.0: failed to populate child OF nodes (-22)

Fix this by checking for the existence of 'dev.of_node' before calling the
of_platform_populate() API.

Fixes: 50b040ef3732 ("PCI/pwrctl: only call of_platform_populate() if CONFIG_OF is enabled")
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Closes: https://lore.kernel.org/linux-arm-msm/CAHk-=wjcO_9dkNf-bNda6bzykb5ZXWtAYA97p7oDsXPHmMRi6g@mail.gmail.com/
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/pci/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bartosz Golaszewski July 16, 2024, 3:24 p.m. UTC | #1
On Tue, Jul 16, 2024 at 10:04 AM Manivannan Sadhasivam
<manivannan.sadhasivam@linaro.org> wrote:
>
> Commit 50b040ef3732 ("PCI/pwrctl: only call of_platform_populate() if
> CONFIG_OF is enabled") added the CONFIG_OF guard for the
> of_platform_populate() API. But it missed the fact that the CONFIG_OF
> platforms can also run on ACPI without devicetree. In those cases,
> of_platform_populate() will fail with below error messages as seen on the
> Ampere Altra box:
>
> pci 000c:00:01.0: failed to populate child OF nodes (-22)
> pci 000c:00:02.0: failed to populate child OF nodes (-22)
>
> Fix this by checking for the existence of 'dev.of_node' before calling the
> of_platform_populate() API.
>
> Fixes: 50b040ef3732 ("PCI/pwrctl: only call of_platform_populate() if CONFIG_OF is enabled")
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Closes: https://lore.kernel.org/linux-arm-msm/CAHk-=wjcO_9dkNf-bNda6bzykb5ZXWtAYA97p7oDsXPHmMRi6g@mail.gmail.com/
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
>  drivers/pci/bus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
> index 3bab78cc68f7..12849a164acf 100644
> --- a/drivers/pci/bus.c
> +++ b/drivers/pci/bus.c
> @@ -350,7 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
>
>         pci_dev_assign_added(dev, true);
>
> -       if (IS_ENABLED(CONFIG_OF) && pci_is_bridge(dev)) {
> +       if (IS_ENABLED(CONFIG_OF) && dev_of_node(&dev->dev) && pci_is_bridge(dev)) {
>                 retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
>                                               &dev->dev);
>                 if (retval)
> --
> 2.25.1
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Linus Torvalds July 16, 2024, 6:02 p.m. UTC | #2
On Tue, 16 Jul 2024 at 01:04, Manivannan Sadhasivam
<manivannan.sadhasivam@linaro.org> wrote:
>
> -       if (IS_ENABLED(CONFIG_OF) && pci_is_bridge(dev)) {
> +       if (IS_ENABLED(CONFIG_OF) && dev_of_node(&dev->dev) && pci_is_bridge(dev)) {
>                 retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
>                                               &dev->dev);

I think you should just drop the IS_ENABLED(CONFIG_OF) check entirely.

afaik, dev_of_node() already returns NULL if CONFIG_OF isn't set.

So the bug was literally that you based the decision on something
pointless that shouldn't be there at all.

                Linus
Bartosz Golaszewski July 16, 2024, 6:49 p.m. UTC | #3
On Tue, Jul 16, 2024 at 8:02 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Tue, 16 Jul 2024 at 01:04, Manivannan Sadhasivam
> <manivannan.sadhasivam@linaro.org> wrote:
> >
> > -       if (IS_ENABLED(CONFIG_OF) && pci_is_bridge(dev)) {
> > +       if (IS_ENABLED(CONFIG_OF) && dev_of_node(&dev->dev) && pci_is_bridge(dev)) {
> >                 retval = of_platform_populate(dev->dev.of_node, NULL, NULL,

While at it: you could replace the dev.of_node here with dev_of_node()
too. I seem to have missed this helper.

Bartosz

> >                                               &dev->dev);
>
> I think you should just drop the IS_ENABLED(CONFIG_OF) check entirely.
>
> afaik, dev_of_node() already returns NULL if CONFIG_OF isn't set.
>
> So the bug was literally that you based the decision on something
> pointless that shouldn't be there at all.
>
>                 Linus
diff mbox series

Patch

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 3bab78cc68f7..12849a164acf 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -350,7 +350,7 @@  void pci_bus_add_device(struct pci_dev *dev)
 
 	pci_dev_assign_added(dev, true);
 
-	if (IS_ENABLED(CONFIG_OF) && pci_is_bridge(dev)) {
+	if (IS_ENABLED(CONFIG_OF) && dev_of_node(&dev->dev) && pci_is_bridge(dev)) {
 		retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
 					      &dev->dev);
 		if (retval)