[PATCH net v2] eth: funeth: Include FEC stats in fun_free_stats_area() DMA free size

From: Ian Rogers

Date: Thu Dec 03 2026 - 12:01:37 EST


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 a CONFIG_DMA_API_DEBUG size-mismatch warning on teardown.

Define a shared FUN_PORT_NSTATS macro (casting the first enum constant
to unsigned int to avoid cross-enum arithmetic) and use it in both
fun_init_stats_area() and fun_free_stats_area().

Found with Clang's -Wenum-enum-conversion on an x86_64 allyesconfig
build and confirmed by reading both functions; Gemini helped triage the
warning and draft the patch and commit message. The issue was not
triggered at runtime and the fix is compile-tested only (LLVM=1 W=1
-Werror and -Wenum-enum-conversion) because Fungible Ethernet hardware
is not available.

Fixes: ee6373ddf3a9 ("net/funeth: probing and netdev ops")
Suggested-by: Daniel Machon <daniel.machon@xxxxxxxxxxxxx>
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---

Notes:
v2:
- Replace the fun_stats_area_size() helper with a compile-time
FUN_PORT_NSTATS macro (Daniel Machon, Paolo Abeni).

v1: https://lore.kernel.org/r/20261119170613.1519353-1-irogers@xxxxxxxxxx

.../net/ethernet/fungible/funeth/funeth_main.c | 17 +++++++----------
1 file changed, 7 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..39cfe4f694d2 100644
--- a/drivers/net/ethernet/fungible/funeth/funeth_main.c
+++ b/drivers/net/ethernet/fungible/funeth/funeth_main.c
@@ -1457,17 +1457,16 @@ void fun_set_ring_count(struct net_device *netdev, unsigned int ntx,
}
}

+#define FUN_PORT_NSTATS ((unsigned int)PORT_MAC_RX_STATS_MAX + \
+ PORT_MAC_TX_STATS_MAX + PORT_MAC_FEC_STATS_MAX)
+
static int fun_init_stats_area(struct funeth_priv *fp)
{
- unsigned int nstats;
-
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_PORT_NSTATS * sizeof(u64),
&fp->stats_dma_addr, GFP_KERNEL);
if (!fp->stats)
return -ENOMEM;
@@ -1476,11 +1475,9 @@ 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_PORT_NSTATS * sizeof(u64),
fp->stats, fp->stats_dma_addr);
fp->stats = NULL;
}
--
2.56.1.911.g883d8bcb20-goog