Repository navigation
Name USB devices without string descriptors from usb.ids - #233
Merged
Merged
Conversation
Since commit 1f32bb3 ("Replace libpci with a built-in pci.ids parser"), HAVE_NO_PCI no longer disables PCI support. It is only a test switch that keeps lib.cpp from loading the host's ID database, so the tests do not depend on the build host. The usb.ids lookup needs the same switch, and HAVE_NO_PCI would be a misleading name for it. Rename the switch in lib.cpp, all test build rules, the test comments, tests/testdesign.md and local.md. Test binaries built with the old name now read the host database again. For example, test_lib_pure built with -DHAVE_NO_PCI on a host with pci.ids: Results: 40 passed, 1 failed Built with -DHAVE_NO_HOST_IDS, using GCC 16.1.0: test_lib_pure: Results: 41 passed, 0 failed test_lib_pci: Results: 10 passed, 0 failed test_runtime: Results: 15 passed, 0 failed Assisted-by: claude-opus-5.5 (Claude Code)
usb.ids has the same format as pci.ids, so to name USB devices without
manufacturer and product strings, the parser needs to fill a table other
than the PCI one.
Move the vendor map, device map and loaded flag into a struct ids_table,
and pass the table and the database paths to the parse, load and lookup
helpers. The lookup returns the vendor and device names separately, as
USB callers print them in their own format. pci_id_to_name() keeps its
output.
No functional change. With GCC 16.1.0 the lib tests pass:
$ ./powertop-test-lib-pci
Results: 10 passed, 0 failed
$ ./powertop-test-lib-pure
Results: 41 passed, 0 failed
Assisted-by: claude-opus-5.5 (Claude Code)
Some USB devices have no manufacturer and product string descriptors, so
sysfs has no manufacturer and product files for them, and PowerTOP calls
them unknown. For example the Qualcomm Atheros QCA61x4 Bluetooth
controller in the Dell XPS 13 9360:
$ lsusb -v -d 0cf3:e300 2>/dev/null | grep -E 'iManufacturer|iProduct'
iManufacturer 0
iProduct 0
PowerTOP shows:
Bad Autosuspend for unknown USB device 1-3 (0cf3:e300)
lsusb names the device from the ID database instead.
Add usb_id_to_names(), which takes the sysfs idVendor and idProduct
strings and returns the vendor and product names from the first usb.ids
found in /usr/share/hwdata, /usr/share/misc, /usr/share or
/var/lib/usbutils. It uses the same parser as pci.ids and adds no build
dependency. Like for pci.ids, test builds with HAVE_NO_HOST_IDS never
read the host database, and tests use usb_ids_parse() for fixtures.
With GCC 16.1.0 the new test passes:
$ ./powertop-test-lib-usb-ids
Results: 13 passed, 0 failed
On a host with /usr/share/hwdata/usb.ids, usb_id_to_names("0cf3", "e300")
returns "Qualcomm Atheros Communications" and "QCA61x4 Bluetooth 4.0".
Assisted-by: claude-opus-5.5 (Claude Code)
On a Dell XPS 13 9360 with Debian sid, PowerTOP 2.15 shows:
Bad Autosuspend for unknown USB device 1-3 (0cf3:e300)
while lsusb names the device:
$ lsusb -d 0cf3:e300
Bus 001 Device 118: ID 0cf3:e300 Qualcomm Atheros Communications QCA61x4 Bluetooth 4.0
The QCA61x4 has no manufacturer and product string descriptors, so
sysfs has no manufacturer and product files. lsusb takes the name from
the ID database:
$ udevadm info /sys/bus/usb/devices/1-3 | grep FROM_DATABASE
E: ID_VENDOR_FROM_DATABASE=Qualcomm Atheros Communications
E: ID_MODEL_FROM_DATABASE=QCA61x4 Bluetooth 4.0
When both strings are missing, take the vendor and product names from
usb.ids, so the tunable reads:
Autosuspend for USB device QCA61x4 Bluetooth 4.0 [Qualcomm Atheros Communications]
Devices that are also missing from usb.ids keep the "unknown USB device"
text. Without the change, the new test fails:
Results: 13 passed, 2 failed
and passes with it:
Results: 15 passed, 0 failed
Assisted-by: claude-opus-5.5 (Claude Code)
Like the autosuspend tunable, the device statistics show USB devices
without manufacturer and product string descriptors only by their bus
position, for example "USB device: 1-3" for the Qualcomm Atheros
QCA61x4 Bluetooth controller (0cf3:e300) in the Dell XPS 13 9360.
When both strings are missing, read idVendor and idProduct and take the
names from usb.ids, so the entry reads:
USB device: QCA61x4 Bluetooth 4.0 (Qualcomm Atheros Communications)
The IDs are read only in that case, so the existing replay fixtures stay
valid, except for the hub fixture, which gets the two extra reads.
Without the change, the new test fails:
Results: 17 passed, 1 failed
and passes with it:
Results: 18 passed, 0 failed
Assisted-by: claude-opus-5.5 (Claude Code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
USB devices without manufacturer and product string descriptors have no
manufacturerandproductfiles in sysfs, so PowerTOP calls them unknown. On a Dell XPS 13 9360 with Debian sid/unstable, PowerTOP 2.15 shows the Qualcomm Atheros QCA61x4 Bluetooth controller as:The device does not provide the strings:
lsusbnames it from the USB ID database instead:This series makes PowerTOP do the same. usb.ids has the same format as pci.ids, so it reuses the pci.ids parser from 1f32bb3 ("Replace libpci with a built-in pci.ids parser") and adds no build dependency. When a device has neither string, the tunable and the device statistics take the names from the first usb.ids found in
/usr/share/hwdata,/usr/share/misc,/usr/shareor/var/lib/usbutils:Devices with at least one string keep their current name, and devices missing from usb.ids (or systems without usb.ids) keep the "unknown USB device" text. On Debian, usb.ids is in the optional
usb.idspackage, so packagers may want to add it to Recommends.The series also renames the test define
HAVE_NO_PCItoHAVE_NO_HOST_IDS. Since 1f32bb3 it no longer disables PCI support; it only keepslib.cppfrom loading the host's pci.ids, so the tests do not depend on the build machine. The usb.ids lookup needs the same guard, andHAVE_NO_PCIwould be a misleading name for it. All test build rules, test comments,tests/testdesign.mdandlocal.mduse the new name. Out-of-tree test builds that still pass-DHAVE_NO_PCIwould silently read the host databases again, so they need the new name too.Testing:
lib_ usb id lookup, plus a usb.ids case each inbase_ usb_tunableanddevices_ usbdevice serialize. The latter two fail without the fix.meson testwith-Denable-tests=truein Debian sid (GCC 16.2): 57 OK, 0 failed.