All of lore.kernel.org
 help / color / mirror / Atom feed
From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Mattia Dongili <malattia@linux.it>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	platform-driver-x86@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] sony-laptop: leak in error handling sony_nc_lid_resume_setup()
Date: Sat, 02 Feb 2013 09:51:43 +0000	[thread overview]
Message-ID: <510CE1AF.3070101@bfs.de> (raw)
In-Reply-To: <20130201132826.GA23374@elgon.mountain>



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

WARNING: multiple messages have this Message-ID (diff)
From: walter harms <wharms@bfs.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Mattia Dongili <malattia@linux.it>,
	Matthew Garrett <matthew.garrett@nebula.com>,
	platform-driver-x86@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] sony-laptop: leak in error handling sony_nc_lid_resume_setup()
Date: Sat, 02 Feb 2013 10:51:43 +0100	[thread overview]
Message-ID: <510CE1AF.3070101@bfs.de> (raw)
In-Reply-To: <20130201132826.GA23374@elgon.mountain>



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

  reply	other threads:[~2013-02-02  9:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2013-02-02  9:51   ` walter harms

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=510CE1AF.3070101@bfs.de \
    --to=wharms@bfs.de \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=malattia@linux.it \
    --cc=matthew.garrett@nebula.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /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 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.