kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* kobj->state_initialized is never set to 0
@ 2018-07-20 18:33 Helen Koike
  2018-07-20 18:39 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Helen Koike @ 2018-07-20 18:33 UTC (permalink / raw)
  To: kernelnewbies

Hi,

I am simulating hotplugging a platform device (to the
media/platform/vimc driver), so I register it using
platform_device_register, then I unregister it with
platform_device_unregister, then I register it again, but the code
doesn't allow me to register something that was registered before due
to this line:

    https://github.com/torvalds/linux/blob/master/lib/kobject.c#L334

The variable kobj->state_initialized is set to 1 at

    https://github.com/torvalds/linux/blob/master/lib/kobject.c#L194

but it is never set to 0 again.

Is this how it is supposed to work? Or kobj->state_initialized is set
to 0 somewhere else I couldn't find?

Thanks
Helen

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

* kobj->state_initialized is never set to 0
  2018-07-20 18:33 kobj->state_initialized is never set to 0 Helen Koike
@ 2018-07-20 18:39 ` Greg KH
  2018-08-10 16:39   ` Helen Koike
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2018-07-20 18:39 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Jul 20, 2018 at 03:33:22PM -0300, Helen Koike wrote:
> Hi,
> 
> I am simulating hotplugging a platform device (to the
> media/platform/vimc driver), so I register it using
> platform_device_register, then I unregister it with
> platform_device_unregister, then I register it again, but the code
> doesn't allow me to register something that was registered before due
> to this line:
> 
>     https://github.com/torvalds/linux/blob/master/lib/kobject.c#L334
> 
> The variable kobj->state_initialized is set to 1 at
> 
>     https://github.com/torvalds/linux/blob/master/lib/kobject.c#L194
> 
> but it is never set to 0 again.

Yes, do not do that, that is why we wrote that code.  Never "recycle" a
struct device, or a kobject, as you never really know if it is still in
use or not.  That is why it needs to be dynamically created, not
statically created.

> Is this how it is supposed to work? Or kobj->state_initialized is set
> to 0 somewhere else I couldn't find?

Nope, don't do this please.  Again, never recycle these objects, bad
things will happen as the code is not designed to do that for good
reasons (think object lifetimes, you do not control them fully, other
things do which you have no control over.)

hope this helps,

greg k-h

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

* kobj->state_initialized is never set to 0
  2018-07-20 18:39 ` Greg KH
@ 2018-08-10 16:39   ` Helen Koike
  0 siblings, 0 replies; 3+ messages in thread
From: Helen Koike @ 2018-08-10 16:39 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Jul 20, 2018 at 3:39 PM, Greg KH <greg@kroah.com> wrote:
> On Fri, Jul 20, 2018 at 03:33:22PM -0300, Helen Koike wrote:
>> Hi,
>>
>> I am simulating hotplugging a platform device (to the
>> media/platform/vimc driver), so I register it using
>> platform_device_register, then I unregister it with
>> platform_device_unregister, then I register it again, but the code
>> doesn't allow me to register something that was registered before due
>> to this line:
>>
>>     https://github.com/torvalds/linux/blob/master/lib/kobject.c#L334
>>
>> The variable kobj->state_initialized is set to 1 at
>>
>>     https://github.com/torvalds/linux/blob/master/lib/kobject.c#L194
>>
>> but it is never set to 0 again.
>
> Yes, do not do that, that is why we wrote that code.  Never "recycle" a
> struct device, or a kobject, as you never really know if it is still in
> use or not.  That is why it needs to be dynamically created, not
> statically created.
>
>> Is this how it is supposed to work? Or kobj->state_initialized is set
>> to 0 somewhere else I couldn't find?
>
> Nope, don't do this please.  Again, never recycle these objects, bad
> things will happen as the code is not designed to do that for good
> reasons (think object lifetimes, you do not control them fully, other
> things do which you have no control over.)
>
> hope this helps,
>
> greg k-h

Yes, this helps a lot, thank you!

Helen

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

end of thread, other threads:[~2018-08-10 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-20 18:33 kobj->state_initialized is never set to 0 Helen Koike
2018-07-20 18:39 ` Greg KH
2018-08-10 16:39   ` Helen Koike

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