public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Hans J. Koch" <hjk@hansjkoch.de>
To: Cong Ding <dinggnu@gmail.com>, h@local
Cc: "Hans J. Koch" <hjk@hansjkoch.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] uio.c: solve memory leak
Date: Fri, 30 Nov 2012 01:13:04 +0100	[thread overview]
Message-ID: <20121130001304.GB2590@local> (raw)
In-Reply-To: <1354210800-27230-1-git-send-email-dinggnu@gmail.com>

On Thu, Nov 29, 2012 at 05:40:00PM +0000, Cong Ding wrote:
> In version 1, I forgot to modify the same bug in the first loop.
> 
> we have to call kobject_put() to clean up the kobject after function
> kobject_init(), kobject_add(), or kobject_uevent() is called.

Yes, thanks. Incredible how that code looks like...
There's still another bug: The memory allocated with kzalloc is
never freed. More tomorrow, have to go to sleep now.

Thanks,
Hans

> 
> Signed-off-by: Cong Ding <dinggnu@gmail.com>
> ---
>  drivers/uio/uio.c |   16 ++++++++++------
>  1 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> index 5110f36..79774d3 100644
> --- a/drivers/uio/uio.c
> +++ b/drivers/uio/uio.c
> @@ -291,10 +291,10 @@ static int uio_dev_add_attributes(struct uio_device *idev)
>  		mem->map = map;
>  		ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi);
>  		if (ret)
> -			goto err_map;
> +			goto err_map_kobj;
>  		ret = kobject_uevent(&map->kobj, KOBJ_ADD);
>  		if (ret)
> -			goto err_map;
> +			goto err_map_kobj;
>  	}
>  
>  	for (pi = 0; pi < MAX_UIO_PORT_REGIONS; pi++) {
> @@ -317,23 +317,27 @@ static int uio_dev_add_attributes(struct uio_device *idev)
>  		ret = kobject_add(&portio->kobj, idev->portio_dir,
>  							"port%d", pi);
>  		if (ret)
> -			goto err_portio;
> +			goto err_portio_kobj;
>  		ret = kobject_uevent(&portio->kobj, KOBJ_ADD);
>  		if (ret)
> -			goto err_portio;
> +			goto err_portio_kobj;
>  	}
>  
>  	return 0;
>  
>  err_portio:
> -	for (pi--; pi >= 0; pi--) {
> +	pi--;
> +err_portio_kobj:
> +	for (; pi >= 0; pi--) {
>  		port = &idev->info->port[pi];
>  		portio = port->portio;
>  		kobject_put(&portio->kobj);
>  	}
>  	kobject_put(idev->portio_dir);
>  err_map:
> -	for (mi--; mi>=0; mi--) {
> +	mi--;
> +err_map_kobj:
> +	for (; mi >= 0; mi--) {
>  		mem = &idev->info->mem[mi];
>  		map = mem->map;
>  		kobject_put(&map->kobj);
> -- 
> 1.7.4.5
> 
> 

  reply	other threads:[~2012-11-30  0:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-29 17:40 [PATCH v2 1/1] uio.c: solve memory leak Cong Ding
2012-11-30  0:13 ` Hans J. Koch [this message]
2012-11-30 11:03   ` Cong Ding
2012-12-06 23:02     ` Cong Ding
2012-12-08  0:10       ` Hans J. Koch
2012-12-08  0:15         ` Cong Ding
2012-12-11  1:21 ` Hans J. Koch
2013-01-18 21:05   ` Cong Ding
2013-01-18 22:00     ` Greg Kroah-Hartman
2013-01-20 21:01       ` Hans J. Koch
2013-02-14 11:43         ` Cong Ding
2013-04-25 10:19           ` Cong Ding
2013-05-26 22:14             ` Cong Ding
2013-07-25  7:05               ` Cong Ding

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=20121130001304.GB2590@local \
    --to=hjk@hansjkoch.de \
    --cc=dinggnu@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=h@local \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox