]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
eth: remove usb-ethernet devices before re-enumerating them
authorVincent Palatin <vpalatin@chromium.org>
Mon, 9 Jan 2012 08:32:36 +0000 (08:32 +0000)
committerWolfgang Denk <wd@denx.de>
Sat, 3 Mar 2012 15:56:04 +0000 (16:56 +0100)
Fix the crash when running several times usb_init() with a USB ethernet
device plugged.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Wolfgang Grandegger <wg@denx.de>
drivers/usb/eth/usb_ether.c
include/net.h
net/eth.c

index 48a30ebbf99cee3fc534652531e7d66ad72197c6..6cad6c87caea165c2ec6268c1999d6805949d2f6 100644 (file)
@@ -127,8 +127,11 @@ int usb_host_eth_scan(int mode)
 
        old_async = usb_disable_asynch(1); /* asynch transfer not allowed */
 
-       for (i = 0; i < USB_MAX_ETH_DEV; i++)
-               memset(&usb_eth[i], 0, sizeof(usb_eth[i]));
+       /* unregister a previously detected device */
+       for (i = 0; i < usb_max_eth_dev; i++)
+               eth_unregister(&usb_eth[i].eth_dev);
+
+       memset(usb_eth, 0, sizeof(usb_eth));
 
        for (i = 0; prob_dev[i].probe; i++) {
                if (prob_dev[i].before_probe)
index e4d42c2a8be7d3f608beea634986cec52c6c4b66..1707a7fbec5fff2f64faf1c1f3faf55171297121 100644 (file)
@@ -96,6 +96,7 @@ struct eth_device {
 
 extern int eth_initialize(bd_t *bis);  /* Initialize network subsystem */
 extern int eth_register(struct eth_device* dev);/* Register network device */
+extern int eth_unregister(struct eth_device *dev);/* Remove network device */
 extern void eth_try_another(int first_restart);        /* Change the device */
 extern void eth_set_current(void);             /* set nterface to ethcur var */
 extern struct eth_device *eth_get_dev(void);   /* get the current device MAC */
index b4b9b4341fdecb25869a07cc8dbe9deefd6452bd..3fb5fb685700d4e558278a1c4b15e29764402c27 100644 (file)
--- a/net/eth.c
+++ b/net/eth.c
@@ -224,6 +224,35 @@ int eth_register(struct eth_device *dev)
        return 0;
 }
 
+int eth_unregister(struct eth_device *dev)
+{
+       struct eth_device *cur;
+
+       /* No device */
+       if (!eth_devices)
+               return -1;
+
+       for (cur = eth_devices; cur->next != eth_devices && cur->next != dev;
+            cur = cur->next)
+               ;
+
+       /* Device not found */
+       if (cur->next != dev)
+               return -1;
+
+       cur->next = dev->next;
+
+       if (eth_devices == dev)
+               eth_devices = dev->next == eth_devices ? NULL : dev->next;
+
+       if (eth_current == dev) {
+               eth_current = eth_devices;
+               eth_current_changed();
+       }
+
+       return 0;
+}
+
 int eth_initialize(bd_t *bis)
 {
        int num_devices = 0;