bnxt: fix memory leak in bnxt_queue_mem_alloc error cases
PATCH 1/1 bnxt: fix memory leak in bnxt_queue_mem_alloc error cases
There is a small memory leak in bnxt_queue_mem_alloc:
when bnxt_alloc_rx_agg_bmap() succeeds
but bnxt_alloc_one_tpa_info() later fails, the rx_agg_bmap allocated by bnxt_alloc_rx_agg_bmap() is not freed in the fallthrough cleanup cases.
Simply free the rx_agg_bmap in the err_free_tpa_info case, as this is the only remaining error path where rx_agg_bmap is allocated and needs to be freed.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -0
@@ -16267,6 +16267,8 @@ static int bnxt_queue_mem_alloc(struct net_device *dev, err_free_tpa_info:bnxt_free_one_tpa_info (bp, clone); +kfree (clone->rx_agg_bmap); + clone->rx_agg_bmap =NULL ; err_free_rx_agg_ring:bnxt_free_ring (bp, &clone->rx_agg_ring_struct.ring_mem); err_free_rx_ring:
base-commit: 3f1f755366687d051174739fb99f7d560202f60b
Signature · 1 line
2.53.0-Meta
Quoted 10 lines · Will Chen
There is a small memory leak in
bnxt_queue_mem_alloc:
whenbnxt_alloc_rx_agg_bmap()succeeds
butbnxt_alloc_one_tpa_info()later fails, therx_agg_bmapallocated bybnxt_alloc_rx_agg_bmap()is not freed in the fallthrough cleanup cases.Simply free the
rx_agg_bmapintheerr_free_tpa_infocase, as this is the only remaining error path whererx_agg_bmapis allocated and needs to be freed.
Quoted 6 lines
Fixes bd649c5cc958 ("bnxt_en: handle tpa_info in queue API implementation")Signed-off-by Will Chen <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++ 1 file changed, 2 insertions(+)
Michael Chan
maintainerQuoted 22 lines · Will Chen
There is a small memory leak in
bnxt_queue_mem_alloc:
whenbnxt_alloc_rx_agg_bmap()succeeds
butbnxt_alloc_one_tpa_info()later fails, therx_agg_bmapallocated bybnxt_alloc_rx_agg_bmap()is not freed in the fallthrough cleanup cases.Simply free the
rx_agg_bmapin theerr_free_tpa_infocase, as this is the only remaining error path whererx_agg_bmapis allocated and needs to be freed.Fixes bd649c5cc958 ("bnxt_en: handle tpa_info in queue API implementation")Signed-off-by Will Chen <[email protected]>--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++ 1 file changed, 2 insertions(+)drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0
drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_queue_mem_alloc(struct net_device *dev, · line 16271
Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2
-0@@ -16267,6 +16267,8 @@ static int bnxt_queue_mem_alloc(struct net_device *dev, err_free_tpa_info:bnxt_free_one_tpa_info (bp, clone); +kfree (clone->rx_agg_bmap); + clone->rx_agg_bmap =NULL ;
I think logically, these 2 lines should be moved below under err_free_rx_agg_ring because it is memory related to the agg ring. We may need to initialize clone->rx_agg_bmap = NULL near the top of the function to be more complete. Thanks.
Quoted 4 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0
-0err_free_rx_agg_ring:bnxt_free_ring (bp, &clone->rx_agg_ring_struct.ring_mem); err_free_rx_ring:
Thanks for the feedback, will apply these changes in upcoming v2.