Re: [PATCH RFD] alternative kobject release wait mechanism



Here's a patch to do what I mentioned earlier. Not tested -- it may
expose some existing bugs. It may even break something, but I'm not aware
of anything that depends on it explicitly.

Greg, do you know of anything in particular that depends on a kobjects not
being released before their children are released?

This is meant to be used without any of the other changes Cornelia and I
have posted. Although it might not hurt to have them all present...

Alan Stern



Index: usb-2.6/lib/kobject.c
===================================================================
--- usb-2.6.orig/lib/kobject.c
+++ usb-2.6/lib/kobject.c
@@ -192,12 +192,15 @@ void kobject_init(struct kobject * kobj)

static void unlink(struct kobject * kobj)
{
+ struct kobject *parent = kobj->parent;
+
if (kobj->kset) {
spin_lock(&kobj->kset->list_lock);
list_del_init(&kobj->entry);
spin_unlock(&kobj->kset->list_lock);
}
kobject_put(kobj);
+ kobject_put(parent);
}

/**
@@ -241,7 +244,6 @@ int kobject_shadow_add(struct kobject *
if (error) {
/* unlink does the kobject_put() for us */
unlink(kobj);
- kobject_put(parent);

/* be noisy on error issues */
if (error == -EEXIST)
@@ -489,7 +491,6 @@ void kobject_cleanup(struct kobject * ko
{
struct kobj_type * t = get_ktype(kobj);
struct kset * s = kobj->kset;
- struct kobject * parent = kobj->parent;

pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
if (kobj->k_name != kobj->name)
@@ -505,7 +506,6 @@ void kobject_cleanup(struct kobject * ko

if (s)
kset_put(s);
- kobject_put(parent);
}

static void kobject_release(struct kref *kref)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • [PATCH] kref docs, take 2
    ... +The kref can occur anywhere within the data structure. ... If you already have a valid pointer to a kref-ed structure (the ... refcount cannot go to zero) you may do this without a lock. ... +static void put_entry ...
    (Linux-Kernel)
  • Documentation for krefs
    ... +The kref can occur anywhere within the data structure. ... If you already have a valid pointer to a kref-ed structure (the ... refcount cannot go to zero) you may do this without a lock. ... +static void put_entry ...
    (Linux-Kernel)
  • [PATCH] Remove completion from struct klist_node
    ... a single list of klist nodes which are pending deletion and scan them. ... klist_init - Initialize a klist structure. ... static void klist_release(struct kref *kref) ...
    (Linux-Kernel)
  • Re: [PATCH] Remove completion from struct klist_node
    ... a single list of klist nodes which are pending deletion and scan them. ... klist_init - Initialize a klist structure. ... static void klist_release(struct kref *kref) ...
    (Linux-Kernel)
  • [PATCH] convert usb-serial core to use kref instead of kobject
    ... > kobjects to using krefs instead. ... And here is that patch. ... -static void destroy_serial (struct kobject *kobj) ... +static void destroy_serial(struct kref *kref) ...
    (Linux-Kernel)