return a->store ? a->store(ls, buf, len) : len;
 }
 
+static void lockspace_kobj_release(struct kobject *k)
+{
+       struct dlm_ls *ls  = container_of(k, struct dlm_ls, ls_kobj);
+       kfree(ls);
+}
+
 static struct sysfs_ops dlm_attr_ops = {
        .show  = dlm_attr_show,
        .store = dlm_attr_store,
 static struct kobj_type dlm_ktype = {
        .default_attrs = dlm_attrs,
        .sysfs_ops     = &dlm_attr_ops,
+       .release       = lockspace_kobj_release,
 };
 
 static struct kset dlm_kset = {
        dlm_clear_members_gone(ls);
        kfree(ls->ls_node_array);
        kobject_unregister(&ls->ls_kobj);
-       kfree(ls);
+        /* The ls structure will be freed when the kobject is done with */
 
        mutex_lock(&ls_lock);
        ls_count--;