linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florinel Iordache <florinel.iordache@nxp.com>
To: madalin.bucur@nxp.com, davem@davemloft.net, kuba@kernel.org,
	netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	Florinel Iordache <florinel.iordache@nxp.com>
Subject: [PATCH net 2/5] fsl/fman: fix dereference null return value
Date: Fri, 31 Jul 2020 09:46:06 +0300	[thread overview]
Message-ID: <1596177969-27645-3-git-send-email-florinel.iordache@nxp.com> (raw)
In-Reply-To: <1596177969-27645-1-git-send-email-florinel.iordache@nxp.com>

Check before using returned value to avoid dereferencing null pointer.

Fixes: 18a6c85f ("fsl/fman: Add FMan Port Support")

Signed-off-by: Florinel Iordache <florinel.iordache@nxp.com>
---
 drivers/net/ethernet/freescale/fman/fman_port.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c
index 87b26f0..c27df15 100644
--- a/drivers/net/ethernet/freescale/fman/fman_port.c
+++ b/drivers/net/ethernet/freescale/fman/fman_port.c
@@ -1767,6 +1767,7 @@ static int fman_port_probe(struct platform_device *of_dev)
 	struct fman_port *port;
 	struct fman *fman;
 	struct device_node *fm_node, *port_node;
+	struct platform_device *fm_pdev;
 	struct resource res;
 	struct resource *dev_res;
 	u32 val;
@@ -1791,8 +1792,14 @@ static int fman_port_probe(struct platform_device *of_dev)
 		goto return_err;
 	}
 
-	fman = dev_get_drvdata(&of_find_device_by_node(fm_node)->dev);
+	fm_pdev = of_find_device_by_node(fm_node);
 	of_node_put(fm_node);
+	if (!fm_pdev) {
+		err = -EINVAL;
+		goto return_err;
+	}
+
+	fman = dev_get_drvdata(&fm_pdev->dev);
 	if (!fman) {
 		err = -EINVAL;
 		goto return_err;
-- 
1.9.1


  parent reply	other threads:[~2020-07-31  6:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31  6:46 [PATCH net 0/5] DPAA FMan driver fixes Florinel Iordache
2020-07-31  6:46 ` [PATCH net 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
2020-07-31  6:46 ` Florinel Iordache [this message]
2020-07-31  6:46 ` [PATCH net 3/5] fsl/fman: fix unreachable code Florinel Iordache
2020-07-31  6:46 ` [PATCH net 4/5] fsl/fman: check dereferencing null pointer Florinel Iordache
2020-07-31  7:48   ` Madalin Bucur
2020-07-31  6:46 ` [PATCH net 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache

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=1596177969-27645-3-git-send-email-florinel.iordache@nxp.com \
    --to=florinel.iordache@nxp.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madalin.bucur@nxp.com \
    --cc=netdev@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).