Re: [PATCH net] bnxt_en: Fix memory leak in bnxt_alloc_mem()
From: Leon Romanovsky
Date: Mon Jan 26 2026 - 05:10:09 EST
On Thu, Jan 22, 2026 at 03:14:08PM +0530, Pavan Chebbi wrote:
> On Thu, Jan 22, 2026 at 2:56 PM Zilin Guan <zilin@xxxxxxxxxx> wrote:
> >
> > In bnxt_alloc_mem(), the function allocates memory for bp->bnapi,
> > bp->rx_ring, bp->tx_ring, and bp->tx_ring_map.
> >
> > However, if the allocation for rx_ring, tx_ring, or tx_ring_map fails, the
> > function currently returns -ENOMEM directly without freeing the previously
> > allocated memory. This leads to a memory leak.
> >
> > Fix this by jumping to the alloc_mem_err label when allocation fails,
> > which ensures that bnxt_free_mem() is called to properly release all
> > allocated resources.
>
> This fix is not needed. The memory is freed by the caller of bnxt_alloc_mem().
That is an anti-pattern as well. On error, the function should clean up
all resources it allocated.
Thanks