Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pci: Fix crash in PCI code on ppc64 when matching device nodes

Commit b5d937de0367d26f65b9af1aef5f2c34c1939be0 has a bug which causes
basically a NULL dereference in the PCI code during boot on ppc64
machines.

fetch_dev_dn() is called when dev->dev.of_node is NULL, so using that
as the starting point for the search makes no sense. It should instead
start from the device node of the PHB.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

+5 -2
+5 -2
arch/powerpc/kernel/pci_dn.c
··· 176 176 */ 177 177 struct device_node *fetch_dev_dn(struct pci_dev *dev) 178 178 { 179 - struct device_node *orig_dn = dev->dev.of_node; 179 + struct pci_controller *phb = dev->sysdata; 180 180 struct device_node *dn; 181 181 unsigned long searchval = (dev->bus->number << 8) | dev->devfn; 182 182 183 - dn = traverse_pci_devices(orig_dn, is_devfn_node, (void *)searchval); 183 + if (WARN_ON(!phb)) 184 + return NULL; 185 + 186 + dn = traverse_pci_devices(phb->dn, is_devfn_node, (void *)searchval); 184 187 if (dn) 185 188 dev->dev.of_node = dn; 186 189 return dn;