diff mbox series

[v3] scsi: hpsa: fix memory leak in hpsa_init_one

Message ID 20201027073125.14229-1-keitasuzuki.park@sslab.ics.keio.ac.jp (mailing list archive)
State Accepted
Headers show
Series [v3] scsi: hpsa: fix memory leak in hpsa_init_one | expand

Commit Message

Keita Suzuki Oct. 27, 2020, 7:31 a.m. UTC
When hpsa_scsi_add_host fails, h->lastlogicals is leaked since it lacks
free in the error handler.

Fix this by adding free when hpsa_scsi_add_host fails.

Signed-off-by: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>
---
v3: revert label name to numbered labels
v2: rename labels
 drivers/scsi/hpsa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Don Brace Oct. 27, 2020, 3:27 p.m. UTC | #1
-----Original Message-----
From: Keita Suzuki [mailto:keitasuzuki.park@sslab.ics.keio.ac.jp] 
Sent: Tuesday, October 27, 2020 2:31 AM
Cc: keitasuzuki.park@sslab.ics.keio.ac.jp; takafumi@sslab.ics.keio.ac.jp; Don Brace <don.brace@microsemi.com>; James E.J. Bottomley <jejb@linux.ibm.com>; Martin K. Petersen <martin.petersen@oracle.com>; esc.storagedev@microsemi.com; linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org
Subject: [PATCH v3] scsi: hpsa: fix memory leak in hpsa_init_one

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

When hpsa_scsi_add_host fails, h->lastlogicals is leaked since it lacks free in the error handler.

Fix this by adding free when hpsa_scsi_add_host fails.

Signed-off-by: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>

Acked-by: Don Brace <don.brace@microchip.com>
Tested-by: Don Brace <don.brace@microchip.com>

---
v3: revert label name to numbered labels
v2: rename labels
 drivers/scsi/hpsa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 48d5da59262b..aed59ec20ad9 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -8854,7 +8854,7 @@ static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        /* hook into SCSI subsystem */
        rc = hpsa_scsi_add_host(h);
        if (rc)
-               goto clean7; /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
+               goto clean8; /* lastlogicals, perf, sg, cmd, irq, shost, 
+ pci, lu, aer/h */

        /* Monitor the controller for firmware lockups */
        h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL; @@ -8869,6 +8869,8 @@ static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                                HPSA_EVENT_MONITOR_INTERVAL);
        return 0;

+clean8: /* lastlogicals, perf, sg, cmd, irq, shost, pci, lu, aer/h */
+       kfree(h->lastlogicals);
 clean7: /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
        hpsa_free_performant_mode(h);
        h->access.set_intr_mask(h, HPSA_INTR_OFF);
--
2.17.1
Martin K. Petersen Oct. 30, 2020, 2:20 a.m. UTC | #2
On Tue, 27 Oct 2020 07:31:24 +0000, Keita Suzuki wrote:

> When hpsa_scsi_add_host fails, h->lastlogicals is leaked since it lacks
> free in the error handler.
> 
> Fix this by adding free when hpsa_scsi_add_host fails.

Applied to 5.10/scsi-fixes, thanks!

[1/1] scsi: hpsa: Fix memory leak in hpsa_init_one()
      https://git.kernel.org/mkp/scsi/c/af61bc1e33d2
diff mbox series

Patch

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 48d5da59262b..aed59ec20ad9 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -8854,7 +8854,7 @@  static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	/* hook into SCSI subsystem */
 	rc = hpsa_scsi_add_host(h);
 	if (rc)
-		goto clean7; /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
+		goto clean8; /* lastlogicals, perf, sg, cmd, irq, shost, pci, lu, aer/h */
 
 	/* Monitor the controller for firmware lockups */
 	h->heartbeat_sample_interval = HEARTBEAT_SAMPLE_INTERVAL;
@@ -8869,6 +8869,8 @@  static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 				HPSA_EVENT_MONITOR_INTERVAL);
 	return 0;
 
+clean8: /* lastlogicals, perf, sg, cmd, irq, shost, pci, lu, aer/h */
+	kfree(h->lastlogicals);
 clean7: /* perf, sg, cmd, irq, shost, pci, lu, aer/h */
 	hpsa_free_performant_mode(h);
 	h->access.set_intr_mask(h, HPSA_INTR_OFF);