public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: Venu Byravarasu <vbyravarasu@nvidia.com>
Cc: "balbi@ti.com" <balbi@ti.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] usb: phy: tegra: Using devm API for memory allocation
Date: Wed, 19 Dec 2012 10:38:03 -0700	[thread overview]
Message-ID: <50D1FB7B.4090002@wwwdotorg.org> (raw)
In-Reply-To: <D958900912E20642BCBC71664EFECE3E6E19E0BFC4@BGMAIL02.nvidia.com>

On 12/18/2012 10:38 PM, Venu Byravarasu wrote:
>> -----Original Message-----
>> From: Stephen Warren [mailto:swarren@wwwdotorg.org]
>> Sent: Tuesday, December 18, 2012 10:03 PM
>> To: Venu Byravarasu
>> Cc: balbi@ti.com; gregkh@linuxfoundation.org; linux-
>> kernel@vger.kernel.org; linux-usb@vger.kernel.org
>> Subject: Re: [PATCH] usb: phy: tegra: Using devm API for memory allocation
>>
>> On 12/17/2012 11:21 PM, Venu Byravarasu wrote:
>>> Using devm_kzalloc for allocating memory needed for PHY
>>> pointer and hence removing kfree calls to PHY pointer.
>>
>> Since the kfree() here used to be in tegra_usb_phy_close() rather than
>> any remove() function, does it actually make sense to use
>> devm_kzalloc(); would plain using kzalloc() instead, and not removing
>> the kfree() calls, be better?
>>
>  
> Stephen,
> As you mentioned I can replace kmalloc with kzalloc in the original code 
> and push an updated patch.
> However, I just wanted to understand if there exists any issue
> in using devm_kzalloc instead of kzalloc?

devm_* are intended for objects allocated during probe(), and free()d
during remove(). The object you're allocating here isn't that case.

Now, once you convert the Tegra PHY driver to be a true device, perhaps
this object will be allocated/freed during probe/remove, so the devm_
functions will be useful then?

The problem this may cause is a memory leak. Consider the Tegra EHCI and
PHY drivers being built as modules, the PHY driver module being inserted
and never removed, yet the EHCI driver being continually inserted and
removed. Since the PHY is never removed, the memory allocated by its
devm_kzalloc() call is never freed, but it's continually re-allocated
since tegra_usb_phy_open() is called whenever the EHCI driver module is
inserted. You need the explicit kfree() to avoid that, and since you're
kfree()ing somewhere other than remove(), using devm_* to make the
allocation isn't appropriate.

  reply	other threads:[~2012-12-19 17:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-18  6:21 [PATCH] usb: phy: tegra: Using devm API for memory allocation Venu Byravarasu
2012-12-18 16:33 ` Stephen Warren
2012-12-19  5:38   ` Venu Byravarasu
2012-12-19 17:38     ` Stephen Warren [this message]
2012-12-20  8:48       ` Venu Byravarasu

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=50D1FB7B.4090002@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=vbyravarasu@nvidia.com \
    /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