From patchwork Sun Jul 3 18:22:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 643800 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 3rjJQf5S6qz9t0T for ; Mon, 4 Jul 2016 04:22:18 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3DD1D4B9B0; Sun, 3 Jul 2016 20:22:17 +0200 (CEST) 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 M6OR-7UckaX2; Sun, 3 Jul 2016 20:22:16 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3B8E64B853; Sun, 3 Jul 2016 20:22:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D8E4A4B853 for ; Sun, 3 Jul 2016 20:22:13 +0200 (CEST) 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 pHJ8tBY2rQxW for ; Sun, 3 Jul 2016 20:22:13 +0200 (CEST) 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 mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by theia.denx.de (Postfix) with ESMTPS id 7A4FF4B7FB for ; Sun, 3 Jul 2016 20:22:11 +0200 (CEST) Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A2AF83F46; Sun, 3 Jul 2016 18:22:10 +0000 (UTC) Received: from shalem.localdomain.com (vpn1-5-3.ams2.redhat.com [10.36.5.3]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u63IM7wk023111; Sun, 3 Jul 2016 14:22:08 -0400 From: Hans de Goede To: Simon Glass , Marek Vasut Date: Sun, 3 Jul 2016 20:22:04 +0200 Message-Id: <1467570125-8790-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sun, 03 Jul 2016 18:22:10 +0000 (UTC) Cc: u-boot@lists.denx.de, Bernhard Nortmann Subject: [U-Boot] [PATCH 1/2] usb: dm: Add a usb_for_each_root_dev() helper function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Iterating over usb-root devs and doing something for all of them is a bit tricky with dm, factor out the proven usb_show_tree() for this into a helper function. Signed-off-by: Hans de Goede Reviewed-by: Simon Glass --- cmd/usb.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/usb.c b/cmd/usb.c index 58d9db2..5453c0d 100644 --- a/cmd/usb.c +++ b/cmd/usb.c @@ -438,9 +438,11 @@ static void usb_show_subtree(struct usb_device *dev) usb_show_tree_graph(dev, &preamble[0]); } -void usb_show_tree(void) -{ #ifdef CONFIG_DM_USB +typedef void (*usb_dev_func_t)(struct usb_device *udev); + +static void usb_for_each_root_dev(usb_dev_func_t func) +{ struct udevice *bus; for (uclass_find_first_device(UCLASS_USB, &bus); @@ -455,9 +457,16 @@ void usb_show_tree(void) device_find_first_child(bus, &dev); if (dev && device_active(dev)) { udev = dev_get_parent_priv(dev); - usb_show_subtree(udev); + func(udev); } } +} +#endif + +void usb_show_tree(void) +{ +#ifdef CONFIG_DM_USB + usb_for_each_root_dev(usb_show_subtree); #else struct usb_device *udev; int i;