public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: Axel Lin <axel.lin@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Debora Velarde <debora@linux.vnet.ibm.com>,
	Rajiv Andrade <srajiv@linux.vnet.ibm.com>,
	Marcel Selhorst <m.selhorst@sirrix.com>,
	tpmdd-devel@lists.sourceforge.net
Subject: Re: [PATCH] tpm: tpm_nsc: Fix a double free of pdev in cleanup_nsc
Date: Fri, 05 Aug 2011 10:20:22 -0400	[thread overview]
Message-ID: <4E3BFC26.8060904@linux.vnet.ibm.com> (raw)
In-Reply-To: <1312415887.2604.1.camel@phoenix>

On 08/03/2011 07:58 PM, Axel Lin wrote:
> platform_device_unregister() will release all resources
> and remove it from the subsystem, then drop reference count by
> calling platform_device_put().
I also changed code into that direction in the recent patch to the 
tpm_nsc driver. I didn't know whether that memory had to be freed or 
not. Looking at several other drivers I found that none was freeing it 
but calling platform_device_put() (which is also called by 
platform_device_unregiser()) with the memory previously allocated via 
platform_device_alloc(). Though platform_device_put() calls put_device()

http://lxr.linux.no/#linux+v3.0/drivers/base/platform.c#L138

which in turn calls kobject_put().

http://lxr.linux.no/#linux+v3.0/drivers/base/core.c#L1066

It was not clear to me whether the pdev memory would actually get freed 
by kobject_put() -- but since other drivers were not freeing it 
explicitly I wasn't sure. So either many drivers have a memory leak or 
tpm_nsc was previously right about freeing it...

    Stefan

> We should not call kfree(pdev) after platform_device_unregister(pdev).
>
> Signed-off-by: Axel Lin<axel.lin@gmail.com>
> ---
>   drivers/char/tpm/tpm_nsc.c |    2 --
>   1 files changed, 0 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
> index 82facc9..4d24648 100644
> --- a/drivers/char/tpm/tpm_nsc.c
> +++ b/drivers/char/tpm/tpm_nsc.c
> @@ -396,8 +396,6 @@ static void __exit cleanup_nsc(void)
>   	if (pdev) {
>   		tpm_nsc_remove(&pdev->dev);
>   		platform_device_unregister(pdev);
> -		kfree(pdev);
> -		pdev = NULL;
>   	}
>
>   	platform_driver_unregister(&nsc_drv);


      reply	other threads:[~2011-08-05 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 23:58 [PATCH] tpm: tpm_nsc: Fix a double free of pdev in cleanup_nsc Axel Lin
2011-08-05 14:20 ` Stefan Berger [this message]

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=4E3BFC26.8060904@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=axel.lin@gmail.com \
    --cc=debora@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.selhorst@sirrix.com \
    --cc=srajiv@linux.vnet.ibm.com \
    --cc=tpmdd-devel@lists.sourceforge.net \
    /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