Re: [PATCH net 1/8] net: bcmgenet: fix 64-bit RTNL stats reading in ethtool on 32-bit systems

Nicolai Buchwitz <[email protected]>
Newsgroups org.kernel.vger.netdev,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On 18.9.2026 02:07, Florian Fainelli wrote:
> When bcmgenet was converted to 64-bit statistics, STAT_RTNL members 
> were
> switched to point into struct rtnl_link_stats64, whose fields are 
> 64-bit
> (__u64) regardless of architecture.
> 
> However, bcmgenet_get_ethtool_stats() retained a legacy check:
>   if (sizeof(unsigned long) != sizeof(u32) &&
>       s->stat_sizeof == sizeof(unsigned long))
> 
> On 32-bit systems, sizeof(unsigned long) == sizeof(u32), causing this
> condition to evaluate to false. As a result, 64-bit RTNL stats fields 
> were
> read via *(u32 *)p. On 32-bit Big-Endian systems (such as MIPS BE), 
> this
> reads the high 32 bits and returns 0 until the counter exceeds 4GB; on
> 32-bit Little-Endian systems (such as 32-bit ARM), the value is 
> truncated
> to 32 bits.
> 
> Fix this by checking if s->stat_sizeof == sizeof(u64) so 64-bit fields 
> are
> always read as 64-bit values.
> 
> Fixes: 59aa6e3072aa ("net: bcmgenet: switch to use 64bit statistics")
> Assisted-by: LLM
> Co-authored-by: Cursor <[email protected]>
> Change-Id: I3e9f2f8d4fd136392148d6c0cd4eb40f7ccbe4ef
> ---
>  drivers/net/ethernet/broadcom/genet/bcmgenet.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c 
> b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> index b916080f4ff1..7b089de9484e 100644
> --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
> @@ -1346,9 +1346,8 @@ static void bcmgenet_get_ethtool_stats(struct 
> net_device *dev,
>  				p = (char *)&stats64;
> 
>  			p += s->stat_offset;
> -			if (sizeof(unsigned long) != sizeof(u32) &&
> -				s->stat_sizeof == sizeof(unsigned long))
> -				data[i] = *(unsigned long *)p;
> +			if (s->stat_sizeof == sizeof(u64))
> +				data[i] = *(u64 *)p;
>  			else
>  				data[i] = *(u32 *)p;
>  		}

Reviewed-by: Nicolai Buchwitz <[email protected]>

Thanks,
Nicolai
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.