diff mbox

[U-Boot,1/1] net: core: avoid possible NULL pointer dereference

Message ID 20170516030701.29736-1-xypron.glpk@gmx.de
State Accepted
Commit c08248d601e939ababe1642d11be63d0c14c7d1a
Delegated to: Joe Hershberger
Headers show

Commit Message

Heinrich Schuchardt May 16, 2017, 3:07 a.m. UTC
Checking if dev is NULL after dereferencing it does not make sense.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 net/eth-uclass.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Joe Hershberger May 30, 2017, 4:59 p.m. UTC | #1
On Mon, May 15, 2017 at 10:07 PM, Heinrich Schuchardt
<xypron.glpk@gmx.de> wrote:
> Checking if dev is NULL after dereferencing it does not make sense.

Yes, it was incorrect, but fortunately it was never used for anything,
so even though it's garbage if the dev is NULL, at least we didn't use
it for anything in that case.

> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger June 2, 2017, 7:48 p.m. UTC | #2
Hi xypron.glpk@gmx.de,

https://patchwork.ozlabs.org/patch/762783/ was applied to u-boot-net.git.

Thanks!
-Joe
diff mbox

Patch

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index c3cc3152a2..b659961a5d 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -181,7 +181,7 @@  int eth_get_dev_index(void)
 
 static int eth_write_hwaddr(struct udevice *dev)
 {
-	struct eth_pdata *pdata = dev->platdata;
+	struct eth_pdata *pdata;
 	int ret = 0;
 
 	if (!dev || !device_active(dev))
@@ -189,6 +189,7 @@  static int eth_write_hwaddr(struct udevice *dev)
 
 	/* seq is valid since the device is active */
 	if (eth_get_ops(dev)->write_hwaddr && !eth_mac_skip(dev->seq)) {
+		pdata = dev->platdata;
 		if (!is_valid_ethaddr(pdata->enetaddr)) {
 			printf("\nError: %s address %pM illegal value\n",
 			       dev->name, pdata->enetaddr);