Skip to contentSkip to conversation

bnxt: fix memory leak in bnxt_queue_mem_alloc error cases

PATCH Superseded Will Chen 3 participants 4 messages Jul 28 – Jul 29

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Will Chen

author
#0 lore raw

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.

Fixes bd649c5cc958 ("bnxt_en: handle tpa_info in queue API implementation")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -0
index 7513618793da..c30507dd824e 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Will Chen

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 theerr_free_tpa_info case, as this is the only remaining error path where rx_agg_bmap is allocated and needs to be freed.

Quoted 6 lines
Fixes bd649c5cc958 ("bnxt_en: handle tpa_info in queue API implementation")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++
 1 file changed, 2 insertions(+)
maintainer
#2 lore raw
In reply to Will Chen
Quoted 22 lines · Will Chen

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.

Fixes bd649c5cc958 ("bnxt_en: handle tpa_info in queue API implementation")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index 7513618793da..c30507dd824e 100644

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 -0
 err_free_rx_agg_ring:
        bnxt_free_ring(bp, &clone->rx_agg_ring_struct.ring_mem);
 err_free_rx_ring:
author
#3 lore raw

Thanks for the feedback, will apply these changes in upcoming v2.