public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sparc: vio: use put_device() instead of kfree()
@ 2018-04-25 14:56 Arvind Yadav
  2018-04-25 15:44 ` Shannon Nelson
  2018-04-30 20:10 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Arvind Yadav @ 2018-04-25 14:56 UTC (permalink / raw)
  To: davem, shannon.nelson, jag.raman, liam.merwick; +Cc: linux-kernel, sparclinux

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);
 		return NULL;
 	}
 	if (vdev->dp)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] sparc: vio: use put_device() instead of kfree()
  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
  2018-04-30 20:10 ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Shannon Nelson @ 2018-04-25 15:44 UTC (permalink / raw)
  To: Arvind Yadav, davem, jag.raman, liam.merwick; +Cc: linux-kernel, sparclinux

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.

sln

>   		return NULL;
>   	}
>   	if (vdev->dp)
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sparc: vio: use put_device() instead of kfree()
  2018-04-25 15:44 ` Shannon Nelson
@ 2018-04-25 15:59   ` arvindY
  2018-04-25 16:38     ` Shannon Nelson
  0 siblings, 1 reply; 5+ messages in thread
From: arvindY @ 2018-04-25 15:59 UTC (permalink / raw)
  To: Shannon Nelson, davem, jag.raman, liam.merwick; +Cc: linux-kernel, sparclinux



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sparc: vio: use put_device() instead of kfree()
  2018-04-25 15:59   ` arvindY
@ 2018-04-25 16:38     ` Shannon Nelson
  0 siblings, 0 replies; 5+ messages in thread
From: Shannon Nelson @ 2018-04-25 16:38 UTC (permalink / raw)
  To: arvindY
  Cc: Shannon Nelson, David Miller, jag.raman, liam.merwick,
	linux-kernel, Sparc kernel list

Oh, yes, there it is, and the pointer to vio_dev_release() was already
set up a little earlier in this function.

Sorry for the noise.
sln

On Wed, Apr 25, 2018 at 8:59 AM, arvindY <arvind.yadav.cs@gmail.com> wrote:
>
>
> 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)
>>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe sparclinux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
==============================================
Mr. Shannon Nelson         Parents can't afford to be squeamish.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] sparc: vio: use put_device() instead of kfree()
  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-30 20:10 ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2018-04-30 20:10 UTC (permalink / raw)
  To: arvind.yadav.cs
  Cc: shannon.nelson, jag.raman, liam.merwick, linux-kernel, sparclinux

From: Arvind Yadav <arvind.yadav.cs@gmail.com>
Date: Wed, 25 Apr 2018 20:26:14 +0530

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

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-04-30 20:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2018-04-25 16:38     ` Shannon Nelson
2018-04-30 20:10 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox