From: Bjorn Helgaas <bhelgaas@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Veaceslav Falico <vfalico@redhat.com>,
Russell King <linux@arm.linux.org.uk>,
Neil Horman <nhorman@tuxdriver.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Zdenek Kabelac <zkabelac@redhat.com>
Subject: [PATCH v2 2/2] kobject: remove kset from sysfs immediately in kset_unregister()
Date: Thu, 05 Dec 2013 17:38:00 -0700 [thread overview]
Message-ID: <20131206003759.28684.63772.stgit@bhelgaas-glaptop.roam.corp.google.com> (raw)
In-Reply-To: <20131206003508.28684.1337.stgit@bhelgaas-glaptop.roam.corp.google.com>
There's no "unlink from sysfs" interface for ksets, so I think callers of
kset_unregister() expect the kset to be removed from sysfs immediately,
without waiting for the last reference to be released.
This patch makes the sysfs removal happen immediately, so the caller may
create a new kset with the same name as soon as kset_unregister() returns.
Without this, every caller has to call "kobject_del(&kset->kobj)" first
unless it knows it will never create a new kset with the same name.
This sometimes shows up on module unload and reload, where the reload fails
because it tries to create a kobject with the same name as one from the
original load that still exists. CONFIG_DEBUG_KOBJECT_RELEASE=y makes this
problem easier to hit.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
Documentation/kobject.txt | 5 ++++-
lib/kobject.c | 1 +
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
index c5182bb2c16c..f87241dfed87 100644
--- a/Documentation/kobject.txt
+++ b/Documentation/kobject.txt
@@ -342,7 +342,10 @@ kset use:
When you are finished with the kset, call:
void kset_unregister(struct kset *kset);
-to destroy it.
+to destroy it. This removes the kset from sysfs and decrements its reference
+count. When the reference count goes to zero, the kset will be released.
+Because other references to the kset may still exist, the release may happen
+after kset_unregister() returns.
An example of using a kset can be seen in the
samples/kobject/kset-example.c file in the kernel tree.
diff --git a/lib/kobject.c b/lib/kobject.c
index bc73312ac797..40e3b2c0abae 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -757,6 +757,7 @@ void kset_unregister(struct kset *k)
{
if (!k)
return;
+ kobject_del(&k->kobj);
kobject_put(&k->kobj);
}
prev parent reply other threads:[~2013-12-06 0:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-06 0:37 [PATCH v2 0/2] Remove ksets from sysfs eagerly Bjorn Helgaas
2013-12-06 0:37 ` [PATCH v2 1/2] kobject: delay kobject release for random time Bjorn Helgaas
2013-12-06 0:38 ` Bjorn Helgaas [this message]
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=20131206003759.28684.63772.stgit@bhelgaas-glaptop.roam.corp.google.com \
--to=bhelgaas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=nhorman@tuxdriver.com \
--cc=vfalico@redhat.com \
--cc=zkabelac@redhat.com \
/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
all inboxes | Powered by JetHome®