Skip to contentSkip to conversation

octeontx2-af: CGX: fix bitmap leaks

PATCH Superseded Bo Sun 3 participants 7 messages Oct 20, 2025 – Feb 6

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/1 octeontx2-af: CGX: fix bitmap leaks

In reply to Bo Sun

The RX/TX flow-control bitmaps (rx_fc_pfvf_bmap and tx_fc_pfvf_bmap) are allocated by cgx_lmac_init() but never freed in cgx_lmac_exit(). Unbinding and rebinding the driver therefore triggers kmemleak:

unreferenced object (size 16):
backtrace:
rvu_alloc_bitmap
cgx_probe

Free both bitmaps during teardown.

Fixes e740003874ed ("octeontx2-af: Flow control resource management")
---
 drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +2 -0
index ec0e11c77cbf..f56e6782c4de 100644
@@ -1823,6 +1823,8 @@ static int cgx_lmac_exit(struct cgx *cgx)
 		cgx->mac_ops->mac_pause_frm_config(cgx, lmac->lmac_id, false);
 		cgx_configure_interrupt(cgx, lmac, lmac->lmac_id, true);
 		kfree(lmac->mac_to_index_bmap.bmap);
+		kfree(lmac->rx_fc_pfvf_bmap.bmap);
+		kfree(lmac->tx_fc_pfvf_bmap.bmap);
 		kfree(lmac->name);
 		kfree(lmac);
 	}

Bo Sun

author
#0 lore raw

cover octeontx2-af: CGX: fix bitmap leaks

This patch frees the RX/TX flow-control bitmaps in cgx_lmac_exit(). The leak was introduced in commit e740003874ed ("octeontx2-af:Flow control resource management") and should be back-ported to stable.

Bo Sun (1):
octeontx2-af: CGX: fix bitmap leaks

 drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 2 ++
 1 file changed, 2 insertions(+)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Bo Sun

From: Bo Sun <[email protected]>
Date: Mon, 20 Oct 2025 22:31:12 +0800

Quoted 9 lines

The RX/TX flow-control bitmaps (rx_fc_pfvf_bmap and tx_fc_pfvf_bmap) are allocated by cgx_lmac_init() but never freed in cgx_lmac_exit(). Unbinding and rebinding the driver therefore triggers kmemleak:

unreferenced object (size 16):
backtrace:
rvu_alloc_bitmap
cgx_probe

Quoted 5 lines

Free both bitmaps during teardown.

Fixes e740003874ed ("octeontx2-af: Flow control resource management")
Quoted 9 lines
---
 drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +0 -0
index ec0e11c77cbf..f56e6782c4de 100644

drivers/net/ethernet/marvell/octeontx2/af/cgx.c static int cgx_lmac_exit(struct cgx *cgx) · line 1830

Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +2 -0
@@ -1823,6 +1823,8 @@ static int cgx_lmac_exit(struct cgx *cgx)
 		cgx->mac_ops->mac_pause_frm_config(cgx, lmac->lmac_id, false);
 		cgx_configure_interrupt(cgx, lmac, lmac->lmac_id, true);
 		kfree(lmac->mac_to_index_bmap.bmap);
+		kfree(lmac->rx_fc_pfvf_bmap.bmap);
+		kfree(lmac->tx_fc_pfvf_bmap.bmap);
 		kfree(lmac->name);
 		kfree(lmac);
 	}

Thanks,
Olek

maintainer
#3 lore raw
In reply to Bo Sun
Quoted 9 lines · On Mon, 20 Oct 2025 22:31:12 +0800 Bo Sun wrote:

The RX/TX flow-control bitmaps (rx_fc_pfvf_bmap and tx_fc_pfvf_bmap) are allocated by cgx_lmac_init() but never freed in cgx_lmac_exit(). Unbinding and rebinding the driver therefore triggers kmemleak:

unreferenced object (size 16):
backtrace:
rvu_alloc_bitmap
cgx_probe

Quoted 5 lines

Free both bitmaps during teardown.

Fixes e740003874ed ("octeontx2-af: Flow control resource management")

Looks like rvu_free_bitmap() exists. We should probably use it?

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +2 -0
index ec0e11c77cbf..f56e6782c4de 100644
@@ -1823,6 +1823,8 @@ static int cgx_lmac_exit(struct cgx *cgx)
 		cgx->mac_ops->mac_pause_frm_config(cgx, lmac->lmac_id, false);
 		cgx_configure_interrupt(cgx, lmac, lmac->lmac_id, true);
 		kfree(lmac->mac_to_index_bmap.bmap);
+		kfree(lmac->rx_fc_pfvf_bmap.bmap);
+		kfree(lmac->tx_fc_pfvf_bmap.bmap);
 		kfree(lmac->name);
 		kfree(lmac);
 	}
Signature · 1 line
pw-bot: cr
author
#4 lore raw
Quoted 10 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 20 Oct 2025 22:31:12 +0800 Bo Sun wrote:

The RX/TX flow-control bitmaps (rx_fc_pfvf_bmap and tx_fc_pfvf_bmap) are allocated by cgx_lmac_init() but never freed in cgx_lmac_exit(). Unbinding and rebinding the driver therefore triggers kmemleak:

unreferenced object (size 16):
backtrace:
rvu_alloc_bitmap
cgx_probe

Quoted 7 lines
Quoted 5 lines

Free both bitmaps during teardown.

Fixes e740003874ed ("octeontx2-af: Flow control resource management")

Looks like rvu_free_bitmap() exists. We should probably use it?

Apologies for the late reply.
You're right that rvu_free_bitmap() exists. I stayed with direct kfree() for consistency with the existing code in cgx_lmac_exit(), because which already uses kfree(lmac->mac_to_index_bmap.bmap).

That said, I'm OK with either way:
1. Keep kfree() to match the existing pattern in this function
2. Switch all three bitmap frees (including mac_to_index_bmap) to use rvu_free_bitmap() for consistency with the alloc/free API pairing

What's your preference?

Thanks,
Bo

Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/marvell/octeontx2/af/cgx.c +2 -0
index ec0e11c77cbf..f56e6782c4de 100644
@@ -1823,6 +1823,8 @@ static int cgx_lmac_exit(struct cgx *cgx)
  		cgx->mac_ops->mac_pause_frm_config(cgx, lmac->lmac_id, false);
  		cgx_configure_interrupt(cgx, lmac, lmac->lmac_id, true);
  		kfree(lmac->mac_to_index_bmap.bmap);
+		kfree(lmac->rx_fc_pfvf_bmap.bmap);
+		kfree(lmac->tx_fc_pfvf_bmap.bmap);
  		kfree(lmac->name);
  		kfree(lmac);
  	}
maintainer
#5 lore raw
Quoted 11 lines · On Thu, 5 Feb 2026 21:35:29 +0800 Bo Sun wrote:
Quoted 5 lines
Quoted 3 lines
Fixes e740003874ed ("octeontx2-af: Flow control resource management")

Looks like rvu_free_bitmap() exists. We should probably use it?

Apologies for the late reply.
You're right that rvu_free_bitmap() exists. I stayed with direct kfree() for consistency with the existing code in cgx_lmac_exit(), because which already uses kfree(lmac->mac_to_index_bmap.bmap).

Quoted 6 lines

That said, I'm OK with either way:
1. Keep kfree() to match the existing pattern in this function
2. Switch all three bitmap frees (including mac_to_index_bmap) to use rvu_free_bitmap() for consistency with the alloc/free API pairing

What's your preference?

3. do what I implied, just use rvu_free_bitmap() in this single case for the fix. Follow up separately with a patch to remaining sites if any to convert from kfree() to rvu_free_bitmap(). We want the fix itself to be small, the cleanup should be separate.

#6 lore raw
Quoted 17 lines · Jakub Kicinski
Quoted 16 lines · On Thu, 5 Feb 2026 21:35:29 +0800 Bo Sun wrote:
Quoted 5 lines
Quoted 3 lines
Fixes e740003874ed ("octeontx2-af: Flow control resource management")

Looks like rvu_free_bitmap() exists. We should probably use it?

Apologies for the late reply.
You're right that rvu_free_bitmap() exists. I stayed with direct kfree() for consistency with the existing code in cgx_lmac_exit(), because which already uses kfree(lmac->mac_to_index_bmap.bmap).

That said, I'm OK with either way:
1. Keep kfree() to match the existing pattern in this function
2. Switch all three bitmap frees (including mac_to_index_bmap) to use rvu_free_bitmap() for consistency with the alloc/free API pairing

Quoted 6 lines
Quoted 1 line

What's your preference?

3. do what I implied, just use rvu_free_bitmap() in this single case for the fix. Follow up separately with a patch to remaining sites if any to convert from kfree() to rvu_free_bitmap(). We want the fix itself to be small, the cleanup should be separate.

Thanks, I'll send v2.