From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: kobj->state_initialized is never set to 0
Date: Fri, 20 Jul 2018 20:39:07 +0200 [thread overview]
Message-ID: <20180720183907.GA8061@kroah.com> (raw)
In-Reply-To: <CAPW4XYai0qOy+6T8hP9A3QgG5PCfYHo6pp=U-HOk7-zFuUosiA@mail.gmail.com>
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
next prev parent reply other threads:[~2018-07-20 18:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-20 18:33 kobj->state_initialized is never set to 0 Helen Koike
2018-07-20 18:39 ` Greg KH [this message]
2018-08-10 16:39 ` Helen Koike
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=20180720183907.GA8061@kroah.com \
--to=greg@kroah.com \
--cc=kernelnewbies@lists.kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).