* [PATCH net] eth: funeth: Include FEC stats in fun_free_stats_area() DMA free size
@ 2026-11-19 17:06 Ian Rogers
2026-11-23 9:07 ` Daniel Machon
0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2026-11-19 17:06 UTC (permalink / raw)
To: Dimitris Michailidis, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, llvm, Elkin Cruz, Ian Rogers
fun_init_stats_area() allocates coherent DMA memory for
(PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX)
64-bit counters (632 bytes), whereas fun_free_stats_area() omits
PORT_MAC_FEC_STATS_MAX and passes 616 bytes to dma_free_coherent(),
triggering DMA-API debug size-mismatch warnings on teardown.
Extract a shared fun_stats_area_size() helper used by both allocation and
deallocation paths, and cast the leading enum constant to unsigned int to
avoid cross-enum arithmetic.
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
-Wenum-enum-conversion enabled; fix and changelog drafted with an AI
coding assistant. Build-tested under LLVM=1 W=1 and
-Wenum-enum-conversion; not tested on Fungible Ethernet hardware.
Fixes: ee6373ddf3a9 ("net/funeth: probing and netdev ops")
Signed-off-by: Ian Rogers <irogers@google.com>
---
.../ethernet/fungible/funeth/funeth_main.c | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/fungible/funeth/funeth_main.c b/drivers/net/ethernet/fungible/funeth/funeth_main.c
index bad8276d26b0..e0d4e69abfa4 100644
--- a/drivers/net/ethernet/fungible/funeth/funeth_main.c
+++ b/drivers/net/ethernet/fungible/funeth/funeth_main.c
@@ -1457,17 +1457,20 @@ void fun_set_ring_count(struct net_device *netdev, unsigned int ntx,
}
}
-static int fun_init_stats_area(struct funeth_priv *fp)
+static size_t fun_stats_area_size(void)
{
- unsigned int nstats;
+ unsigned int nstats = (unsigned int)PORT_MAC_RX_STATS_MAX +
+ PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX;
+
+ return nstats * sizeof(u64);
+}
+static int fun_init_stats_area(struct funeth_priv *fp)
+{
if (!(fp->port_caps & FUN_PORT_CAP_STATS))
return 0;
- nstats = PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX +
- PORT_MAC_FEC_STATS_MAX;
-
- fp->stats = dma_alloc_coherent(&fp->pdev->dev, nstats * sizeof(u64),
+ fp->stats = dma_alloc_coherent(&fp->pdev->dev, fun_stats_area_size(),
&fp->stats_dma_addr, GFP_KERNEL);
if (!fp->stats)
return -ENOMEM;
@@ -1476,11 +1479,8 @@ static int fun_init_stats_area(struct funeth_priv *fp)
static void fun_free_stats_area(struct funeth_priv *fp)
{
- unsigned int nstats;
-
if (fp->stats) {
- nstats = PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX;
- dma_free_coherent(&fp->pdev->dev, nstats * sizeof(u64),
+ dma_free_coherent(&fp->pdev->dev, fun_stats_area_size(),
fp->stats, fp->stats_dma_addr);
fp->stats = NULL;
}
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] eth: funeth: Include FEC stats in fun_free_stats_area() DMA free size
2026-11-19 17:06 [PATCH net] eth: funeth: Include FEC stats in fun_free_stats_area() DMA free size Ian Rogers
@ 2026-11-23 9:07 ` Daniel Machon
2026-11-25 15:48 ` Paolo Abeni
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Machon @ 2026-11-23 9:07 UTC (permalink / raw)
To: Ian Rogers
Cc: Dimitris Michailidis, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, llvm,
Elkin Cruz
> fun_init_stats_area() allocates coherent DMA memory for
> (PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX)
> 64-bit counters (632 bytes), whereas fun_free_stats_area() omits
> PORT_MAC_FEC_STATS_MAX and passes 616 bytes to dma_free_coherent(),
> triggering DMA-API debug size-mismatch warnings on teardown.
>
> Extract a shared fun_stats_area_size() helper used by both allocation and
> deallocation paths, and cast the leading enum constant to unsigned int to
> avoid cross-enum arithmetic.
>
> Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
> -Wenum-enum-conversion enabled; fix and changelog drafted with an AI
> coding assistant. Build-tested under LLVM=1 W=1 and
> -Wenum-enum-conversion; not tested on Fungible Ethernet hardware.
>
> Fixes: ee6373ddf3a9 ("net/funeth: probing and netdev ops")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> .../ethernet/fungible/funeth/funeth_main.c | 20 +++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/ethernet/fungible/funeth/funeth_main.c b/drivers/net/ethernet/fungible/funeth/funeth_main.c
> index bad8276d26b0..e0d4e69abfa4 100644
> --- a/drivers/net/ethernet/fungible/funeth/funeth_main.c
> +++ b/drivers/net/ethernet/fungible/funeth/funeth_main.c
> @@ -1457,17 +1457,20 @@ void fun_set_ring_count(struct net_device *netdev, unsigned int ntx,
> }
> }
>
> -static int fun_init_stats_area(struct funeth_priv *fp)
> +static size_t fun_stats_area_size(void)
> {
> - unsigned int nstats;
> + unsigned int nstats = (unsigned int)PORT_MAC_RX_STATS_MAX +
> + PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX;
> +
> + return nstats * sizeof(u64);
> +}
>
> +static int fun_init_stats_area(struct funeth_priv *fp)
> +{
> if (!(fp->port_caps & FUN_PORT_CAP_STATS))
> return 0;
>
> - nstats = PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX +
> - PORT_MAC_FEC_STATS_MAX;
> -
> - fp->stats = dma_alloc_coherent(&fp->pdev->dev, nstats * sizeof(u64),
> + fp->stats = dma_alloc_coherent(&fp->pdev->dev, fun_stats_area_size(),
> &fp->stats_dma_addr, GFP_KERNEL);
> if (!fp->stats)
> return -ENOMEM;
> @@ -1476,11 +1479,8 @@ static int fun_init_stats_area(struct funeth_priv *fp)
>
> static void fun_free_stats_area(struct funeth_priv *fp)
> {
> - unsigned int nstats;
> -
> if (fp->stats) {
> - nstats = PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX;
> - dma_free_coherent(&fp->pdev->dev, nstats * sizeof(u64),
> + dma_free_coherent(&fp->pdev->dev, fun_stats_area_size(),
> fp->stats, fp->stats_dma_addr);
> fp->stats = NULL;
> }
> --
> 2.56.1.708.g77570a6a1d-goog
>
Fix looks good to me.
Although, I think it's more common with a compile time constant for a fixed size
used for alloc and free. Something like:
#define FUN_PORT_NSTATS ((unsigned int)PORT_MAC_RX_STATS_MAX + \
PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX)
fp->stats = dma_alloc_coherent(&fp->pdev->dev,
FUN_PORT_NSTATS * sizeof(u64),
&fp->stats_dma_addr, GFP_KERNEL);
Not a big deal though.
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] eth: funeth: Include FEC stats in fun_free_stats_area() DMA free size
2026-11-23 9:07 ` Daniel Machon
@ 2026-11-25 15:48 ` Paolo Abeni
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Abeni @ 2026-11-25 15:48 UTC (permalink / raw)
To: Daniel Machon, Ian Rogers
Cc: Dimitris Michailidis, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, netdev, linux-kernel, llvm, Elkin Cruz
On 11/23/26 10:07, Daniel Machon wrote:
>> fun_init_stats_area() allocates coherent DMA memory for
>> (PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX)
>> 64-bit counters (632 bytes), whereas fun_free_stats_area() omits
>> PORT_MAC_FEC_STATS_MAX and passes 616 bytes to dma_free_coherent(),
>> triggering DMA-API debug size-mismatch warnings on teardown.
>>
>> Extract a shared fun_stats_area_size() helper used by both allocation and
>> deallocation paths, and cast the leading enum constant to unsigned int to
>> avoid cross-enum arithmetic.
>>
>> Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
>> -Wenum-enum-conversion enabled; fix and changelog drafted with an AI
>> coding assistant. Build-tested under LLVM=1 W=1 and
>> -Wenum-enum-conversion; not tested on Fungible Ethernet hardware.
>>
>> Fixes: ee6373ddf3a9 ("net/funeth: probing and netdev ops")
>> Signed-off-by: Ian Rogers <irogers@google.com>
>> ---
>> .../ethernet/fungible/funeth/funeth_main.c | 20 +++++++++----------
>> 1 file changed, 10 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/fungible/funeth/funeth_main.c b/drivers/net/ethernet/fungible/funeth/funeth_main.c
>> index bad8276d26b0..e0d4e69abfa4 100644
>> --- a/drivers/net/ethernet/fungible/funeth/funeth_main.c
>> +++ b/drivers/net/ethernet/fungible/funeth/funeth_main.c
>> @@ -1457,17 +1457,20 @@ void fun_set_ring_count(struct net_device *netdev, unsigned int ntx,
>> }
>> }
>>
>> -static int fun_init_stats_area(struct funeth_priv *fp)
>> +static size_t fun_stats_area_size(void)
>> {
>> - unsigned int nstats;
>> + unsigned int nstats = (unsigned int)PORT_MAC_RX_STATS_MAX +
>> + PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX;
>> +
>> + return nstats * sizeof(u64);
>> +}
>>
>> +static int fun_init_stats_area(struct funeth_priv *fp)
>> +{
>> if (!(fp->port_caps & FUN_PORT_CAP_STATS))
>> return 0;
>>
>> - nstats = PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX +
>> - PORT_MAC_FEC_STATS_MAX;
>> -
>> - fp->stats = dma_alloc_coherent(&fp->pdev->dev, nstats * sizeof(u64),
>> + fp->stats = dma_alloc_coherent(&fp->pdev->dev, fun_stats_area_size(),
>> &fp->stats_dma_addr, GFP_KERNEL);
>> if (!fp->stats)
>> return -ENOMEM;
>> @@ -1476,11 +1479,8 @@ static int fun_init_stats_area(struct funeth_priv *fp)
>>
>> static void fun_free_stats_area(struct funeth_priv *fp)
>> {
>> - unsigned int nstats;
>> -
>> if (fp->stats) {
>> - nstats = PORT_MAC_RX_STATS_MAX + PORT_MAC_TX_STATS_MAX;
>> - dma_free_coherent(&fp->pdev->dev, nstats * sizeof(u64),
>> + dma_free_coherent(&fp->pdev->dev, fun_stats_area_size(),
>> fp->stats, fp->stats_dma_addr);
>> fp->stats = NULL;
>> }
>> --
>> 2.56.1.708.g77570a6a1d-goog
>>
>
> Fix looks good to me.
>
> Although, I think it's more common with a compile time constant for a fixed size
> used for alloc and free. Something like:
>
> #define FUN_PORT_NSTATS ((unsigned int)PORT_MAC_RX_STATS_MAX + \
> PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX)
>
> fp->stats = dma_alloc_coherent(&fp->pdev->dev,
> FUN_PORT_NSTATS * sizeof(u64),
> &fp->stats_dma_addr, GFP_KERNEL);
>
> Not a big deal though.
Please use the macro, as suggested by Daniel. Also please wait a few
days before resubmitting.
/P
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 15:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:06 [PATCH net] eth: funeth: Include FEC stats in fun_free_stats_area() DMA free size Ian Rogers
2026-11-23 9:07 ` Daniel Machon
2026-11-25 15:48 ` Paolo Abeni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®