All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] input: da9052: fix mem leak in da9052_onkey_probe()
@ 2012-04-11 20:56 Jesper Juhl
  2012-04-11 21:22 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Jesper Juhl @ 2012-04-11 20:56 UTC (permalink / raw)
  To: linux-kernel
  Cc: David Dajun Chen, linux-input, Ashish Jangam, Dmitry Torokhov

If, in drivers/input/misc/da9052_onkey.c::da9052_onkey_probe(), the
call to either kzalloc() or input_allocate_device() fails then we will
return -ENOMEM from the function without freeing the other allocation
that may have succeeded, thus we leak either the memory allocated for
'onkey' or the memory allocated for 'input_dev' if one succeeds and
the other fails.
Fix that by jumping to the 'err_free_mem' label at the end of the
function that properly cleans up rather than returning directly.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/input/misc/da9052_onkey.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/da9052_onkey.c b/drivers/input/misc/da9052_onkey.c
index 34aebb8..3c843cd 100644
--- a/drivers/input/misc/da9052_onkey.c
+++ b/drivers/input/misc/da9052_onkey.c
@@ -95,7 +95,8 @@ static int __devinit da9052_onkey_probe(struct platform_device *pdev)
 	input_dev = input_allocate_device();
 	if (!onkey || !input_dev) {
 		dev_err(&pdev->dev, "Failed to allocate memory\n");
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto err_free_mem;
 	}
 
 	onkey->input = input_dev;
-- 
1.7.10


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH] input: da9052: fix mem leak in da9052_onkey_probe()
  2012-04-11 20:56 [PATCH] input: da9052: fix mem leak in da9052_onkey_probe() Jesper Juhl
@ 2012-04-11 21:22 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2012-04-11 21:22 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, David Dajun Chen, linux-input, Ashish Jangam

On Wed, Apr 11, 2012 at 10:56:10PM +0200, Jesper Juhl wrote:
> If, in drivers/input/misc/da9052_onkey.c::da9052_onkey_probe(), the
> call to either kzalloc() or input_allocate_device() fails then we will
> return -ENOMEM from the function without freeing the other allocation
> that may have succeeded, thus we leak either the memory allocated for
> 'onkey' or the memory allocated for 'input_dev' if one succeeds and
> the other fails.
> Fix that by jumping to the 'err_free_mem' label at the end of the
> function that properly cleans up rather than returning directly.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

I must have messed up error hanlding path when collapsing the 2 memory
allocations; applied, thank Jesper.

> ---
>  drivers/input/misc/da9052_onkey.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/da9052_onkey.c b/drivers/input/misc/da9052_onkey.c
> index 34aebb8..3c843cd 100644
> --- a/drivers/input/misc/da9052_onkey.c
> +++ b/drivers/input/misc/da9052_onkey.c
> @@ -95,7 +95,8 @@ static int __devinit da9052_onkey_probe(struct platform_device *pdev)
>  	input_dev = input_allocate_device();
>  	if (!onkey || !input_dev) {
>  		dev_err(&pdev->dev, "Failed to allocate memory\n");
> -		return -ENOMEM;
> +		error = -ENOMEM;
> +		goto err_free_mem;
>  	}
>  
>  	onkey->input = input_dev;
> -- 
> 1.7.10
> 
> 
> -- 
> Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
> Don't top-post http://www.catb.org/jargon/html/T/top-post.html
> Plain text mails only, please.
> 

-- 
Dmitry

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

end of thread, other threads:[~2012-04-11 21:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-11 20:56 [PATCH] input: da9052: fix mem leak in da9052_onkey_probe() Jesper Juhl
2012-04-11 21:22 ` Dmitry Torokhov

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.