[PATCH] usbutils: lsusb-t: print entries for devices with no interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not all USB devices have interfaces.  This is true in particular of
the STMicroelectronics STEVAL-USBC2DP Type-C to DisplayPort adapter,
as well as possibly other USB-C devices.

As a result these devices do not show up in the output from "lsusb -t",
because the logic in print_tree_dev_interface() lists interfaces, not
devices (as implied by the function's name).  This means that the
output from "lsusb -t" can be inconsistent with the output from
"lsusb", since some devices are omitted.

To fix the problem, we make the subroutine call print_usbdevice() at
least once even if the device has no interfaces, and make the latter
routine print a minimal description of such devices (anything that does
not require access to the interface descriptor).

Reported-and-tested-by: Douglas Gilbert <dgilbert@xxxxxxxxxxxx>
Signed-off-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/linux-usb/70c563f1-847c-32a1-cf4d-6bf9802017ab@xxxxxxxxxxxx/

---

 lsusb-t.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Index: usbutils-master/lsusb-t.c
===================================================================
--- usbutils-master.orig/lsusb-t.c
+++ usbutils-master/lsusb-t.c
@@ -183,9 +183,12 @@ static void print_usbdevice(struct usbde
 	char lanes[32];
 
 	lanes_to_str(lanes, d->tx_lanes, d->rx_lanes);
-	get_class_string(subcls, sizeof(subcls), i->bInterfaceClass);
+	if (i)
+		get_class_string(subcls, sizeof(subcls), i->bInterfaceClass);
 
-	if (i->bInterfaceClass == 9)
+	if (!i)
+		printf("Port %03u: Dev %03u, %sM%s\n", d->portnum, d->devnum, d->speed, lanes);
+	else if (i->bInterfaceClass == 9)
 		printf("Port %03u: Dev %03u, If %u, Class=%s, Driver=%s/%up, %sM%s\n", d->portnum, d->devnum, i->ifnum, subcls,
 		       i->driver, d->maxchild, d->speed, lanes);
 	else
@@ -690,11 +693,12 @@ static void sort_busses(void)
 static void print_tree_dev_interface(struct usbdevice *d, struct usbinterface *i)
 {
 	indent += 3;
-	while (i) {
+	do {
 		printf(" %*s", indent, "|__ ");
 		print_usbdevice(d, i);
-		i = i->next;
-	}
+		if (i)
+			i = i->next;
+	} while (i);
 	indent -= 3;
 }
 static void print_tree_dev_children(struct usbdevice *d)




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux