All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
@ 2026-07-24  8:32 stf_xl
  0 siblings, 0 replies; 6+ messages in thread
From: stf_xl @ 2026-07-24  8:32 UTC (permalink / raw)
  To: netdev; +Cc: linux-kernel

From: Stanislaw Gruszka <stf_xl@wp.pl>

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.

Fixes: 7738a7ab9d12 ("misc: eeprom: eeprom_93cx6: Add quirk for extra read clock cycle")
Cc: stable@kernel.org # v6.13+
Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
---
 drivers/net/ethernet/8390/ax88796.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
index e1695d0fbd8b..5ee1fbafdcfc 100644
--- a/drivers/net/ethernet/8390/ax88796.c
+++ b/drivers/net/ethernet/8390/ax88796.c
@@ -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,
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
@ 2026-07-24  8:34 stf_xl
  2026-07-24 12:57 ` Andrew Lunn
  2026-07-24 13:04 ` Vadim Fedorenko
  0 siblings, 2 replies; 6+ messages in thread
From: stf_xl @ 2026-07-24  8:34 UTC (permalink / raw)
  To: netdev; +Cc: linux-kernel

From: Stanislaw Gruszka <stf_xl@wp.pl>

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.

Fixes: 7738a7ab9d12 ("misc: eeprom: eeprom_93cx6: Add quirk for extra read clock cycle")
Cc: stable@kernel.org # v6.13+
Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
---
 drivers/net/ethernet/8390/ax88796.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
index e1695d0fbd8b..5ee1fbafdcfc 100644
--- a/drivers/net/ethernet/8390/ax88796.c
+++ b/drivers/net/ethernet/8390/ax88796.c
@@ -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,
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
  2026-07-24  8:34 [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct stf_xl
@ 2026-07-24 12:57 ` Andrew Lunn
  2026-07-24 15:04   ` Stanislaw Gruszka
  2026-07-24 13:04 ` Vadim Fedorenko
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2026-07-24 12:57 UTC (permalink / raw)
  To: stf_xl; +Cc: netdev, linux-kernel

On Fri, Jul 24, 2026 at 10:34:11AM +0200, stf_xl@wp.pl wrote:
> From: Stanislaw Gruszka <stf_xl@wp.pl>
> 
> 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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
  2026-07-24  8:34 [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct stf_xl
  2026-07-24 12:57 ` Andrew Lunn
@ 2026-07-24 13:04 ` Vadim Fedorenko
  1 sibling, 0 replies; 6+ messages in thread
From: Vadim Fedorenko @ 2026-07-24 13:04 UTC (permalink / raw)
  To: stf_xl, netdev; +Cc: linux-kernel

On 24/07/2026 09:34, stf_xl@wp.pl wrote:
> From: Stanislaw Gruszka <stf_xl@wp.pl>
> 
> 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.
> 
> Fixes: 7738a7ab9d12 ("misc: eeprom: eeprom_93cx6: Add quirk for extra read clock cycle")
> Cc: stable@kernel.org # v6.13+
> Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
> ---
>   drivers/net/ethernet/8390/ax88796.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
> index e1695d0fbd8b..5ee1fbafdcfc 100644
> --- a/drivers/net/ethernet/8390/ax88796.c
> +++ b/drivers/net/ethernet/8390/ax88796.c
> @@ -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,

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
  2026-07-24 12:57 ` Andrew Lunn
@ 2026-07-24 15:04   ` Stanislaw Gruszka
  2026-07-24 16:05     ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Stanislaw Gruszka @ 2026-07-24 15:04 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, linux-kernel

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@wp.pl wrote:
> > From: Stanislaw Gruszka <stf_xl@wp.pl>
> > 
> > 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct
  2026-07-24 15:04   ` Stanislaw Gruszka
@ 2026-07-24 16:05     ` David Laight
  0 siblings, 0 replies; 6+ messages in thread
From: David Laight @ 2026-07-24 16:05 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: Andrew Lunn, netdev, linux-kernel

On Fri, 24 Jul 2026 17:04:03 +0200
Stanislaw Gruszka <stf_xl@wp.pl> wrote:

> 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@wp.pl wrote:  
> > > From: Stanislaw Gruszka <stf_xl@wp.pl>
> > > 
> > > 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.

Unless there are unions or padding...

	David

> 
> Regards
> Stanislaw
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-24 16:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24  8:34 [PATCH] net: ethernet: ax88796: initialize all fields of eeprom_93cx6 struct stf_xl
2026-07-24 12:57 ` Andrew Lunn
2026-07-24 15:04   ` Stanislaw Gruszka
2026-07-24 16:05     ` David Laight
2026-07-24 13:04 ` Vadim Fedorenko
  -- strict thread matches above, loose matches on Subject: below --
2026-07-24  8:32 stf_xl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.