diff mbox series

[v2,1/2] net: eth-uclass: Fix eth_halt

Message ID 20220402025836.19374-1-qianfanguijin@163.com
State Rejected
Delegated to: Ramon Fried
Headers show
Series [v2,1/2] net: eth-uclass: Fix eth_halt | expand

Commit Message

qianfan April 2, 2022, 2:58 a.m. UTC
From: qianfan Zhao <qianfanguijin@163.com>

eth_device_priv maybe unaccessable after @stop handler due to eth device
is removed in @stop, touch it will trigger data abort.

Fix data abort bug when run dhcp or tftp command via usbnet.

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
---
 net/eth-uclass.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 0da0e85be0..2b88b6c145 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -339,8 +339,15 @@  void eth_halt(void)
 		return;
 
 	eth_get_ops(current)->stop(current);
-	priv->state = ETH_STATE_PASSIVE;
-	priv->running = false;
+
+	/* ethernet device maybe removed when @stop handler, that will cause
+	 * @priv is freed. get private data again to avoid it
+	 */
+	priv = dev_get_uclass_priv(current);
+	if (priv) {
+		priv->state = ETH_STATE_PASSIVE;
+		priv->running = false;
+	}
 }
 
 int eth_is_active(struct udevice *dev)