public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
@ 2011-05-31 21:45 Andre Bartke
  2011-06-01 12:28 ` KY Srinivasan
  0 siblings, 1 reply; 4+ messages in thread
From: Andre Bartke @ 2011-05-31 21:45 UTC (permalink / raw)
  To: gregkh; +Cc: hjanssen, haiyangz, devel, linux-kernel, Andre Bartke

stor_device is not freed in storvsc_dev_add()
causing a memory leak in case of an allocation error.

Signed-off-by: Andre Bartke <andre.bartke@gmail.com>
---
 drivers/staging/hv/storvsc.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
index 06cd327..92b44f4 100644
--- a/drivers/staging/hv/storvsc.c
+++ b/drivers/staging/hv/storvsc.c
@@ -414,6 +414,7 @@ int storvsc_dev_add(struct hv_device *device,
 	device_info->target_id = stor_device->target_id;
 
 cleanup:
+	free_stor_device(stor_device);
 	return ret;
 }
 
-- 
1.7.5.2


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

* RE: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
  2011-05-31 21:45 [PATCH] staging/hv: Fix memory leak of storvsc_dev_add() Andre Bartke
@ 2011-06-01 12:28 ` KY Srinivasan
  2011-06-01 16:32   ` Andre Bartke
  0 siblings, 1 reply; 4+ messages in thread
From: KY Srinivasan @ 2011-06-01 12:28 UTC (permalink / raw)
  To: Andre Bartke, gregkh@suse.de
  Cc: devel@driverdev.osuosl.org, Andre Bartke, Haiyang Zhang,
	linux-kernel@vger.kernel.org



> -----Original Message-----
> From: devel-bounces@linuxdriverproject.org [mailto:devel-
> bounces@linuxdriverproject.org] On Behalf Of Andre Bartke
> Sent: Tuesday, May 31, 2011 5:46 PM
> To: gregkh@suse.de
> Cc: devel@driverdev.osuosl.org; Andre Bartke; Haiyang Zhang; linux-
> kernel@vger.kernel.org
> Subject: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
> 
> stor_device is not freed in storvsc_dev_add()
> causing a memory leak in case of an allocation error.
> 
> Signed-off-by: Andre Bartke <andre.bartke@gmail.com>
> ---
>  drivers/staging/hv/storvsc.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
> index 06cd327..92b44f4 100644
> --- a/drivers/staging/hv/storvsc.c
> +++ b/drivers/staging/hv/storvsc.c
> @@ -414,6 +414,7 @@ int storvsc_dev_add(struct hv_device *device,
>  	device_info->target_id = stor_device->target_id;
> 
>  cleanup:
> +	free_stor_device(stor_device);
>  	return ret;

Was this patch tested? Even the normal path falls through the cleanup label
and obviously you should not be freeing the stor_device in that case. I have 
patches queued up to cleanup some of the unnecessary labels and meaningless
return values that I will be sending soon.

Regards,

K. Y
 



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

* Re: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
  2011-06-01 12:28 ` KY Srinivasan
@ 2011-06-01 16:32   ` Andre Bartke
  2011-06-01 18:03     ` KY Srinivasan
  0 siblings, 1 reply; 4+ messages in thread
From: Andre Bartke @ 2011-06-01 16:32 UTC (permalink / raw)
  To: KY Srinivasan
  Cc: Andre Bartke, gregkh@suse.de, devel@driverdev.osuosl.org,
	Haiyang Zhang, linux-kernel@vger.kernel.org

On Wed, 1 Jun 2011 12:28:40 +0000
KY Srinivasan <kys@microsoft.com> wrote:

> 
> 
> > -----Original Message-----
> > From: devel-bounces@linuxdriverproject.org [mailto:devel-
> > bounces@linuxdriverproject.org] On Behalf Of Andre Bartke
> > Sent: Tuesday, May 31, 2011 5:46 PM
> > To: gregkh@suse.de
> > Cc: devel@driverdev.osuosl.org; Andre Bartke; Haiyang Zhang; linux-
> > kernel@vger.kernel.org
> > Subject: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
> > 
> > stor_device is not freed in storvsc_dev_add()
> > causing a memory leak in case of an allocation error.
> > 
> > Signed-off-by: Andre Bartke <andre.bartke@gmail.com>
> > ---
> >  drivers/staging/hv/storvsc.c |    1 +
> >  1 files changed, 1 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/staging/hv/storvsc.c
> > b/drivers/staging/hv/storvsc.c index 06cd327..92b44f4 100644
> > --- a/drivers/staging/hv/storvsc.c
> > +++ b/drivers/staging/hv/storvsc.c
> > @@ -414,6 +414,7 @@ int storvsc_dev_add(struct hv_device *device,
> >  	device_info->target_id = stor_device->target_id;
> > 
> >  cleanup:
> > +	free_stor_device(stor_device);
> >  	return ret;
> 
> Was this patch tested? Even the normal path falls through the cleanup
> label and obviously you should not be freeing the stor_device in that
> case. I have patches queued up to cleanup some of the unnecessary
> labels and meaningless return values that I will be sending soon.
> 
> Regards,
> 
> K. Y
>  
> 
> 

Right, I really messed up there, here is how it was supposed to be

>From 5fe8c601bae555b03257d0e7ea57e42a99c5e634 Mon Sep 17 00:00:00 2001
From: Andre Bartke <andre.bartke@gmail.com>
Date: Wed, 1 Jun 2011 18:18:58 +0200
Subject: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()

stor_device is not freed in storvsc_dev_add()
causing a memory leak in case of an allocation error.

Signed-off-by: Andre Bartke <andre.bartke@gmail.com>
---
 drivers/staging/hv/storvsc.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
index 06cd327..3d77c82 100644
--- a/drivers/staging/hv/storvsc.c
+++ b/drivers/staging/hv/storvsc.c
@@ -392,10 +392,8 @@ int storvsc_dev_add(struct hv_device *device,
 
 	device_info = (struct storvsc_device_info *)additional_info;
 	stor_device = alloc_stor_device(device);
-	if (!stor_device) {
-		ret = -1;
-		goto cleanup;
-	}
+	if (!stor_device)
+		goto err;
 
 	/* Save the channel properties to our storvsc channel */
 
@@ -413,6 +411,12 @@ int storvsc_dev_add(struct hv_device *device,
 	device_info->path_id = stor_device->path_id;
 	device_info->target_id = stor_device->target_id;
 
+	goto cleanup;
+
+err:
+	ret = -1;
+	free_stor_device(stor_device);
+
 cleanup:
 	return ret;
 }
-- 
1.7.5.2


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

* RE: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
  2011-06-01 16:32   ` Andre Bartke
@ 2011-06-01 18:03     ` KY Srinivasan
  0 siblings, 0 replies; 4+ messages in thread
From: KY Srinivasan @ 2011-06-01 18:03 UTC (permalink / raw)
  To: Andre Bartke
  Cc: gregkh@suse.de, devel@driverdev.osuosl.org, Haiyang Zhang,
	linux-kernel@vger.kernel.org



> -----Original Message-----
> From: Andre Bartke [mailto:andre.bartke@googlemail.com]
> Sent: Wednesday, June 01, 2011 12:32 PM
> To: KY Srinivasan
> Cc: Andre Bartke; gregkh@suse.de; devel@driverdev.osuosl.org; Haiyang Zhang;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
> 
> On Wed, 1 Jun 2011 12:28:40 +0000
> KY Srinivasan <kys@microsoft.com> wrote:
> 
> >
> >
> > > -----Original Message-----
> > > From: devel-bounces@linuxdriverproject.org [mailto:devel-
> > > bounces@linuxdriverproject.org] On Behalf Of Andre Bartke
> > > Sent: Tuesday, May 31, 2011 5:46 PM
> > > To: gregkh@suse.de
> > > Cc: devel@driverdev.osuosl.org; Andre Bartke; Haiyang Zhang; linux-
> > > kernel@vger.kernel.org
> > > Subject: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
> > >
> > > stor_device is not freed in storvsc_dev_add()
> > > causing a memory leak in case of an allocation error.
> > >
> > > Signed-off-by: Andre Bartke <andre.bartke@gmail.com>
> > > ---
> > >  drivers/staging/hv/storvsc.c |    1 +
> > >  1 files changed, 1 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/drivers/staging/hv/storvsc.c
> > > b/drivers/staging/hv/storvsc.c index 06cd327..92b44f4 100644
> > > --- a/drivers/staging/hv/storvsc.c
> > > +++ b/drivers/staging/hv/storvsc.c
> > > @@ -414,6 +414,7 @@ int storvsc_dev_add(struct hv_device *device,
> > >  	device_info->target_id = stor_device->target_id;
> > >
> > >  cleanup:
> > > +	free_stor_device(stor_device);
> > >  	return ret;
> >
> > Was this patch tested? Even the normal path falls through the cleanup
> > label and obviously you should not be freeing the stor_device in that
> > case. I have patches queued up to cleanup some of the unnecessary
> > labels and meaningless return values that I will be sending soon.
> >
> > Regards,
> >
> > K. Y
> >
> >
> >
> 
> Right, I really messed up there, here is how it was supposed to be
> 
> From 5fe8c601bae555b03257d0e7ea57e42a99c5e634 Mon Sep 17 00:00:00 2001
> From: Andre Bartke <andre.bartke@gmail.com>
> Date: Wed, 1 Jun 2011 18:18:58 +0200
> Subject: [PATCH] staging/hv: Fix memory leak of storvsc_dev_add()
> 
> stor_device is not freed in storvsc_dev_add()
> causing a memory leak in case of an allocation error.
> 
> Signed-off-by: Andre Bartke <andre.bartke@gmail.com>
> ---
>  drivers/staging/hv/storvsc.c |   12 ++++++++----
>  1 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
> index 06cd327..3d77c82 100644
> --- a/drivers/staging/hv/storvsc.c
> +++ b/drivers/staging/hv/storvsc.c
> @@ -392,10 +392,8 @@ int storvsc_dev_add(struct hv_device *device,
> 
>  	device_info = (struct storvsc_device_info *)additional_info;
>  	stor_device = alloc_stor_device(device);
> -	if (!stor_device) {
> -		ret = -1;
> -		goto cleanup;
> -	}
> +	if (!stor_device)
> +		goto err;
> 
>  	/* Save the channel properties to our storvsc channel */
> 
> @@ -413,6 +411,12 @@ int storvsc_dev_add(struct hv_device *device,
>  	device_info->path_id = stor_device->path_id;
>  	device_info->target_id = stor_device->target_id;
> 
> +	goto cleanup;
> +
> +err:
> +	ret = -1;
> +	free_stor_device(stor_device);
> +
>  cleanup:
>  	return ret;
>  }
> --
> 1.7.5.2
> 
This could be cleaned up much better; we don't need to additional labels. As I said,
earlier, I have patches queued up for this and a whole lot more. I will add your name to
the patch that fixes this issue.

Regards,

K. Y

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

end of thread, other threads:[~2011-06-01 18:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-31 21:45 [PATCH] staging/hv: Fix memory leak of storvsc_dev_add() Andre Bartke
2011-06-01 12:28 ` KY Srinivasan
2011-06-01 16:32   ` Andre Bartke
2011-06-01 18:03     ` KY Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox