Re: [PATCH] qla2xxx: Fix memory leak in error path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 15:16 09/01/19, Anirban Chakraborty wrote:
>The following patch fixes memory leak in the error path of scsi host allocation 
>failure.
>Please review and apply.
>
>Thanks,
>Anirban
>
>Signed-off-by: Anirban Chakraborty <anirban.chakraborty@xxxxxxxxxx>
>
>diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
>index df6e6a2..2cf1491 100644
>--- a/drivers/scsi/qla2xxx/qla_os.c
>+++ b/drivers/scsi/qla2xxx/qla_os.c
>@@ -1888,6 +1888,8 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct 
>pci_device_id *id)
> 		    "[ERROR] Failed to allocate memory for scsi_host\n");
> 
> 		ret = -ENOMEM;
>+		qla2x00_mem_free(ha);
>+		qla2x00_free_queues(ha);
> 		goto probe_hw_failed;
> 	}
> 

This patch is not sufficient, because req and rsp are not freed and
at this point ha->req_q_map and ha->rsp_q_map are not allocated yet,
so qla2x00_free_queues is not needed.

Following is my patch.
Comments?

Signed-off-by: Hisashi Hifumi <hifumi.hisashi@xxxxxxxxxxxxx>

diff -Nrup linux-2.6.29-rc2.org/drivers/scsi/qla2xxx/qla_os.c linux-2.6.29-rc2.qla2x/drivers/scsi/qla2xxx/qla_os.c
--- linux-2.6.29-rc2.org/drivers/scsi/qla2xxx/qla_os.c	2009-01-19 11:46:19.000000000 +0900
+++ linux-2.6.29-rc2.qla2x/drivers/scsi/qla2xxx/qla_os.c	2009-01-19 16:00:42.000000000 +0900
@@ -1888,6 +1888,8 @@ qla2x00_probe_one(struct pci_dev *pdev, 
 		    "[ERROR] Failed to allocate memory for scsi_host\n");
 
 		ret = -ENOMEM;
+		qla2x00_mem_free(ha);
+		qla2x00_free_que(ha, req, rsp);
 		goto probe_hw_failed;
 	}
 
@@ -1916,14 +1918,18 @@ qla2x00_probe_one(struct pci_dev *pdev, 
 
 	/* Set up the irqs */
 	ret = qla2x00_request_irqs(ha, rsp);
-	if (ret)
+	if (ret) {
+		qla2x00_free_que(ha, req, rsp);
 		goto probe_failed;
+	}
 
 	/* Alloc arrays of request and response ring ptrs */
 	if (!qla2x00_alloc_queues(ha)) {
 		qla_printk(KERN_WARNING, ha,
 		"[ERROR] Failed to allocate memory for queue"
 		" pointers\n");
+
+		qla2x00_free_que(ha, req, rsp);
 		goto probe_failed;
 	}
 	ha->rsp_q_map[0] = rsp;


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux