Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VID, PID and Subdev comparison cause unintended sign extension #76

Open
f14h opened this issue Nov 13, 2024 · 1 comment · May be fixed by #77
Open

VID, PID and Subdev comparison cause unintended sign extension #76

f14h opened this issue Nov 13, 2024 · 1 comment · May be fixed by #77

Comments

@f14h
Copy link

f14h commented Nov 13, 2024

VID, PID and SUBDEV are all unsigned 16bit values (per PCI specification).

As the corresponding struct uses signed 16bit values (on most architectures, implemented as short) and the bdx_get_phy_by_id function uses signed ints (32bit on most architectures) as arguments. This will cause an unintended sign extension e.g. for the "Edimax 10 Gigabit Ethernet SFP+ PCI Express Adapter" which has a subdev ID of 0x8103 (which will get extended to 0xffff8103) thus failing the comparison.

Fixing the struct to use ints instead was successful in our quick and dirty test, however, using u16 everywhere might be cleaner.

@jwstolk
Copy link

jwstolk commented Dec 4, 2024

I spend an afternoon digging though the code and found exactly the same issue:
[13177.288528] tn40xx 0000:06:00.0: Comparing [1fc9:4022:8103] with table [1fc9:4022:ffff8103] <-- this test fails

Also, it would more clear if bdx_get_phy_by_id() returned PHY_TYPE_NA instead of 0.
The value would be the same, since PHY_TYPE_NA is the first in the enum list.

And bdx_phy_init() has 4 code paths that can return PHY_TYPE_NA, the first being the call to bdx_get_phy_by_id().
The first 2 paths do the return without mentioning anything in dmesg, making it difficult to differentiate between the two causes.

Testing on an Ubuntu 24.04 machine, before upgrading the Ubuntu 22.04 machine where this card worked fine, with an old driver.

@jwstolk jwstolk linked a pull request Dec 5, 2024 that will close this issue
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 a pull request may close this issue.

2 participants