Re: [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct

From: Stanislaw Gruszka

Date: Fri Jul 24 2026 - 11:21:25 EST


On Fri, Jul 24, 2026 at 02:57:33PM +0200, Andrew Lunn wrote:
> On Fri, Jul 24, 2026 at 10:34:11AM +0200, stf_xl@xxxxx wrote:
> > From: Stanislaw Gruszka <stf_xl@xxxxx>
> >
> > 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.
>
> 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.

> 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.

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