From: arvindY <arvind.yadav.cs@gmail.com>
To: Shannon Nelson <shannon.nelson@oracle.com>,
davem@davemloft.net, jag.raman@oracle.com,
liam.merwick@oracle.com
Cc: linux-kernel@vger.kernel.org, sparclinux@vger.kernel.org
Subject: Re: [PATCH] sparc: vio: use put_device() instead of kfree()
Date: Wed, 25 Apr 2018 21:29:57 +0530 [thread overview]
Message-ID: <5AE0A5FD.3060009@gmail.com> (raw)
In-Reply-To: <d16d5b54-90c9-3137-bc74-2b0d7135a928@oracle.com>
On Wednesday 25 April 2018 09:14 PM, Shannon Nelson wrote:
> On 4/25/2018 7:56 AM, Arvind Yadav wrote:
>> Never directly free @dev after calling device_register(), even
>> if it returned an error. Always use put_device() to give up the
>> reference initialized.
>>
>> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
>> ---
>> arch/sparc/kernel/vio.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/sparc/kernel/vio.c b/arch/sparc/kernel/vio.c
>> index 1a0fa10..32bae68 100644
>> --- a/arch/sparc/kernel/vio.c
>> +++ b/arch/sparc/kernel/vio.c
>> @@ -403,7 +403,7 @@ static struct vio_dev *vio_create_one(struct
>> mdesc_handle *hp, u64 mp,
>> if (err) {
>> printk(KERN_ERR "VIO: Could not register device %s, err=%d\n",
>> dev_name(&vdev->dev), err);
>> - kfree(vdev);
>> + put_device(&vdev->dev);
>
> Hmmm... I can see why the put_device() might be a good idea, but I
> think we still need the kfree() so as to not leak the memory that was
> kzalloc'd above for vdev.
>
There is no need to call kfree() here. Because put_device()
will decrement the last reference and then free the memory
by calling dev->release(It'll call vio_dev_release()).
Internally put_device() -> kobject_put() -> kobject_cleanup()
which is responsible to call 'dev -> release' and also free
other kobject resources.
If we will call kfree() here, Then It'll be a redundant call.
~arvind
> sln
>
>> return NULL;
>> }
>> if (vdev->dp)
>>
next prev parent reply other threads:[~2018-04-25 16:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-25 14:56 [PATCH] sparc: vio: use put_device() instead of kfree() Arvind Yadav
2018-04-25 15:44 ` Shannon Nelson
2018-04-25 15:59 ` arvindY [this message]
2018-04-25 16:38 ` Shannon Nelson
2018-04-30 20:10 ` David Miller
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=5AE0A5FD.3060009@gmail.com \
--to=arvind.yadav.cs@gmail.com \
--cc=davem@davemloft.net \
--cc=jag.raman@oracle.com \
--cc=liam.merwick@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shannon.nelson@oracle.com \
--cc=sparclinux@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