[PATCH] Fix a memory leak in piix_init_one

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

 



The piix_init_one() function in drivers/ata/ata_piix.c can return an
error without cleaning up the piix_host_priv structure
allocation. This patch adds a kfree() call on the error path.

Signed-off-by: Catalin Marinas <catalin.marinas@xxxxxxxxx>
---

 drivers/ata/ata_piix.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index dfe17e1..6717891 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -1051,6 +1051,7 @@ static int piix_init_one (struct pci_dev
 	struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] };
 	struct piix_host_priv *hpriv;
 	unsigned long port_flags;
+	int ret;
 
 	if (!printed_version++)
 		dev_printk(KERN_DEBUG, &pdev->dev,
@@ -1075,9 +1076,9 @@ static int piix_init_one (struct pci_dev
 		u8 tmp;
 		pci_read_config_byte(pdev, PIIX_SCC, &tmp);
 		if (tmp == PIIX_AHCI_DEVICE) {
-			int rc = piix_disable_ahci(pdev);
-			if (rc)
-				return rc;
+			ret = piix_disable_ahci(pdev);
+			if (ret)
+				goto cleanup;
 		}
 	}
 
@@ -1107,7 +1108,15 @@ static int piix_init_one (struct pci_dev
 		port_info[1].mwdma_mask = 0;
 		port_info[1].udma_mask = 0;
 	}
-	return ata_pci_init_one(pdev, ppinfo, 2);
+	ret = ata_pci_init_one(pdev, ppinfo, 2);
+	if (ret)
+		goto cleanup;
+	goto out;
+
+ cleanup:
+	kfree(hpriv);
+ out:
+	return ret;
 }
 
 static void piix_host_stop(struct ata_host *host)
-
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystems]     [Linux SCSI]     [Linux RAID]     [Git]     [Kernel Newbies]     [Linux Newbie]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Samba]     [Device Mapper]

  Powered by Linux