public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Tiezhu Yang" <kernelpatch@126.com>
To: martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] scsi: ufs: fix potential memory leak
Date: Wed, 8 Jun 2016 02:00:35 +0800 (CST)	[thread overview]
Message-ID: <1a5ff649.111.1552c05f371.Coremail.kernelpatch@126.com> (raw)

There exists potential memory leak in ufshcd_parse_clock_info(),
this patch fixes it.

Signed-off-by: Tiezhu Yang <kernelpatch@126.com>
---
 drivers/scsi/ufs/ufshcd-pltfrm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
index db53f38..8b057f4 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
@@ -100,19 +100,19 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
 	if (ret && (ret != -EINVAL)) {
 		dev_err(dev, "%s: error reading array %d\n",
 				"freq-table-hz", ret);
-		return ret;
+		goto out_free;
 	}
 
 	for (i = 0; i < sz; i += 2) {
 		ret = of_property_read_string_index(np,
 				"clock-names", i/2, (const char **)&name);
 		if (ret)
-			goto out;
+			goto out_free;
 
 		clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL);
 		if (!clki) {
 			ret = -ENOMEM;
-			goto out;
+			goto out_free;
 		}
 
 		clki->min_freq = clkfreq[i];
@@ -122,6 +122,10 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
 				clki->min_freq, clki->max_freq, clki->name);
 		list_add_tail(&clki->list, &hba->clk_list_head);
 	}
+
+out_free:
+	devm_kfree(dev, clkfreq);
+	clkfreq = NULL;
 out:
 	return ret;
 }
-- 
1.8.3.1

             reply	other threads:[~2016-06-07 18:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-07 18:00 Tiezhu Yang [this message]
2016-06-07 19:12 ` [PATCH] scsi: ufs: fix potential memory leak James Bottomley
2016-06-07 22:49   ` Tiezhu Yang

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=1a5ff649.111.1552c05f371.Coremail.kernelpatch@126.com \
    --to=kernelpatch@126.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /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