All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Popple <alistair@popple.id.au>
To: mpe@ellerman.id.au
Cc: robh+dt@kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	mhairgrove@nvidia.com, shailendras@nvidia.com,
	Alistair Popple <alistair@popple.id.au>
Subject: [PATCH 2/3] powerpc/powernv: Add sanity checks to pnv_pci_get_{gpu|npu}_dev
Date: Wed, 22 Mar 2017 14:49:32 +1100	[thread overview]
Message-ID: <1490154573-22475-2-git-send-email-alistair@popple.id.au> (raw)
In-Reply-To: <1490154573-22475-1-git-send-email-alistair@popple.id.au>

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 incorrectly called which can be harder to
spot than an explicit WARN_ON.

Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 arch/powerpc/platforms/powernv/npu-dma.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/powerpc/platforms/powernv/npu-dma.c b/arch/powerpc/platforms/powernv/npu-dma.c
index 1c383f3..050bd5d 100644
--- a/arch/powerpc/platforms/powernv/npu-dma.c
+++ b/arch/powerpc/platforms/powernv/npu-dma.c
@@ -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)
--
2.1.4

  reply	other threads:[~2017-03-22  3:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22  3:49 [PATCH 1/3] drivers/of/base.c: Add of_property_read_u64_index Alistair Popple
2017-03-22  3:49 ` Alistair Popple [this message]
2017-03-22  3:49 ` [PATCH 3/3] powerpc/powernv: Introduce address translation services for Nvlink2 Alistair Popple
2017-03-24 12:28   ` Michael Ellerman
2017-03-24 12:28     ` Michael Ellerman
2017-03-24 13:53   ` kbuild test robot
2017-03-24 13:53     ` kbuild test robot
2017-03-22 14:49 ` [PATCH 1/3] drivers/of/base.c: Add of_property_read_u64_index Rob Herring
2017-03-22 14:49   ` Rob Herring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1490154573-22475-2-git-send-email-alistair@popple.id.au \
    --to=alistair@popple.id.au \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mhairgrove@nvidia.com \
    --cc=mpe@ellerman.id.au \
    --cc=robh+dt@kernel.org \
    --cc=shailendras@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.