diff mbox

[U-Boot,07/22] dm: usb: Fix "usb tree" output

Message ID 1434569645-30322-8-git-send-email-hdegoede@redhat.com
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Hans de Goede June 17, 2015, 7:33 p.m. UTC
last_child was abused by the old usb code to first store 1 if the
usb_device was not the root of the usb tree, and then later on re-used
to store whether or not the usb_device is actually the last child.

The dm-usb code was always setting it to actually reflect the last-child
status which is wrong for the last child leading to output like this:

USB device tree:
  1  Hub (12 Mb/s, 100mA)
  |  ALCOR USB Hub 2.0
  |
  | 2  Mass Storage (12 Mb/s, 100mA)
  |    USB Flash Disk 4C0E960F
  |
  +-3  Human Interface (1.5 Mb/s, 100mA)
       SINO WEALTH USB Composite Device

Instead of this:

USB device tree:
  1  Hub (12 Mb/s, 100mA)
  |  ALCOR USB Hub 2.0
  |
  +-2  Mass Storage (12 Mb/s, 100mA)
  |    USB Flash Disk 4C0E960F
  |
  +-3  Human Interface (1.5 Mb/s, 100mA)
       SINO WEALTH USB Composite Device

This commit fixes this by first checking that the device is not root,
and then setting last_child. This commit also updates the old code to not
abuse the last_child variable to store the root check result.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 common/cmd_usb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Simon Glass June 29, 2015, 3:45 a.m. UTC | #1
On 17 June 2015 at 13:33, Hans de Goede <hdegoede@redhat.com> wrote:
> last_child was abused by the old usb code to first store 1 if the
> usb_device was not the root of the usb tree, and then later on re-used
> to store whether or not the usb_device is actually the last child.
>
> The dm-usb code was always setting it to actually reflect the last-child
> status which is wrong for the last child leading to output like this:
>
> USB device tree:
>   1  Hub (12 Mb/s, 100mA)
>   |  ALCOR USB Hub 2.0
>   |
>   | 2  Mass Storage (12 Mb/s, 100mA)
>   |    USB Flash Disk 4C0E960F
>   |
>   +-3  Human Interface (1.5 Mb/s, 100mA)
>        SINO WEALTH USB Composite Device
>
> Instead of this:
>
> USB device tree:
>   1  Hub (12 Mb/s, 100mA)
>   |  ALCOR USB Hub 2.0
>   |
>   +-2  Mass Storage (12 Mb/s, 100mA)
>   |    USB Flash Disk 4C0E960F
>   |
>   +-3  Human Interface (1.5 Mb/s, 100mA)
>        SINO WEALTH USB Composite Device
>
> This commit fixes this by first checking that the device is not root,
> and then setting last_child. This commit also updates the old code to not
> abuse the last_child variable to store the root check result.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  common/cmd_usb.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>
Simon Glass July 7, 2015, 6:34 p.m. UTC | #2
On 28 June 2015 at 21:45, Simon Glass <sjg@chromium.org> wrote:
> On 17 June 2015 at 13:33, Hans de Goede <hdegoede@redhat.com> wrote:
>> last_child was abused by the old usb code to first store 1 if the
>> usb_device was not the root of the usb tree, and then later on re-used
>> to store whether or not the usb_device is actually the last child.
>>
>> The dm-usb code was always setting it to actually reflect the last-child
>> status which is wrong for the last child leading to output like this:
>>
>> USB device tree:
>>   1  Hub (12 Mb/s, 100mA)
>>   |  ALCOR USB Hub 2.0
>>   |
>>   | 2  Mass Storage (12 Mb/s, 100mA)
>>   |    USB Flash Disk 4C0E960F
>>   |
>>   +-3  Human Interface (1.5 Mb/s, 100mA)
>>        SINO WEALTH USB Composite Device
>>
>> Instead of this:
>>
>> USB device tree:
>>   1  Hub (12 Mb/s, 100mA)
>>   |  ALCOR USB Hub 2.0
>>   |
>>   +-2  Mass Storage (12 Mb/s, 100mA)
>>   |    USB Flash Disk 4C0E960F
>>   |
>>   +-3  Human Interface (1.5 Mb/s, 100mA)
>>        SINO WEALTH USB Composite Device
>>
>> This commit fixes this by first checking that the device is not root,
>> and then setting last_child. This commit also updates the old code to not
>> abuse the last_child variable to store the root check result.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  common/cmd_usb.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-dm/next, thanks!
diff mbox

Patch

diff --git a/common/cmd_usb.c b/common/cmd_usb.c
index eab55cd..ca06826 100644
--- a/common/cmd_usb.c
+++ b/common/cmd_usb.c
@@ -355,12 +355,12 @@  static void usb_show_tree_graph(struct usb_device *dev, char *pre)
 #endif
 	/* check if we are the last one */
 #ifdef CONFIG_DM_USB
-	last_child = device_is_last_sibling(dev->dev);
+	/* Not the root of the usb tree? */
+	if (device_get_uclass_id(dev->dev->parent) != UCLASS_USB) {
+		last_child = device_is_last_sibling(dev->dev);
 #else
-	last_child = (dev->parent != NULL);
-#endif
-	if (last_child) {
-#ifndef CONFIG_DM_USB
+	if (dev->parent != NULL) { /* not root? */
+		last_child = 1;
 		for (i = 0; i < dev->parent->maxchild; i++) {
 			/* search for children */
 			if (dev->parent->children[i] == dev) {