From: Jean-Jacques Hiblot <jjhiblot@ti.com>
Date: Thu, 9 Aug 2018 14:17:41 +0000 (+0200)
Subject: net: eth-uclass: Fix for DM USB ethernet support
X-Git-Tag: v2025.01-rc5-pxa1908~3684^2~5
X-Git-Url: http://git.dujemihanovic.xyz/%22mailto:Murray.Jensen%40csiro.au/static/%7B%7B%20%28.OutputFormats.Get?a=commitdiff_plain;h=c3211708cf721163733f03330bdb579d8c0f689b;p=u-boot.git

net: eth-uclass: Fix for DM USB ethernet support

When a USB ethernet device is halted, the device driver is removed. When
this happens the uclass private memory is freed and uclass_priv is set to
NULL. This causes a data abort when uclass_priv->state is then set to
ETH_STATE_PASSIVE.

Fix it by checking if uclass_priv is NULL before setting uclass_priv->state

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index fa3f5497a2..91d861be41 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -312,7 +312,8 @@ void eth_halt(void)
 
 	eth_get_ops(current)->stop(current);
 	priv = current->uclass_priv;
-	priv->state = ETH_STATE_PASSIVE;
+	if (priv)
+		priv->state = ETH_STATE_PASSIVE;
 }
 
 int eth_is_active(struct udevice *dev)