octeontx2-af: CGX: fix bitmap leaks
PATCH 1/1 octeontx2-af: CGX: fix bitmap leaks
In reply to Bo SunThe 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.
--- drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 2 ++ 1 file changed, 2 insertions(+)
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); }
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(+)
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_bmapandtx_fc_pfvf_bmap) are allocated bycgx_lmac_init()but never freed incgx_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")Signed-off-by Bo Sun <[email protected]>
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
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
Jakub Kicinski
maintainerQuoted 9 lines · On Mon, 20 Oct 2025 22:31:12 +0800 Bo Sun wrote:
The RX/TX flow-control bitmaps (
rx_fc_pfvf_bmapandtx_fc_pfvf_bmap) are allocated bycgx_lmac_init()but never freed incgx_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")Signed-off-by Bo Sun <[email protected]>
Looks like rvu_free_bitmap() exists. We should probably use it?
Quoted 13 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); }
Signature · 1 line
pw-bot: cr
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_bmapandtx_fc_pfvf_bmap) are allocated bycgx_lmac_init()but never freed incgx_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")Signed-off-by Bo Sun <[email protected]>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@@ -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); }
Jakub Kicinski
maintainerQuoted 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")Signed-off-by Bo Sun <[email protected]>Looks like
rvu_free_bitmap()exists. We should probably use it?Apologies for the late reply.
You're right thatrvu_free_bitmap()exists. I stayed with directkfree()for consistency with the existing code incgx_lmac_exit(), because which already useskfree(lmac->mac_to_index_bmap.bmap).
Quoted 6 lines
That said, I'm OK with either way:
1. Keepkfree()to match the existing pattern in this function
2. Switch all three bitmap frees (includingmac_to_index_bmap) to uservu_free_bitmap()for consistency with the alloc/free API pairingWhat'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.
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")Signed-off-by Bo Sun <[email protected]>Looks like
rvu_free_bitmap()exists. We should probably use it?Apologies for the late reply.
You're right thatrvu_free_bitmap()exists. I stayed with directkfree()for consistency with the existing code incgx_lmac_exit(), because which already useskfree(lmac->mac_to_index_bmap.bmap).That said, I'm OK with either way:
1. Keepkfree()to match the existing pattern in this function
2. Switch all three bitmap frees (includingmac_to_index_bmap) to uservu_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 fromkfree()torvu_free_bitmap(). We want the fix itself to be small, the cleanup should be separate.
Thanks, I'll send v2.