All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: fix potential memory leak
@ 2016-06-07 18:00 Tiezhu Yang
  2016-06-07 19:12 ` James Bottomley
  0 siblings, 1 reply; 3+ messages in thread
From: Tiezhu Yang @ 2016-06-07 18:00 UTC (permalink / raw)
  To: martin.petersen; +Cc: linux-scsi, linux-kernel

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: ufs: fix potential memory leak
  2016-06-07 18:00 [PATCH] scsi: ufs: fix potential memory leak Tiezhu Yang
@ 2016-06-07 19:12 ` James Bottomley
  2016-06-07 22:49   ` Tiezhu Yang
  0 siblings, 1 reply; 3+ messages in thread
From: James Bottomley @ 2016-06-07 19:12 UTC (permalink / raw)
  To: Tiezhu Yang, martin.petersen; +Cc: linux-scsi, linux-kernel

On Wed, 2016-06-08 at 02:00 +0800, Tiezhu Yang wrote:
> There exists potential memory leak in ufshcd_parse_clock_info(),
> this patch fixes it.

What makes you think there's a leak here?  These are all devm_
allocations, so they're all freed when the device is.  If an error is
returned, the device is released and the memory freed.

You can argue that on successful initialization, there's no need to
keep the clkfreq array but this patch isn't the way you'd change that.

James

> 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;
>  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: ufs: fix potential memory leak
  2016-06-07 19:12 ` James Bottomley
@ 2016-06-07 22:49   ` Tiezhu Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Tiezhu Yang @ 2016-06-07 22:49 UTC (permalink / raw)
  To: James Bottomley; +Cc: martin.petersen, linux-scsi, linux-kernel

At 2016-06-08 03:12:08, "James Bottomley" <James.Bottomley@HansenPartnership.com> wrote:
>On Wed, 2016-06-08 at 02:00 +0800, Tiezhu Yang wrote:
>> There exists potential memory leak in ufshcd_parse_clock_info(),
>> this patch fixes it.
>
>What makes you think there's a leak here?  These are all devm_
>allocations, so they're all freed when the device is.  If an error is
>returned, the device is released and the memory freed.
>
>You can argue that on successful initialization, there's no need to
>keep the clkfreq array but this patch isn't the way you'd change that.
>
>James
>
OK, thanks. I will send a v2 patch.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-07 23:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-07 18:00 [PATCH] scsi: ufs: fix potential memory leak Tiezhu Yang
2016-06-07 19:12 ` James Bottomley
2016-06-07 22:49   ` Tiezhu Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.