Skip to content

Commit 35a5fe6

Browse files
bjorn-helgaasgregkh
authored andcommitted
kobject: remove kset from sysfs immediately in kset_unregister()
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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 89c86a6 commit 35a5fe6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Documentation/kobject.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ kset use:
342342

343343
When you are finished with the kset, call:
344344
void kset_unregister(struct kset *kset);
345-
to destroy it.
345+
to destroy it. This removes the kset from sysfs and decrements its reference
346+
count. When the reference count goes to zero, the kset will be released.
347+
Because other references to the kset may still exist, the release may happen
348+
after kset_unregister() returns.
346349

347350
An example of using a kset can be seen in the
348351
samples/kobject/kset-example.c file in the kernel tree.

lib/kobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ void kset_unregister(struct kset *k)
855855
{
856856
if (!k)
857857
return;
858+
kobject_del(&k->kobj);
858859
kobject_put(&k->kobj);
859860
}
860861

0 commit comments

Comments
 (0)