[PATCH] scsi: bnx2fc: unmap DMA mappings when BD count exceeds firmware limit

From: Haoxiang Li

Date: Wed May 27 2026 - 04:03:54 EST


bnx2fc_build_bd_list_from_sg() maps the SCSI SG list before checking
whether the generated BD count exceeds the firmware limit. If the limit
check fails, the function returns an error without unmapping the DMA
mapping.

Unmap the SG list before returning the error.

Fixes: 3c97b569505f ("scsi: bnx2fc: Limit the IO size according to the FW capability")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Haoxiang Li <lihaoxiang@xxxxxxxxxxxxxxxx>
---
drivers/scsi/bnx2fc/bnx2fc_io.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 33057908f147..5429f127c5b8 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1718,6 +1718,7 @@ static int bnx2fc_build_bd_list_from_sg(struct bnx2fc_cmd *io_req)
if (bd_count > BNX2FC_FW_MAX_BDS_PER_CMD) {
pr_err("bd_count = %d exceeded FW supported max BD(255), task_id = 0x%x\n",
bd_count, io_req->xid);
+ bnx2fc_unmap_sg_list(io_req);
return -ENOMEM;
}

--
2.25.1