Skip to content

Name USB devices without string descriptors from usb.ids - #233

Merged
fenrus75 merged 5 commits into
fenrus75:masterfrom
paulmenzel:use-usb.ids-names
Nov 10, 2026
Merged

fenrus75 merged 5 commits into
fenrus75:masterfrom
paulmenzel:use-usb.ids-names

Conversation

@paulmenzel

Copy link
Copy Markdown
Contributor

USB devices without manufacturer and product string descriptors have no manufacturer and product files 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:

Bad           Autosuspend for unknown USB device 1-3 (0cf3:e300)

The device does not provide the strings:

$ lsusb -v -d 0cf3:e300 2>/dev/null | grep -E 'iManufacturer|iProduct'
  iManufacturer           0
  iProduct                0

lsusb names it from the USB ID database instead:

$ lsusb -d 0cf3:e300
Bus 001 Device 118: ID 0cf3:e300 Qualcomm Atheros Communications QCA61x4 Bluetooth 4.0

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/share or /var/lib/usbutils:

Autosuspend for USB device QCA61x4 Bluetooth 4.0 [Qualcomm Atheros Communications]
USB device: QCA61x4 Bluetooth 4.0 (Qualcomm Atheros Communications)

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.ids package, so packagers may want to add it to Recommends.

The series also renames the test define HAVE_NO_PCI to HAVE_NO_HOST_IDS. Since 1f32bb3 it no longer disables PCI support; it only keeps lib.cpp from loading the host's pci.ids, so the tests do not depend on the build machine. The usb.ids lookup needs the same guard, and HAVE_NO_PCI would be a misleading name for it. All test build rules, test comments, tests/testdesign.md and local.md use the new name. Out-of-tree test builds that still pass -DHAVE_NO_PCI would silently read the host databases again, so they need the new name too.

Testing:

  • New tests: lib_ usb id lookup, plus a usb.ids case each in base_ usb_tunable and devices_ usbdevice serialize. The latter two fail without the fix.
  • meson test with -Denable-tests=true in Debian sid (GCC 16.2): 57 OK, 0 failed.
  • Successful test Dell XPS 13 9360

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)
@fenrus75
fenrus75 merged commit 86b327e into fenrus75:master Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants