* [PATCH] ssb:: use put_device() if device_register fail
@ 2018-03-07 10:01 Arvind Yadav
2018-03-07 16:47 ` Michael Büsch
0 siblings, 1 reply; 5+ messages in thread
From: Arvind Yadav @ 2018-03-07 10:01 UTC (permalink / raw)
To: m; +Cc: linux-kernel, linux-wireless
if device_register() returned an error! Always use put_device()
to give up the reference initialized.
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
drivers/ssb/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 65420a9..c4449e0 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -521,6 +521,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
ssb_err("Could not register %s\n", dev_name(dev));
/* Set dev to NULL to not unregister
* dev on error unwinding. */
+ put_device(dev);
sdev->dev = NULL;
kfree(devwrap);
goto error;
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ssb:: use put_device() if device_register fail
2018-03-07 10:01 [PATCH] ssb:: use put_device() if device_register fail Arvind Yadav
@ 2018-03-07 16:47 ` Michael Büsch
2018-03-07 17:16 ` arvindY
0 siblings, 1 reply; 5+ messages in thread
From: Michael Büsch @ 2018-03-07 16:47 UTC (permalink / raw)
To: Arvind Yadav; +Cc: linux-kernel, linux-wireless
[-- Attachment #1: Type: text/plain, Size: 954 bytes --]
On Wed, 7 Mar 2018 15:31:30 +0530
Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:
> if device_register() returned an error! Always use put_device()
> to give up the reference initialized.
>
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/ssb/main.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
> index 65420a9..c4449e0 100644
> --- a/drivers/ssb/main.c
> +++ b/drivers/ssb/main.c
> @@ -521,6 +521,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
> ssb_err("Could not register %s\n", dev_name(dev));
> /* Set dev to NULL to not unregister
> * dev on error unwinding. */
> + put_device(dev);
> sdev->dev = NULL;
> kfree(devwrap);
> goto error;
I don't think this is correct.
The dev structure is allocated as part of devwrap, which is freed here.
Why do you think we need put_device here?
--
Michael
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ssb:: use put_device() if device_register fail
2018-03-07 16:47 ` Michael Büsch
@ 2018-03-07 17:16 ` arvindY
2018-03-07 17:38 ` Michael Büsch
0 siblings, 1 reply; 5+ messages in thread
From: arvindY @ 2018-03-07 17:16 UTC (permalink / raw)
To: Michael Büsch; +Cc: linux-kernel, linux-wireless
On Wednesday 07 March 2018 10:17 PM, Michael Büsch wrote:
> On Wed, 7 Mar 2018 15:31:30 +0530
> Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:
>
>> if device_register() returned an error! Always use put_device()
>> to give up the reference initialized.
>>
>> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
>> ---
>> drivers/ssb/main.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
>> index 65420a9..c4449e0 100644
>> --- a/drivers/ssb/main.c
>> +++ b/drivers/ssb/main.c
>> @@ -521,6 +521,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
>> ssb_err("Could not register %s\n", dev_name(dev));
>> /* Set dev to NULL to not unregister
>> * dev on error unwinding. */
>> + put_device(dev);
>> sdev->dev = NULL;
>> kfree(devwrap);
>> goto error;
>
> I don't think this is correct.
> The dev structure is allocated as part of devwrap, which is freed here.
>
> Why do you think we need put_device here?
>
Yes this patch is not correct, We must not use kfree() after you called
device_register() (even
if it was not successful!) -- see the comment for device_register().
I will delete kfree() and send updated patch.
~arvind
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ssb:: use put_device() if device_register fail
2018-03-07 17:16 ` arvindY
@ 2018-03-07 17:38 ` Michael Büsch
2018-03-07 18:22 ` arvindY
0 siblings, 1 reply; 5+ messages in thread
From: Michael Büsch @ 2018-03-07 17:38 UTC (permalink / raw)
To: arvindY; +Cc: linux-kernel, linux-wireless
[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]
On Wed, 7 Mar 2018 22:46:14 +0530
arvindY <arvind.yadav.cs@gmail.com> wrote:
> >> diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
> >> index 65420a9..c4449e0 100644
> >> --- a/drivers/ssb/main.c
> >> +++ b/drivers/ssb/main.c
> >> @@ -521,6 +521,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
> >> ssb_err("Could not register %s\n", dev_name(dev));
> >> /* Set dev to NULL to not unregister
> >> * dev on error unwinding. */
> >> + put_device(dev);
> >> sdev->dev = NULL;
> >> kfree(devwrap);
> >> goto error;
> >
> > I don't think this is correct.
> > The dev structure is allocated as part of devwrap, which is freed here.
> >
> > Why do you think we need put_device here?
> >
> Yes this patch is not correct, We must not use kfree() after you called
> device_register() (even
> if it was not successful!) -- see the comment for device_register().
> I will delete kfree() and send updated patch.
Is device_put() going to call ssb_release_dev() to free the structure?
Can you please elaborate on why device_put() must be used? The comment
is not really of any use here.
--
Michael
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ssb:: use put_device() if device_register fail
2018-03-07 17:38 ` Michael Büsch
@ 2018-03-07 18:22 ` arvindY
0 siblings, 0 replies; 5+ messages in thread
From: arvindY @ 2018-03-07 18:22 UTC (permalink / raw)
To: Michael Büsch; +Cc: linux-kernel, linux-wireless
On Wednesday 07 March 2018 11:08 PM, Michael Büsch wrote:
> On Wed, 7 Mar 2018 22:46:14 +0530
> arvindY <arvind.yadav.cs@gmail.com> wrote:
>>>> diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
>>>> index 65420a9..c4449e0 100644
>>>> --- a/drivers/ssb/main.c
>>>> +++ b/drivers/ssb/main.c
>>>> @@ -521,6 +521,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
>>>> ssb_err("Could not register %s\n", dev_name(dev));
>>>> /* Set dev to NULL to not unregister
>>>> * dev on error unwinding. */
>>>> + put_device(dev);
>>>> sdev->dev = NULL;
>>>> kfree(devwrap);
>>>> goto error;
>>> I don't think this is correct.
>>> The dev structure is allocated as part of devwrap, which is freed here.
>>>
>>> Why do you think we need put_device here?
>>>
>> Yes this patch is not correct, We must not use kfree() after you called
>> device_register() (even
>> if it was not successful!) -- see the comment for device_register().
>> I will delete kfree() and send updated patch.
>
> Is device_put() going to call ssb_release_dev() to free the structure?
>
> Can you please elaborate on why device_put() must be used? The comment
> is not really of any use here.
>
put_device() will call kobject_put(). By calling this, The kobject core
will automatically
clean up all of the memory allocated with the kobject. Internally
kobject_put() will call
kobject_cleanup() which is responsible to call 'dev -> release' and also
free other
kobject resources. we should always avoid kfree() if device_register()
returned an error.
Otherwise it'll not do clean up of other kobject resources.
~arvind
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-03-07 18:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07 10:01 [PATCH] ssb:: use put_device() if device_register fail Arvind Yadav
2018-03-07 16:47 ` Michael Büsch
2018-03-07 17:16 ` arvindY
2018-03-07 17:38 ` Michael Büsch
2018-03-07 18:22 ` arvindY
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).