PCI: of_property: Add support for NULL pdev in of_pci_set_address()
authorHerve Codina <herve.codina@bootlin.com>
Mon, 24 Feb 2025 14:13:53 +0000 (15:13 +0100)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 28 Feb 2025 21:13:07 +0000 (15:13 -0600)
The pdev (pointer to a struct pci_dev) parameter of of_pci_set_address()
cannot be NULL.

In order to use of_pci_set_address() when creating the PCI root bus node,
it needs to support a NULL pdev parameter. Indeed, in the case of the PCI
root bus node creation, no pdev is available and of_pci_set_address() will
be used with the bridge windows.

Allow to call of_pci_set_address() with a NULL pdev.

Link: https://lore.kernel.org/r/20250224141356.36325-4-herve.codina@bootlin.com
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
drivers/pci/of_property.c

index 58fbafac7c6acbf4be17521eff0fc405c6605825..a6acd64ff8695819ed3bdc00d32b72b42a27465a 100644 (file)
@@ -54,9 +54,13 @@ enum of_pci_prop_compatible {
 static void of_pci_set_address(struct pci_dev *pdev, u32 *prop, u64 addr,
                               u32 reg_num, u32 flags, bool reloc)
 {
-       prop[0] = FIELD_PREP(OF_PCI_ADDR_FIELD_BUS, pdev->bus->number) |
-               FIELD_PREP(OF_PCI_ADDR_FIELD_DEV, PCI_SLOT(pdev->devfn)) |
-               FIELD_PREP(OF_PCI_ADDR_FIELD_FUNC, PCI_FUNC(pdev->devfn));
+       if (pdev) {
+               prop[0] = FIELD_PREP(OF_PCI_ADDR_FIELD_BUS, pdev->bus->number) |
+                         FIELD_PREP(OF_PCI_ADDR_FIELD_DEV, PCI_SLOT(pdev->devfn)) |
+                         FIELD_PREP(OF_PCI_ADDR_FIELD_FUNC, PCI_FUNC(pdev->devfn));
+       } else
+               prop[0] = 0;
+
        prop[0] |= flags | reg_num;
        if (!reloc) {
                prop[0] |= OF_PCI_ADDR_FIELD_NONRELOC;