From patchwork Mon Jan 9 18:32:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Palatin X-Patchwork-Id: 135089 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 174D3B6FCA for ; Tue, 10 Jan 2012 05:38:58 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 54E27283C3; Mon, 9 Jan 2012 19:38:56 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id En40DwNW5t9h; Mon, 9 Jan 2012 19:38:56 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6C004283B2; Mon, 9 Jan 2012 19:38:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 36DC6283B2 for ; Mon, 9 Jan 2012 19:38:52 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JigSWW5Ward6 for ; Mon, 9 Jan 2012 19:38:51 +0100 (CET) X-Greylist: delayed 357 seconds by postgrey-1.27 at theia; Mon, 09 Jan 2012 19:38:49 CET X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ww0-f74.google.com (mail-ww0-f74.google.com [74.125.82.74]) by theia.denx.de (Postfix) with ESMTPS id 8ACAA28387 for ; Mon, 9 Jan 2012 19:38:49 +0100 (CET) Received: by wgbdt14 with SMTP id dt14so70064wgb.3 for ; Mon, 09 Jan 2012 10:38:49 -0800 (PST) Received: by 10.213.13.136 with SMTP id c8mr1725342eba.1.1326133970617; Mon, 09 Jan 2012 10:32:50 -0800 (PST) Received: by 10.213.13.136 with SMTP id c8mr1725326eba.1.1326133970427; Mon, 09 Jan 2012 10:32:50 -0800 (PST) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id v41si50076518eea.2.2012.01.09.10.32.50 (version=TLSv1/SSLv3 cipher=AES128-SHA); Mon, 09 Jan 2012 10:32:50 -0800 (PST) Received: from vpa.mtv.corp.google.com (vpa.mtv.corp.google.com [172.22.72.27]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id 3D2E620004E; Mon, 9 Jan 2012 10:32:50 -0800 (PST) Received: by vpa.mtv.corp.google.com (Postfix, from userid 125455) id 6F490160F5E; Mon, 9 Jan 2012 10:32:49 -0800 (PST) From: Vincent Palatin To: u-boot Date: Mon, 9 Jan 2012 10:32:36 -0800 Message-Id: <1326133956-25941-1-git-send-email-vpalatin@chromium.org> X-Mailer: git-send-email 1.7.3.1 Cc: Vincent Palatin , Wolfgang Grandegger Subject: [U-Boot] [PATCH] eth: remove usb-ethernet devices before re-enumerating them X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Fix the crash when running several times usb_init() with a USB ethernet device plugged. Signed-off-by: Vincent Palatin Tested-by: Wolfgang Grandegger --- drivers/usb/eth/usb_ether.c | 7 +++++-- include/net.h | 1 + net/eth.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/usb/eth/usb_ether.c b/drivers/usb/eth/usb_ether.c index 6565ea5..73a0790 100644 --- a/drivers/usb/eth/usb_ether.c +++ b/drivers/usb/eth/usb_ether.c @@ -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) diff --git a/include/net.h b/include/net.h index e4d42c2..1707a7f 100644 --- a/include/net.h +++ b/include/net.h @@ -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 */ diff --git a/net/eth.c b/net/eth.c index b4b9b43..3fb5fb6 100644 --- 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;