From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Greg KH <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Brendan Higgins <brendanhiggins@google.com>,
Randy Dunlap <rdunlap@infradead.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Naresh Kamboju <naresh.kamboju@linaro.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Hans de Goede <hdegoede@redhat.com>,
Rafael Wysocki <rafael.j.wysocki@intel.com>,
linux-kselftest@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Shuah Khan <shuah@kernel.org>,
anders.roxell@linaro.org, lkft-triage@lists.linaro.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: Re: [PATCH v1] kobject: make sure parent is not released before children
Date: Fri, 17 Apr 2020 14:39:56 +0300 [thread overview]
Message-ID: <20200417113956.GA3728594@kuha.fi.intel.com> (raw)
In-Reply-To: <20200415133122.GB3461248@kroah.com>
Hi,
> > > An alternative might be to define something like __kobject_del() doing
> > > everything that kobject_del() does *without* the
> > > kobject_put(kobj->parent).
> > >
> > > Then, kobject_del() could be defined as something like (pseudocode):
> > >
> > > kobject_del(kobj)
> > > {
> > > kobject *perent = kobj->parent;
> > >
> > > __kobject_del(kobj);
> > > kobject_put(parent);
> > > }
> > >
> > > and kobject_cleanup() could call __kobject_del() instead of
> > > kobject_del() and then do the last kobject_put(parent) when it is done
> > > with the child.
> > >
> > > Would that work?
> >
> > I think so. Greg, what do you think?
>
> Hm, maybe. Can someone test it out with the reproducer?
Brendan, or Randy! Can you guys test Rafael's proposal? I think it
would look like this:
diff --git a/lib/kobject.c b/lib/kobject.c
index 83198cb37d8d..2bd631460e18 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -599,14 +599,7 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)
}
EXPORT_SYMBOL_GPL(kobject_move);
-/**
- * kobject_del() - Unlink kobject from hierarchy.
- * @kobj: object.
- *
- * This is the function that should be called to delete an object
- * successfully added via kobject_add().
- */
-void kobject_del(struct kobject *kobj)
+static void __kobject_del(struct kobject *kobj)
{
struct kernfs_node *sd;
const struct kobj_type *ktype;
@@ -625,9 +618,23 @@ void kobject_del(struct kobject *kobj)
kobj->state_in_sysfs = 0;
kobj_kset_leave(kobj);
- kobject_put(kobj->parent);
kobj->parent = NULL;
}
+
+/**
+ * kobject_del() - Unlink kobject from hierarchy.
+ * @kobj: object.
+ *
+ * This is the function that should be called to delete an object
+ * successfully added via kobject_add().
+ */
+void kobject_del(struct kobject *kobj)
+{
+ struct kobject *parent = kobj->parent;
+
+ __kobject_del(kobj);
+ kobject_put(parent);
+}
EXPORT_SYMBOL(kobject_del);
/**
@@ -663,6 +670,7 @@ EXPORT_SYMBOL(kobject_get_unless_zero);
*/
static void kobject_cleanup(struct kobject *kobj)
{
+ struct kobject *parent = kobj->parent;
struct kobj_type *t = get_ktype(kobj);
const char *name = kobj->name;
@@ -684,7 +692,7 @@ static void kobject_cleanup(struct kobject *kobj)
if (kobj->state_in_sysfs) {
pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n",
kobject_name(kobj), kobj);
- kobject_del(kobj);
+ __kobject_del(kobj);
}
if (t && t->release) {
@@ -698,6 +706,8 @@ static void kobject_cleanup(struct kobject *kobj)
pr_debug("kobject: '%s': free name\n", name);
kfree_const(name);
}
+
+ kobject_put(parent);
}
#ifdef CONFIG_DEBUG_KOBJECT_RELEASE
thanks,
--
heikki
next prev parent reply other threads:[~2020-04-17 11:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-14 20:42 [PATCH v1] kobject: make sure parent is not released before children Brendan Higgins
2020-04-14 22:38 ` Randy Dunlap
2020-04-15 6:11 ` Greg KH
2020-04-15 8:46 ` Heikki Krogerus
2020-04-15 9:21 ` Rafael J. Wysocki
2020-04-15 13:10 ` Heikki Krogerus
2020-04-15 13:31 ` Greg KH
2020-04-17 11:39 ` Heikki Krogerus [this message]
2020-04-17 16:08 ` Randy Dunlap
2020-04-20 22:03 ` Brendan Higgins
2020-04-15 9:21 ` Greg KH
2020-04-15 11:25 ` Heikki Krogerus
2020-04-15 12:12 ` Greg KH
2020-04-15 8:18 ` Heikki Krogerus
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=20200417113956.GA3728594@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=anders.roxell@linaro.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=brendanhiggins@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=lkft-triage@lists.linaro.org \
--cc=naresh.kamboju@linaro.org \
--cc=rafael.j.wysocki@intel.com \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sakari.ailus@linux.intel.com \
--cc=sergey.senozhatsky@gmail.com \
--cc=shuah@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