[PATCH net v2] octeontx2-af: Fix BPID leak in nix_bp_enable()

From: nshettyj

Date: Wed Sep 09 2026 - 23:16:41 EST


From: Rakesh Kudurumalla <rkudurumalla@xxxxxxxxxxx>

For LBK interfaces, rvu_nix_get_bpid() allocates a BPID from the free
pool on every call. nix_bp_enable() called it unconditionally before
the loop, and again after the last channel was programmed, leaking a
BPID whenever that extra call's result went unused. With
req->chan_cnt == 0, the pre-loop call leaked a BPID on every call.

Move the allocation into the loop body so it runs exactly once per
channel actually programmed, and reject req->chan_cnt == 0 upfront.

Fixes: d6212d2e41a0 ("octeontx2-af: Create BPIDs free pool")
Signed-off-by: Nitin Shetty J <nshettyj@xxxxxxxxxxx>
Signed-off-by: Rakesh Kudurumalla <rkudurumalla@xxxxxxxxxxx>
---
changes in v2:
- Move the rvu_nix_get_bpid() call for LBK BPID allocation from before
the loop into the loop body.
- Validate req->chan_cnt before allocating BPIDs.
- updated commit message and fix tag
---
drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
index 153eb57bad06..3a43432d29c1 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c
@@ -764,19 +764,25 @@ static int nix_bp_enable(struct rvu *rvu,
if (cpt_link && !rvu->hw->cpt_links)
return 0;

+ if (!req->chan_cnt)
+ return NIX_AF_ERR_INVALID_BPID_REQ;
+
pfvf = rvu_get_pfvf(rvu, pcifunc);
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NIX, pcifunc);

- bpid_base = rvu_nix_get_bpid(rvu, req, type, chan_id);
chan_base = pfvf->rx_chan_base + req->chan_base;
- bpid = bpid_base;
+ bpid_base = -1;

for (chan = chan_base; chan < (chan_base + req->chan_cnt); chan++) {
+ bpid = rvu_nix_get_bpid(rvu, req, type, chan_id);
if (bpid < 0) {
dev_warn(rvu->dev, "Fail to enable backpressure\n");
return -EINVAL;
}

+ if (bpid_base < 0)
+ bpid_base = bpid;
+
chan_v = nix_get_channel(chan, cpt_link);

cfg = rvu_read64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v));
@@ -784,7 +790,6 @@ static int nix_bp_enable(struct rvu *rvu,
rvu_write64(rvu, blkaddr, NIX_AF_RX_CHANX_CFG(chan_v),
cfg | (bpid & GENMASK_ULL(8, 0)) | BIT_ULL(16));
chan_id++;
- bpid = rvu_nix_get_bpid(rvu, req, type, chan_id);
}

for (chan = 0; chan < req->chan_cnt; chan++) {
--
2.48.1