[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
<PAXPR04MB8510AADE753F4D8E195F61F9887BA@PAXPR04MB8510.eurprd04.prod.outlook.com>
Date: Wed, 25 Jun 2025 02:07:52 +0000
From: Wei Fang <wei.fang@....com>
To: Simon Horman <horms@...nel.org>, Claudiu Manoil <claudiu.manoil@....com>,
Vladimir Oltean <vladimir.oltean@....com>, Clark Wang <xiaoning.wang@....com>
CC: Andrew Lunn <andrew+netdev@...n.ch>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski
<kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, Alexandru Marginean
<alexandru.marginean@....com>, "imx@...ts.linux.dev" <imx@...ts.linux.dev>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: [PATCH net] net: enetc: Correct endianness handling in
_enetc_rd_reg64
> enetc_hw.h provides two versions of _enetc_rd_reg64.
> One which simply calls ioread64() when available.
> And another that composes the 64-bit result from ioread32() calls.
>
> In the second case the code appears to assume that each ioread32() call
> returns a little-endian value. However both the shift and logical or
> used to compose the return value would not work correctly on big endian
> systems if this were the case. Moreover, this is inconsistent with the
> first case where the return value of ioread64() is assumed to be in host
> byte order.
>
> It appears that the correct approach is for both versions to treat the
> return value of ioread*() functions as being in host byte order. And
> this patch corrects the ioread32()-based version to do so.
>
> This is a bug but would only manifest on big endian systems
> that make use of the ioread32-based implementation of _enetc_rd_reg64.
> While all in-tree users of this driver are little endian and
> make use of the ioread64-based implementation of _enetc_rd_reg64.
> Thus, no in-tree user of this driver is affected by this bug.
>
> Flagged by Sparse.
> Compile tested only.
>
> Cc: Wei Fang <wei.fang@....com>
> Fixes: 16eb4c85c964 ("enetc: Add ethtool statistics")
> Closes:
> https://lore.kern/
> el.org%2Fall%2FAM9PR04MB850500D3FC24FE23DEFCEA158879A%40AM9PR0
> 4MB8505.eurprd04.prod.outlook.com%2F&data=05%7C02%7Cwei.fang%40nxp
> .com%7Cefddfbd98e9747bd394d08ddb33d1e72%7C686ea1d3bc2b4c6fa92cd99
> c5c301635%7C0%7C0%7C638863797278832158%7CUnknown%7CTWFpbGZsb3
> d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIj
> oiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=4mt9vl78XAw%2BqX8
> w5zSo7xUA2aajicHGJnn6KpoNbXQ%3D&reserved=0
> Signed-off-by: Simon Horman <horms@...nel.org>
> ---
> drivers/net/ethernet/freescale/enetc/enetc_hw.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h
> b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
> index 4098f01479bc..53e8d18c7a34 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
> @@ -507,7 +507,7 @@ static inline u64 _enetc_rd_reg64(void __iomem *reg)
> tmp = ioread32(reg + 4);
> } while (high != tmp);
>
> - return le64_to_cpu((__le64)high << 32 | low);
> + return (u64)high << 32 | low;
> }
> #endif
>
Many thanks.
Reviewed-by: Wei Fang <wei.fang@....com>
Powered by blists - more mailing lists