gregkh / usbutils

USB utilities for Linux, including lsusb
http://www.linux-usb.org
354 stars 199 forks source link

lsusb: Add function that sorts the output by device ID. #148

Closed undisputed-seraphim closed 10 months ago

undisputed-seraphim commented 2 years ago

On the master branch, device IDs are unsorted. An example from my laptop:

Bus 004 Device 003: ID 17ef:a393 Lenovo USB3.1 Hub
Bus 004 Device 004: ID 17ef:a387 Lenovo USB-C Dock Ethernet
Bus 004 Device 002: ID 17ef:a391 Lenovo USB3.1 Hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 0bda:0328 Realtek Semiconductor Corp. USB3.0-CRW
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 008: ID 06cb:009a Synaptics, Inc. Metallica MIS Touch Fingerprint Reader
Bus 001 Device 006: ID 5986:2115 Acer, Inc Integrated Camera
Bus 001 Device 029: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Action MA-8910P
Bus 001 Device 032: ID 045e:0823 Microsoft Corp. Classic IntelliMouse
Bus 001 Device 031: ID 17ef:a396 Lenovo ThinkPad USB-C Dock Gen2 USB Audio
Bus 001 Device 030: ID 04b4:521a Cypress Semiconductor Corp. USB-I2C Bridge
Bus 001 Device 028: ID 17ef:a395 Lenovo USB2.0 Hub
Bus 001 Device 027: ID 2be8:0002 ARCHISS PTR87 ARCHISS PTR87
Bus 001 Device 026: ID 17ef:a394 Lenovo USB2.0 Hub
Bus 001 Device 025: ID 17ef:a392 Lenovo USB2.0 Hub
Bus 001 Device 002: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

This patch introduces a function that sorts the device IDs by bus:

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 002: ID 17ef:a391 Lenovo USB3.1 Hub
Bus 004 Device 003: ID 17ef:a393 Lenovo USB3.1 Hub
Bus 004 Device 004: ID 17ef:a387 Lenovo USB-C Dock Ethernet
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 002: ID 0bda:0328 Realtek Semiconductor Corp. USB3.0-CRW
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 006: ID 5986:2115 Acer, Inc Integrated Camera
Bus 001 Device 008: ID 06cb:009a Synaptics, Inc. Metallica MIS Touch Fingerprint Reader
Bus 001 Device 025: ID 17ef:a392 Lenovo USB2.0 Hub
Bus 001 Device 026: ID 17ef:a394 Lenovo USB2.0 Hub
Bus 001 Device 027: ID 2be8:0002 ARCHISS PTR87 ARCHISS PTR87
Bus 001 Device 028: ID 17ef:a395 Lenovo USB2.0 Hub
Bus 001 Device 029: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Action MA-8910P
Bus 001 Device 030: ID 04b4:521a Cypress Semiconductor Corp. USB-I2C Bridge
Bus 001 Device 031: ID 17ef:a396 Lenovo ThinkPad USB-C Dock Gen2 USB Audio

Signed-off-by: Tan Li Boon liboon.tan@mujin.co.jp

Notes: I'm not really sure if this would be a thing that anyone besides me really 'wants'... Also C is not my primary language, I'm more used to working in C++, so please scrutinize my conventions.

undisputed-seraphim commented 1 year ago

If you are going to do this, shouldn't they also be sorted by bus at the same time?

I have added a new commit that performs this sort. Kindly review.

undisputed-seraphim commented 1 year ago

Just checking in on this pull request, it's not clear to me if there is anything that needs to be changed on my side (pending the discussion on whether or not the order of sorting of bus values should be reverse or otherwise)

It also looks like issue #161 asks about this, please let me know if there's been a decision (I'm OK with either way personally, as long as there is a sort)

gregkh commented 10 months ago

Sorry for the delay in review, this looks good now, thanks!