From owner-svn-src-stable-10@FreeBSD.ORG Fri Jan 9 02:43:19 2015 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F06FE12F; Fri, 9 Jan 2015 02:43:18 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DBAF6F92; Fri, 9 Jan 2015 02:43:18 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t092hIXx062931; Fri, 9 Jan 2015 02:43:18 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t092hI0q062930; Fri, 9 Jan 2015 02:43:18 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201501090243.t092hI0q062930@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Fri, 9 Jan 2015 02:43:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r276873 - stable/10/sys/dev/usb/net X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jan 2015 02:43:19 -0000 Author: loos Date: Fri Jan 9 02:43:17 2015 New Revision: 276873 URL: https://svnweb.freebsd.org/changeset/base/276873 Log: MFC: r273546 Fix a bug where some DTS layouts could cause the premature ending of the search (i.e. without returning any result) and you would end up with a random MAC address. Change the search algorithm to a recursive one to ensure that all the nodes on DTS will be verified. The previous algorithm could not keep up if the DTS has too many sub-nodes. While here, fix the punctuation on comments. Modified: stable/10/sys/dev/usb/net/if_smsc.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/usb/net/if_smsc.c ============================================================================== --- stable/10/sys/dev/usb/net/if_smsc.c Fri Jan 9 02:38:12 2015 (r276872) +++ stable/10/sys/dev/usb/net/if_smsc.c Fri Jan 9 02:43:17 2015 (r276873) @@ -1535,57 +1535,56 @@ smsc_ioctl(struct ifnet *ifp, u_long cmd } #ifdef FDT +static phandle_t +smsc_fdt_find_eth_node(phandle_t start) +{ + phandle_t child, node; + + /* Traverse through entire tree to find usb ethernet nodes. */ + for (node = OF_child(start); node != 0; node = OF_peer(node)) { + if (fdt_is_compatible(node, "net,ethernet") && + fdt_is_compatible(node, "usb,device")) + return (node); + child = smsc_fdt_find_eth_node(node); + if (child != 0) + return (child); + } + + return (0); +} + /** - * Get MAC address from FDT blob. Firmware or loader should fill - * mac-address or local-mac-address property Returns 0 if MAC address - * obtained, error code otherwise + * Get MAC address from FDT blob. Firmware or loader should fill + * mac-address or local-mac-address property. Returns 0 if MAC address + * obtained, error code otherwise. */ static int smsc_fdt_find_mac(unsigned char *mac) { - phandle_t child, parent, root; + phandle_t node, root; int len; root = OF_finddevice("/"); - len = 0; - parent = root; - - /* Traverse through entire tree to find nodes usb ethernet nodes */ - for (child = OF_child(parent); child != 0; child = OF_peer(child)) { - - /* Find a 'leaf'. Start the search from this node. */ - while (OF_child(child)) { - parent = child; - child = OF_child(child); - } - - if (fdt_is_compatible(child, "net,ethernet") && - fdt_is_compatible(child, "usb,device")) { + node = smsc_fdt_find_eth_node(root); + if (node != 0) { - /* Check if there is property */ - if ((len = OF_getproplen(child, "local-mac-address")) > 0) { - if (len != ETHER_ADDR_LEN) - return (EINVAL); - - OF_getprop(child, "local-mac-address", mac, - ETHER_ADDR_LEN); - return (0); - } - - if ((len = OF_getproplen(child, "mac-address")) > 0) { - if (len != ETHER_ADDR_LEN) - return (EINVAL); - - OF_getprop(child, "mac-address", mac, - ETHER_ADDR_LEN); - return (0); - } + /* Check if there is property */ + if ((len = OF_getproplen(node, "local-mac-address")) > 0) { + if (len != ETHER_ADDR_LEN) + return (EINVAL); + + OF_getprop(node, "local-mac-address", mac, + ETHER_ADDR_LEN); + return (0); } - if (OF_peer(child) == 0) { - /* No more siblings. */ - child = parent; - parent = OF_parent(child); + if ((len = OF_getproplen(node, "mac-address")) > 0) { + if (len != ETHER_ADDR_LEN) + return (EINVAL); + + OF_getprop(node, "mac-address", mac, + ETHER_ADDR_LEN); + return (0); } }