Skip to content

Fix display of HID descriptors#228

Merged
gregkh merged 1 commit intogregkh:masterfrom
WaffleLapkin:fix-hid-descriptor-printing
Apr 15, 2025
Merged

Fix display of HID descriptors#228
gregkh merged 1 commit intogregkh:masterfrom
WaffleLapkin:fix-hid-descriptor-printing

Conversation

@WaffleLapkin
Copy link
Contributor

@WaffleLapkin WaffleLapkin commented Apr 13, 2025

The switch from hash tables to arrays + linear lookups in #202 (cc @evelikov) created a bug -- names_genericstrtable uses two variables (h and t) inconsistently in a loop, causing it to always return NULL, except for the first element in the array table.

This in turn causes everything (except "Usage Page") in the HID descriptors to be (null) instead of the right string.

I'm a bit surprised that this hasn't been caught by tests...

For comparison here is a snippet from lsusb -v without this patch:

          Report Descriptor: (length is 103)
            Item(Global): Usage Page, data= [ 0x01 ] 1
                            (null)
            Item(Local ): (null), data= [ 0x06 ] 6
                            (null)
            Item(Main  ): (null), data= [ 0x01 ] 1
                            Application
            Item(Global): (null), data= [ 0x01 ] 1
            Item(Global): Usage Page, data= [ 0x07 ] 7
                            (null)
            Item(Local ): (null), data= [ 0xe0 ] 224
                            (null)

And with this patch

          Report Descriptor: (length is 103)
            Item(Global): Usage Page, data= [ 0x01 ] 1
                            Generic Desktop Controls
            Item(Local ): Usage, data= [ 0x06 ] 6
                            Keyboard
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Global): Report ID, data= [ 0x01 ] 1
            Item(Global): Usage Page, data= [ 0x07 ] 7
                            Keyboard
            Item(Local ): Usage Minimum, data= [ 0xe0 ] 224
                            Control Left

The switch from hash tables to arrays + linear lookups created a bug --
`names_genericstrtable` uses two variables (`h` and `t`) inconsistently
in a loop, causing it to always return `NULL`, except for the first
element in the array table.

This in turn causes everything (except "Usage Page") in the HID
descriptors to be `(null)` instead of the right string.

Signed-off-by: Waffle Lapkin <waffle.lapkin@gmail.com>
@WaffleLapkin WaffleLapkin force-pushed the fix-hid-descriptor-printing branch from 94c0139 to d03ed80 Compare April 13, 2025 18:47
@gregkh
Copy link
Owner

gregkh commented Apr 15, 2025

thanks for the fix!

@gregkh gregkh merged commit 789fe26 into gregkh:master Apr 15, 2025
16 checks passed
@WaffleLapkin WaffleLapkin deleted the fix-hid-descriptor-printing branch April 15, 2025 22:11
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