summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTan Li Boon <liboon.tan@mujin.co.jp>2022-01-06 15:17:51 +0900
committerTan Li Boon <liboon.tan@mujin.co.jp>2022-06-17 14:23:14 +0900
commit79d2126e7ee6b19d3882b8526a01f89fbd06abda (patch)
tree54bdcdde2fbbe5ad26138939f1806530268b770e
parent4bf4819a0dfddc53810a640e3be83dbbeeab0802 (diff)
downloadusbutils-79d2126e7ee6b19d3882b8526a01f89fbd06abda.tar.gz
lsusb-t: Fix recursive sorting on child devices.
Before this change, child devices beyond the first level of children underneath Bus IDs are not sorted. An example can be seen on a laptop with a USB-C dock attached to it. On current master, the output of lsusb -t looks like this: /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 10000M |__ Port 1: Dev 4, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M |__ Port 3: Dev 3, If 0, Class=Hub, Driver=hub/4p, 10000M /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M |__ Port 3: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M |__ Port 1: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 1: Dev 2, If 2, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 3: Dev 25, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 3: Dev 26, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 4: Dev 29, If 0, Class=Vendor Specific Class, Driver=pl2303, 12M |__ Port 2: Dev 27, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 2: Dev 27, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 3: Dev 28, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 4: Dev 32, If 1, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 4: Dev 32, If 0, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 2: Dev 31, If 2, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 2: Dev 31, If 0, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 2: Dev 31, If 3, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 2: Dev 31, If 1, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 1: Dev 30, If 0, Class=Vendor Specific Class, Driver=, 12M |__ Port 1: Dev 30, If 1, Class=Vendor Specific Class, Driver=, 12M |__ Port 8: Dev 6, If 1, Class=Video, Driver=uvcvideo, 480M |__ Port 8: Dev 6, If 0, Class=Video, Driver=uvcvideo, 480M |__ Port 9: Dev 8, If 0, Class=Vendor Specific Class, Driver=, 12M The devices or ports of the children from second level onwards are unsorted on in reverse order. After my change, the output becomes /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 10000M |__ Port 1: Dev 4, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M |__ Port 3: Dev 3, If 0, Class=Hub, Driver=hub/4p, 10000M /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M |__ Port 3: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 1: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 1: Dev 2, If 2, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 3: Dev 25, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 3: Dev 26, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 2: Dev 27, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 2: Dev 27, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M |__ Port 3: Dev 28, If 0, Class=Hub, Driver=hub/4p, 480M |__ Port 1: Dev 30, If 0, Class=Vendor Specific Class, Driver=, 12M |__ Port 1: Dev 30, If 1, Class=Vendor Specific Class, Driver=, 12M |__ Port 2: Dev 31, If 0, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 2: Dev 31, If 1, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 2: Dev 31, If 2, Class=Audio, Driver=snd-usb-audio, 12M |__ Port 2: Dev 31, If 3, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 4: Dev 32, If 0, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 4: Dev 32, If 1, Class=Human Interface Device, Driver=usbhid, 12M |__ Port 4: Dev 29, If 0, Class=Vendor Specific Class, Driver=pl2303, 12M |__ Port 8: Dev 6, If 0, Class=Video, Driver=uvcvideo, 480M |__ Port 8: Dev 6, If 1, Class=Video, Driver=uvcvideo, 480M |__ Port 9: Dev 8, If 0, Class=Vendor Specific Class, Driver=, 12M Where all devices are now correctly sorted in ascending order. Signed-off-by: Tan Li Boon <liboon.tan@mujin.co.jp>
-rw-r--r--lsusb-t.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/lsusb-t.c b/lsusb-t.c
index 88b6553..839321f 100644
--- a/lsusb-t.c
+++ b/lsusb-t.c
@@ -632,6 +632,7 @@ static void sort_dev_siblings(struct usbdevice **d)
pp = d;
swapped = 0;
while (p->next) {
+ sort_dev_siblings(&p->next);
if (p->portnum > p->next->portnum) {
t = p->next;
p->next = t->next;