All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] sony-laptop: leak in error handling sony_nc_lid_resume_setup()
@ 2013-02-01 13:28 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2013-02-01 13:28 UTC (permalink / raw)
  To: Mattia Dongili; +Cc: Matthew Garrett, platform-driver-x86, kernel-janitors

We need to decrement "i" first because the current "i" was not allocated
succesfully.  Also we should go free the way down to zero to avoid a
leak.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index 438c7fa..9557414 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -2351,7 +2351,7 @@ static int sony_nc_lid_resume_setup(struct platform_device *pd)
 	return 0;
 
 liderror:
-	for (; i > 0; i--)
+	for (i--; i >= 0; i--)
 		device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
 
 	kfree(lid_ctl);

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

* [patch] sony-laptop: leak in error handling sony_nc_lid_resume_setup()
@ 2013-02-01 13:28 ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2013-02-01 13:28 UTC (permalink / raw)
  To: Mattia Dongili; +Cc: Matthew Garrett, platform-driver-x86, kernel-janitors

We need to decrement "i" first because the current "i" was not allocated
succesfully.  Also we should go free the way down to zero to avoid a
leak.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index 438c7fa..9557414 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -2351,7 +2351,7 @@ static int sony_nc_lid_resume_setup(struct platform_device *pd)
 	return 0;
 
 liderror:
-	for (; i > 0; i--)
+	for (i--; i >= 0; i--)
 		device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
 
 	kfree(lid_ctl);

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

* Re: [patch] sony-laptop: leak in error handling sony_nc_lid_resume_setup()
  2013-02-01 13:28 ` Dan Carpenter
@ 2013-02-02  9:51   ` walter harms
  -1 siblings, 0 replies; 4+ messages in thread
From: walter harms @ 2013-02-02  9:51 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mattia Dongili, Matthew Garrett, platform-driver-x86, kernel-janitors



Am 01.02.2013 14:28, schrieb Dan Carpenter:
> We need to decrement "i" first because the current "i" was not allocated
> succesfully.  Also we should go free the way down to zero to avoid a
> leak.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> index 438c7fa..9557414 100644
> --- a/drivers/platform/x86/sony-laptop.c
> +++ b/drivers/platform/x86/sony-laptop.c
> @@ -2351,7 +2351,7 @@ static int sony_nc_lid_resume_setup(struct platform_device *pd)
>  	return 0;
>  
>  liderror:
> -	for (; i > 0; i--)
> +	for (i--; i >= 0; i--)
>  		device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
>  
>  	kfree(lid_ctl);

i have learned that most people get confused when you do loop
"the-other-way-around". (typical errors see above). Maybe it
would be better foe further generations to turn the loop on its
head like:

int c;
for(c=0; c < i ; c++)
    device_remove_file(&pd->dev, &lid_ctl->attrs[c]);
kfree(lid_ctl);

re,
 wh

yes, there is one var more

> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

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

* Re: [patch] sony-laptop: leak in error handling sony_nc_lid_resume_setup()
@ 2013-02-02  9:51   ` walter harms
  0 siblings, 0 replies; 4+ messages in thread
From: walter harms @ 2013-02-02  9:51 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mattia Dongili, Matthew Garrett, platform-driver-x86, kernel-janitors



Am 01.02.2013 14:28, schrieb Dan Carpenter:
> We need to decrement "i" first because the current "i" was not allocated
> succesfully.  Also we should go free the way down to zero to avoid a
> leak.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
> index 438c7fa..9557414 100644
> --- a/drivers/platform/x86/sony-laptop.c
> +++ b/drivers/platform/x86/sony-laptop.c
> @@ -2351,7 +2351,7 @@ static int sony_nc_lid_resume_setup(struct platform_device *pd)
>  	return 0;
>  
>  liderror:
> -	for (; i > 0; i--)
> +	for (i--; i >= 0; i--)
>  		device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
>  
>  	kfree(lid_ctl);

i have learned that most people get confused when you do loop
"the-other-way-around". (typical errors see above). Maybe it
would be better foe further generations to turn the loop on its
head like:

int c;
for(c=0; c < i ; c++)
    device_remove_file(&pd->dev, &lid_ctl->attrs[c]);
kfree(lid_ctl);

re,
 wh

yes, there is one var more

> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

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

end of thread, other threads:[~2013-02-02  9:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-01 13:28 [patch] sony-laptop: leak in error handling sony_nc_lid_resume_setup() Dan Carpenter
2013-02-01 13:28 ` Dan Carpenter
2013-02-02  9:51 ` walter harms
2013-02-02  9:51   ` walter harms

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.