Subject: Re: [PATCH net-next v3 2/2] net: dsa: yt921x: Use u64_stats_t for MIB stats

From: Simon Horman <[email-masked]>
Date: Tue, 3 Mar 2026 11:31:37 +0000

On Fri, Feb 27, 2026 at 09:50:54PM +0800, David Yang wrote:
> 64-bit variables might not be atomic on 32-bit architectures, and could
> lead to load/store tearing. Use u64_stats_t to ensure consistency.
> 
> Signed-off-by: David Yang <[email-masked]>

...

> @@ -717,14 +716,29 @@ static int yt921x_read_mib(struct yt921x_priv *priv, int port)

...

> +	u64_stats_update_begin(&pp->syncp);
> +	for (size_t i = 0; i < ARRAY_SIZE(yt921x_mib_descs); i++) {
> +		u64_stats_set(&mib->stats[i],
> +			      u64_stats_read(&mib_new->stats[i]));
> +	}
> +	u64_stats_set(&pp->rx_frames, rx_frames);
> +	u64_stats_set(&pp->tx_frames, tx_frames);
> +	u64_stats_update_end(&pp->syncp);
>  
>  	return 0;
>  }

...

> @@ -782,9 +796,11 @@ yt921x_dsa_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
>  		if (!desc->name)
>  			continue;
>  
> -		data[j] = ((u64 *)mib)[i];
> +		data[j] = u64_stats_read(&((u64_stats_t *)mib)[i]);

Stats is available as a member of mib as an array of u64_stats_t.
So this code can avoid bypassing the type system with a cast.
And be consistent with an earlier change in this patch.

		data[j] = u64_stats_read(&mib->stats[i]);

>  		j++;
>  	}
> +
> +	mutex_unlock(&priv->reg_lock);
>  }

...