Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: dlink: Correct endian treatment of t_SROM data

As it's name suggests, parse_eeprom() parses EEPROM data.

This is done by reading data, 16 bits at a time as follows:

for (i = 0; i < 128; i++)
((__le16 *) sromdata)[i] = cpu_to_le16(read_eeprom(np, i));

sromdata is at the same memory location as psrom.
And the type of psrom is a pointer to struct t_SROM.

As can be seen in the loop above, data is stored in sromdata, and thus
psrom, as 16-bit little-endian values. However, the integer fields of
t_SROM are host byte order.

In the case of the led_mode field this results in a but which has been
addressed by commit e7e5ae71831c ("net: dlink: Correct endianness
handling of led_mode").

In the case of the remaining fields, which are updated by this patch,
I do not believe this does not result in any bugs. But it does seem
best to correctly annotate the endianness of integers.

Flagged by Sparse as:

.../dl2k.c:344:35: warning: restricted __le32 degrades to integer

Compile tested only.
No run-time change intended.

Signed-off-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Simon Horman and committed by
David S. Miller
b3456571 bb91f754

+8 -8
+8 -8
drivers/net/ethernet/dlink/dl2k.h
··· 329 329 }; 330 330 331 331 typedef struct t_SROM { 332 - u16 config_param; /* 0x00 */ 333 - u16 asic_ctrl; /* 0x02 */ 334 - u16 sub_vendor_id; /* 0x04 */ 335 - u16 sub_system_id; /* 0x06 */ 336 - u16 pci_base_1; /* 0x08 (IP1000A only) */ 337 - u16 pci_base_2; /* 0x0a (IP1000A only) */ 332 + __le16 config_param; /* 0x00 */ 333 + __le16 asic_ctrl; /* 0x02 */ 334 + __le16 sub_vendor_id; /* 0x04 */ 335 + __le16 sub_system_id; /* 0x06 */ 336 + __le16 pci_base_1; /* 0x08 (IP1000A only) */ 337 + __le16 pci_base_2; /* 0x0a (IP1000A only) */ 338 338 __le16 led_mode; /* 0x0c (IP1000A only) */ 339 - u16 reserved1[9]; /* 0x0e-0x1f */ 339 + __le16 reserved1[9]; /* 0x0e-0x1f */ 340 340 u8 mac_addr[6]; /* 0x20-0x25 */ 341 341 u8 reserved2[10]; /* 0x26-0x2f */ 342 342 u8 sib[204]; /* 0x30-0xfb */ 343 - u32 crc; /* 0xfc-0xff */ 343 + __le32 crc; /* 0xfc-0xff */ 344 344 } SROM_t, *PSROM_t; 345 345 346 346 /* Ioctl custom data */