diff mbox series

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

Message ID feeb9f88-b72c-4a37-88ac-4bb28f4bfd3a@rowland.harvard.edu
State New
Headers show
Series usbutils: lsusb-t: print entries for devices with no interfaces | expand

Commit Message

Alan Stern Oct. 13, 2023, 3:22 p.m. UTC
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@interlog.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/linux-usb/70c563f1-847c-32a1-cf4d-6bf9802017ab@interlog.com/

---

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

Comments

Greg Kroah-Hartman Oct. 16, 2023, 6:05 p.m. UTC | #1
On Fri, Oct 13, 2023 at 11:22:12AM -0400, Alan Stern wrote:
> 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@interlog.com>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> Link: https://lore.kernel.org/linux-usb/70c563f1-847c-32a1-cf4d-6bf9802017ab@interlog.com/

Now applied, thanks!  I'll do a new release in a few days to get this
out to the world.

greg k-h
diff mbox series

Patch

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)