Skip to content

Commit

Permalink
powerpc/powernv: Add sanity checks to pnv_pci_get_{gpu|npu}_dev
Browse files Browse the repository at this point in the history
The pnv_pci_get_{gpu|npu}_dev functions are used to find associations
between nvlink PCIe devices and standard PCIe devices. However they
lacked basic sanity checking which results in NULL pointer
dereferencing if they are incorrect called can be harder to spot than
an explicit WARN_ON.

Signed-off-by: Alistair Popple <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
apopple authored and mpe committed Apr 3, 2017
1 parent 2475a2b commit 4c3b89e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions arch/powerpc/platforms/powernv/npu-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ struct pci_dev *pnv_pci_get_gpu_dev(struct pci_dev *npdev)
struct device_node *dn;
struct pci_dev *gpdev;

if (WARN_ON(!npdev))
return NULL;

if (WARN_ON(!npdev->dev.of_node))
return NULL;

/* Get assoicated PCI device */
dn = of_parse_phandle(npdev->dev.of_node, "ibm,gpu", 0);
if (!dn)
Expand All @@ -55,6 +61,12 @@ struct pci_dev *pnv_pci_get_npu_dev(struct pci_dev *gpdev, int index)
struct device_node *dn;
struct pci_dev *npdev;

if (WARN_ON(!gpdev))
return NULL;

if (WARN_ON(!gpdev->dev.of_node))
return NULL;

/* Get assoicated PCI device */
dn = of_parse_phandle(gpdev->dev.of_node, "ibm,npu", index);
if (!dn)
Expand Down

0 comments on commit 4c3b89e

Please sign in to comment.