net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
Subsystems (3)
PATCH 1/1 net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
From: Stanislaw Gruszka <[email protected]>
Commit 7738a7ab9d12 ("misc: eeprom: eeprom_93cx6: Add quirk for extra read clock cycle") added extra 'quirk' field to struct eeprom_93cx6, which change how the data is read.
Some existing users of eeprom_93cx6, including ax88796 driver, allocate the structure on the stack without initialization of all the fields. As a result, the added quirk field has undefined value, what can randomly cause reading wrong data from the EEPROM.
Fix by using designated initialization.
--- drivers/net/ethernet/8390/ax88796.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/8390/ax88796.c +6 -6
@@ -722,12 +722,12 @@ static int ax_init_dev(struct net_device *dev)#ifdef CONFIG_AX88796_93CX6 if (ax->plat->flags &AXFLG_HAS_93CX6 ) {unsigned char mac_addr[ETH_ALEN ]; -struct eeprom_93cx6 eeprom; - - eeprom.data = ei_local; - eeprom.register_read = ax_eeprom_register_read; - eeprom.register_write = ax_eeprom_register_write; - eeprom.width =PCI_EEPROM_WIDTH_93C56 ; +struct eeprom_93cx6 eeprom = { + .data = ei_local, + .register_read = ax_eeprom_register_read, + .register_write = ax_eeprom_register_write, + .width =PCI_EEPROM_WIDTH_93C56 , + }; eeprom_93cx6_multiread(&eeprom, 0, (__le16 __force *)mac_addr,
Signature · 1 line
2.50.1
Quoted 6 lines · On Fri, Jul 24, 2026 at 10:34:11AM +0200, [email protected] wrote:
From: Stanislaw Gruszka <[email protected]>
Commit
7738a7ab9d12("misc: eeprom:eeprom_93cx6: Add quirk for extra read clock cycle") added extra 'quirk' field to structeeprom_93cx6, which change how the data is read.
Quoted 6 lines
Some existing users of
eeprom_93cx6, including ax88796 driver, allocate the structure on the stack without initialization of all the fields. As a result, the added quirk field has undefined value, what can randomly cause reading wrong data from the EEPROM.Fix by using designated initialization.
The problem with this solution is that the next time another member is added, it breaks again.
struct eeprom_93cx6 eeprom = {0};
Will initialise all fields to 0, and then you can use the existing code to set those fields as needed.
Andrew
---
pw-bot: cr
Quoted 12 lines · Andrew Lunn
Quoted 11 lines · On Fri, Jul 24, 2026 at 10:34:11AM +0200, [email protected] wrote:
From: Stanislaw Gruszka <[email protected]>
Commit
7738a7ab9d12("misc: eeprom:eeprom_93cx6: Add quirk for extra read clock cycle") added extra 'quirk' field to structeeprom_93cx6, which change how the data is read.Some existing users of
eeprom_93cx6, including ax88796 driver, allocate the structure on the stack without initialization of all the fields. As a result, the added quirk field has undefined value, what can randomly cause reading wrong data from the EEPROM.
Quoted 4 lines
Quoted 1 line
Fix by using designated initialization.
The problem with this solution is that the next time another member is added, it breaks again.
I did not initialized 'quirks' explicitly in the patch.
Quoted 4 lines
struct
eeprom_93cx6eeprom = {0};Will initialise all fields to 0, and then you can use the existing code to set those fields as needed.
This form:
struct eeprom_93cx6 eeprom = {
.data = ei_local,
.register_read = ax_eeprom_register_read,
.register_write = ax_eeprom_register_write,
.width = PCI_EEPROM_WIDTH_93C56,
};will also initialize _all_ remaining fields to zero.
I believe it is guaranteed by C standard.
Regards
Stanislaw
Quoted 33 lines · On Fri, 24 Jul 2026 17:04:03 +0200 Stanislaw Gruszka <[email protected]> wrote:
Quoted 12 lines · Andrew Lunn
Quoted 11 lines · On Fri, Jul 24, 2026 at 10:34:11AM +0200, [email protected] wrote:
From: Stanislaw Gruszka <[email protected]>
Commit
7738a7ab9d12("misc: eeprom:eeprom_93cx6: Add quirk for extra read clock cycle") added extra 'quirk' field to structeeprom_93cx6, which change how the data is read.Some existing users of
eeprom_93cx6, including ax88796 driver, allocate the structure on the stack without initialization of all the fields. As a result, the added quirk field has undefined value, what can randomly cause reading wrong data from the EEPROM.Quoted 4 lines
Quoted 1 line
Fix by using designated initialization.
The problem with this solution is that the next time another member is added, it breaks again.
I did not initialized 'quirks' explicitly in the patch.
Quoted 4 lines
struct
eeprom_93cx6eeprom = {0};Will initialise all fields to 0, and then you can use the existing code to set those fields as needed.
This form:
struct eeprom_93cx6 eeprom = { .data = ei_local, .register_read = ax_eeprom_register_read, .register_write = ax_eeprom_register_write, .width = PCI_EEPROM_WIDTH_93C56, };
Quoted 3 lines
will also initialize _all_ remaining fields to zero.
I believe it is guaranteed by C standard.
Unless there are unions or padding...
David
Quoted 4 lines
Regards
Stanislaw
Quoted 33 lines · On 24/07/2026 09:34, [email protected] wrote:
From: Stanislaw Gruszka <[email protected]>
Commit
7738a7ab9d12("misc: eeprom:eeprom_93cx6: Add quirk for extra read clock cycle") added extra 'quirk' field to structeeprom_93cx6, which change how the data is read.Some existing users of
eeprom_93cx6, including ax88796 driver, allocate the structure on the stack without initialization of all the fields. As a result, the added quirk field has undefined value, what can randomly cause reading wrong data from the EEPROM.Fix by using designated initialization.
Fixes 7738a7ab9d12 ("misc: eeprom: eeprom_93cx6: Add quirk for extra read clock cycle")Cc [email protected] # v6.13+Signed-off-by Stanislaw Gruszka <[email protected]>--- drivers/net/ethernet/8390/ax88796.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/net/ethernet/8390/ax88796.c +0
-5@@ -722,12 +722,12 @@ static int ax_init_dev(struct net_device *dev)#ifdef CONFIG_AX88796_93CX6 if (ax->plat->flags &AXFLG_HAS_93CX6 ) {unsigned char mac_addr[ETH_ALEN ]; -struct eeprom_93cx6 eeprom; - - eeprom.data = ei_local; - eeprom.register_read = ax_eeprom_register_read; - eeprom.register_write = ax_eeprom_register_write;
drivers/net/ethernet/8390/ax88796.c static int ax_init_dev(struct net_device *dev) · line 733
Quoted 10 lines
drivers/net/ethernet/8390/ax88796.c +6
-1- eeprom.width =PCI_EEPROM_WIDTH_93C56 ; +struct eeprom_93cx6 eeprom = { + .data = ei_local, + .register_read = ax_eeprom_register_read, + .register_write = ax_eeprom_register_write, + .width =PCI_EEPROM_WIDTH_93C56 , + }; eeprom_93cx6_multiread(&eeprom, 0, (__le16 __force *)mac_addr,