]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
powerpc/powernv: Add sanity checks to pnv_pci_get_{gpu|npu}_dev
authorAlistair Popple <alistair@popple.id.au>
Fri, 12 May 2017 17:03:39 +0000 (14:03 -0300)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 20 Jun 2017 08:45:43 +0000 (10:45 +0200)
BugLink: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1690412
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 <alistair@popple.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
(cherry picked from commit 4c3b89effc281704d5395282c800c45e453235f6)
Signed-off-by: Breno Leitao <breno.leitao@gmail.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
arch/powerpc/platforms/powernv/npu-dma.c

index 34339c7e676b051cc1c7aae148a3993ebe512e90..8acebacfbad71d93e89745a3649938ad6cb9d3c4 100644 (file)
@@ -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)
@@ -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)