Re: [PATCH] net: lan969x: fix page pool leak when RX DMA allocation fails
From: Daniel Machon
Date: Tue Nov 03 2026 - 07:36:08 EST
Hi Wentao,
> lan969x_fdma_rx_alloc() creates the RX page pool and then allocates the
> FDMA coherent memory. If fdma_alloc_coherent() fails, the function
> returns without destroying the page pool.
>
> The failure propagates out of lan969x_fdma_init(), and
> sparx5_frame_io_init() then marks the FDMA IRQ as unavailable, so
> lan969x_fdma_deinit() is never called on teardown and the page pool is
> never released. Destroy it before returning the error.
>
> Fixes: d84ad2c0d80c ("net: lan969x: add FDMA implementation")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
> Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
> ---
> drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c
> index 053d125eda65..bc293ba1707d 100644
> --- a/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c
> +++ b/drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_fdma.c
> @@ -169,8 +169,10 @@ static int lan969x_fdma_rx_alloc(struct sparx5 *sparx5)
> return PTR_ERR(rx->page_pool);
>
> err = fdma_alloc_coherent(sparx5->dev, fdma);
> - if (err)
> + if (err) {
> + page_pool_destroy(rx->page_pool);
> return err;
> + }
>
> fdma_dcbs_init(fdma,
> FDMA_DCB_INFO_DATAL(fdma->db_size),
> --
> 2.34.1
>
Thanks. The leak is real, but this init path has another problem
of the same kind:
- If lan969x_fdma_tx_alloc() fails, lan969x_fdma_init() only frees
the RX coherent memory. The page pool and the RX pages that
fdma_dcbs_init() already took from it are leaked, for the same
reason you describe.
All of this has been there since the FDMA implementation was added, and only
triggers on allocation failures at probe. I have a net-next series for
MTU-dependent RX buffer sizes coming up (very soon, within days) that reworks
this exact code and its error unwind, so I'll fix this (and other related
issues) there.
I'd suggest dropping this one.
pw-bot: rejected
/Daniel