Skip to contentSkip to conversation

scsi: Fix two possible memory leaks

PATCH Applied Zhen Lei 2 participants 4 messages Oct 26, 2024 – Nov 14, 2024

Subsystems (3)
lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

cover scsi: Fix two possible memory leaks

When "ops->common->sb_init = qed_sb_init" fails, the DMA memory needs to be explicitly released.

Zhen Lei (2):
scsi: qedf: Fix a possible memory leak in qedf_alloc_and_init_sb()
scsi: qedi: Fix a possible memory leak in qedi_alloc_and_init_sb()

 drivers/scsi/qedf/qedf_main.c | 1 +
 drivers/scsi/qedi/qedi_main.c | 1 +
 2 files changed, 2 insertions(+)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 scsi: qedf: Fix a possible memory leak in qedf_alloc_and_init_sb()

Hook "qed_ops->common->sb_init = qed_sb_init" does not release the dma memory sb_virt when it fails. Add dma_free_coherent() to free it. This is the same way as qedr_alloc_mem_sb() and qede_alloc_mem_sb().

Fixes 61d8658b4a43 ("scsi: qedf: Add QLogic FastLinQ offload FCoE driver framework.")
---
 drivers/scsi/qedf/qedf_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/qedf/qedf_main.c +1 -0
index cf13148ba281c1e..e979ec1478c1844 100644
@@ -2738,6 +2738,7 @@ static int qedf_alloc_and_init_sb(struct qedf_ctx *qedf,
 	    sb_id, QED_SB_TYPE_STORAGE);
 
 	if (ret) {
+		dma_free_coherent(&qedf->pdev->dev, sizeof(*sb_virt), sb_virt, sb_phys);
 		QEDF_ERR(&qedf->dbg_ctx,
 			 "Status block initialization failed (0x%x) for id = %d.\n",
 			 ret, sb_id);
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 scsi: qedi: Fix a possible memory leak in qedi_alloc_and_init_sb()

In reply to Zhen Lei

Hook "qedi_ops->common->sb_init = qed_sb_init" does not release the dma memory sb_virt when it fails. Add dma_free_coherent() to free it. This is the same way as qedr_alloc_mem_sb() and qede_alloc_mem_sb().

Fixes ace7f46ba5fd ("scsi: qedi: Add QLogic FastLinQ offload iSCSI driver framework.")
---
 drivers/scsi/qedi/qedi_main.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/qedi/qedi_main.c +1 -0
index c5aec26019d6abe..628d59dda20cc40 100644
@@ -369,6 +369,7 @@ static int qedi_alloc_and_init_sb(struct qedi_ctx *qedi,
 	ret = qedi_ops->common->sb_init(qedi->cdev, sb_info, sb_virt, sb_phys,
 				       sb_id, QED_SB_TYPE_STORAGE);
 	if (ret) {
+		dma_free_coherent(&qedi->pdev->dev, sizeof(*sb_virt), sb_virt, sb_phys);
 		QEDI_ERR(&qedi->dbg_ctx,
 			 "Status block initialization failed for id = %d.\n",
 			  sb_id);
Signature · 1 line
2.34.1
#3 lore raw
In reply to Zhen Lei
Quoted 8 lines · Zhen Lei

When "ops->common->sb_init = qed_sb_init" fails, the DMA memory needs to be explicitly released.

Zhen Lei (2):
scsi: qedf: Fix a possible memory leak in qedf_alloc_and_init_sb()
scsi: qedi: Fix a possible memory leak in qedi_alloc_and_init_sb()

[...]

Applied to 6.13/scsi-queue, thanks!

[1/2] scsi: qedf: Fix a possible memory leak in qedf_alloc_and_init_sb()

      https://git.kernel.org/mkp/scsi/c/c62c30429db3
[2/2] scsi: qedi: Fix a possible memory leak in qedi_alloc_and_init_sb()
      https://git.kernel.org/mkp/scsi/c/95bbdca4999b
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering