gregkh / usbutils

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

Fix bug in sysfs path construction and expand usage of sysfs queries #110

Closed tchebb closed 3 years ago

tchebb commented 4 years ago

First off, I want to acknowledge that this pull request includes a fix for the same issue #108 fixes. I didn't notice that PR until I was almost done with this one, but I do think that the additional code cleanup and refactoring I did makes this PR worth reviewing, even ignoring its other changes.

So what are those other fixes? The commit messages have details, but to summarize they are

  1. Ensure that the existing logic to fall back on device-reported vendor/product names from sysfs is consistently applied. Currently, it's not used at all when listing only a single device using -D.
  2. When running with -v, fetch strings for iManufacturer, iProduct, and iSerial from sysfs instead of from libusb. This allows these values to be populated even when we don't have permission to open the device.
  3. General code cleanup by moving sysfs-related functions to their own file instead of mixing them in with hwdb-related ones.

Edit: I just noticed that #103 is ALSO a fix for the sysfs path issue. That fix is implemented very differently from mine but also makes sense.

tchebb commented 3 years ago

@ValZapod yes, it ought to. get_sysfs_name() creates the full dotted path within sysfs that corresponds to the device you give it.

gregkh commented 3 years ago

Thanks for this fix, it looks to be the most "complete" of the 3 different ways people have worked to address this issue. I'll merge it and see if it resolves everyone's issues...