acooks / tn40xx-driver

Linux driver for tn40xx from Tehuti Networks
73 stars 52 forks source link

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

Open f14h opened 5 days ago

f14h commented 5 days ago

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.