[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20260122100527.527027-1-zilin@seu.edu.cn>
Date: Thu, 22 Jan 2026 10:05:27 +0000
From: Zilin Guan <zilin@....edu.cn>
To: pavan.chebbi@...adcom.com
Cc: andrew+netdev@...n.ch,
davem@...emloft.net,
edumazet@...gle.com,
jianhao.xu@....edu.cn,
kuba@...nel.org,
linux-kernel@...r.kernel.org,
michael.chan@...adcom.com,
netdev@...r.kernel.org,
pabeni@...hat.com,
zilin@....edu.cn
Subject: Re: [PATCH net] bnxt_en: Fix memory leak in bnxt_alloc_mem()
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@....edu.cn> 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().
Hi Pavan,
Thank you for your review and clarification.
I observed that most allocation failure paths in bnxt_alloc_mem() jump to
alloc_mem_err for error handling, which led me to incorrectly assume that
this function was strictly responsible for cleaning up its own allocated
memory upon failure. I failed to realize that the caller also handles the
cleanup for these specific cases.
Thanks for pointing this out. Sorry for the noise.
Best regards,
Zilin Guan
Powered by blists - more mailing lists