Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@gmail.com>
To: Tejun Heo <htejun@gmail.com>
Cc: Jeff Garzik <jgarzik@pobox.com>,
	linux-ide@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] Fix a memory leak in piix_init_one
Date: Fri, 15 Dec 2006 23:14:20 +0000	[thread overview]
Message-ID: <20061215231419.5107.46451.stgit@localhost.localdomain> (raw)
In-Reply-To: <b0943d9e0612141542s558d3768h57a7bb9b5440a246@mail.gmail.com>

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@gmail.com>
---

 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)

      reply	other threads:[~2006-12-15 23:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <b0943d9e0612091454j6df1fb0ej2fa006c3fa33abae@mail.gmail.com>
2006-12-11 13:26 ` [PATCH] ata_piix: use piix_host_stop() in ich_pata_ops Tejun Heo
2006-12-11 14:19   ` Alan
2006-12-13 10:41   ` Catalin Marinas
2006-12-14 23:42     ` Catalin Marinas
2006-12-15 23:14       ` Catalin Marinas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061215231419.5107.46451.stgit@localhost.localdomain \
    --to=catalin.marinas@gmail.com \
    --cc=htejun@gmail.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox