diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2011-07-29 14:12:02 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2011-08-29 10:59:24 -0700 |
commit | cf14a2f01ae1749143060aa04df6f58dd5859d38 (patch) | |
tree | 31cd37019fd7683e08305e59e1b5e92d5092cd13 /net/eth.c | |
parent | 60531d5f97cb4993541029e7f537b66940f2ab08 (diff) |
eth: remove usb-ethernet devices before re-enumerating them
Fix the crash when running several times usb_init() with a USB ethernet
device plugged.
BUG=chromium-os:15206
TEST=run several "usb start" commands and having inserted/removed all
possible combinations of 0 to 3 USB Ethernet devices.
Change-Id: I23109ad8774daeb07eeba5de615700fec643dfdb
Reviewed-on: http://gerrit.chromium.org/gerrit/5026
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'net/eth.c')
-rw-r--r-- | net/eth.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/net/eth.c b/net/eth.c index 65238340601..0b198250a93 100644 --- a/net/eth.c +++ b/net/eth.c @@ -206,6 +206,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) { unsigned char env_enetaddr[6]; |