Skip to content

Commit 26fa656

Browse files
bkstratusmartinkpetersen
authored andcommitted
scsi: qla2xxx: Fix gnl.l memory leak on adapter init failure
If HBA initialization fails unexpectedly (exiting via probe_failed:), we may fail to free vha->gnl.l. So that we don't attempt to double free, set this pointer to NULL after a free and check for NULL at probe_failed: so we know whether or not to call dma_free_coherent. Signed-off-by: Bill Kuzeja <[email protected]> Acked-by: Himanshu Madhani <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent a86c71b commit 26fa656

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

drivers/scsi/qla2xxx/qla_attr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,8 @@ qla24xx_vport_delete(struct fc_vport *fc_vport)
29562956
dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
29572957
vha->gnl.ldma);
29582958

2959+
vha->gnl.l = NULL;
2960+
29592961
vfree(vha->scan.l);
29602962

29612963
if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {

drivers/scsi/qla2xxx/qla_os.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,12 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
34403440
return 0;
34413441

34423442
probe_failed:
3443+
if (base_vha->gnl.l) {
3444+
dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
3445+
base_vha->gnl.l, base_vha->gnl.ldma);
3446+
base_vha->gnl.l = NULL;
3447+
}
3448+
34433449
if (base_vha->timer_active)
34443450
qla2x00_stop_timer(base_vha);
34453451
base_vha->flags.online = 0;
@@ -3673,7 +3679,7 @@ qla2x00_remove_one(struct pci_dev *pdev)
36733679
if (!atomic_read(&pdev->enable_cnt)) {
36743680
dma_free_coherent(&ha->pdev->dev, base_vha->gnl.size,
36753681
base_vha->gnl.l, base_vha->gnl.ldma);
3676-
3682+
base_vha->gnl.l = NULL;
36773683
scsi_host_put(base_vha->host);
36783684
kfree(ha);
36793685
pci_set_drvdata(pdev, NULL);
@@ -3713,6 +3719,8 @@ qla2x00_remove_one(struct pci_dev *pdev)
37133719
dma_free_coherent(&ha->pdev->dev,
37143720
base_vha->gnl.size, base_vha->gnl.l, base_vha->gnl.ldma);
37153721

3722+
base_vha->gnl.l = NULL;
3723+
37163724
vfree(base_vha->scan.l);
37173725

37183726
if (IS_QLAFX00(ha))
@@ -4816,6 +4824,7 @@ struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
48164824
"Alloc failed for scan database.\n");
48174825
dma_free_coherent(&ha->pdev->dev, vha->gnl.size,
48184826
vha->gnl.l, vha->gnl.ldma);
4827+
vha->gnl.l = NULL;
48194828
scsi_remove_host(vha->host);
48204829
return NULL;
48214830
}

0 commit comments

Comments
 (0)