]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - include/linux/kobject.h
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / include / linux / kobject.h
index 2ec53f8a494a9df1a5e65d3cfc688dbaf71656e2..c33b21267e21f75ad763706ce9782c76c7ae90f9 100644 (file)
 #include <linux/bug.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
-#include <linux/kref.h>
 #include <linux/sysfs.h>
 #include <linux/types.h>
-#include <linux/wait.h>
 #include <linux/workqueue.h>
 
 struct kset;
@@ -31,7 +29,7 @@ struct kset;
 struct kobj_type {
        void (*release)(struct kobject *kobj);
        const struct sysfs_ops *sysfs_ops;
-       struct attribute **default_attrs;
+       const struct attribute_group **default_groups;
        const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
        const void *(*namespace)(struct kobject *kobj);
 };
@@ -50,9 +48,9 @@ struct kobj_attribute {
 struct kobject {
        struct kobject          *parent;
        struct kset             *kset;
-       struct kobj_type        *ktype;
+       const struct kobj_type  *ktype;
        struct kernfs_node      *sd; /* sysfs directory entry */
-       struct kref             kref;
+       atomic_t                ref;
        unsigned int state_initialized:1;
        unsigned int state_in_sysfs:1;
        unsigned int state_add_uevent_sent:1;
@@ -64,18 +62,13 @@ struct kset {
        struct kobject          kobj;
 };
 
-static inline struct kobj_type *get_ktype(struct kobject *kobj)
-{
-       return kobj->ktype;
-}
-
 #define kobject_add(...)       0
 
-static inline void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
+static inline void kobject_init(struct kobject *kobj, const struct kobj_type *ktype)
 {
        memset(kobj, 0, sizeof(*kobj));
 
-       kref_init(&kobj->kref);
+       atomic_set(&kobj->ref, 1);
        kobj->ktype = ktype;
        kobj->state_initialized = 1;
 }
@@ -84,7 +77,7 @@ static inline void kobject_del(struct kobject *kobj);
 
 static inline void kobject_cleanup(struct kobject *kobj)
 {
-       struct kobj_type *t = get_ktype(kobj);
+       const struct kobj_type *t = kobj->ktype;
 
        /* remove from sysfs if the caller did not do it */
        if (kobj->state_in_sysfs)
@@ -94,29 +87,20 @@ static inline void kobject_cleanup(struct kobject *kobj)
                t->release(kobj);
 }
 
-static inline void kobject_release(struct kref *kref)
-{
-       struct kobject *kobj = container_of(kref, struct kobject, kref);
-
-       kobject_cleanup(kobj);
-}
-
 static inline void kobject_put(struct kobject *kobj)
 {
        BUG_ON(!kobj);
        BUG_ON(!kobj->state_initialized);
 
-       kref_put(&kobj->kref, kobject_release);
+       if (atomic_dec_and_test(&kobj->ref))
+               kobject_cleanup(kobj);
 }
 
 static inline void kobject_del(struct kobject *kobj)
 {
-       struct kernfs_node *sd;
-
        if (!kobj)
                return;
 
-       sd = kobj->sd;
        kobj->state_in_sysfs = 0;
 #if 0
        kobj_kset_leave(kobj);
@@ -130,11 +114,14 @@ static inline struct kobject *kobject_get(struct kobject *kobj)
        BUG_ON(!kobj);
        BUG_ON(!kobj->state_initialized);
 
-       kref_get(&kobj->kref);
+       atomic_inc(&kobj->ref);
        return kobj;
 }
 
-static inline void kset_unregister(struct kset *kset) {}
+static inline void kset_unregister(struct kset *kset)
+{
+       kfree(kset);
+}
 
 #define kset_create_and_add(_name, _u, _parent)                                \
        ((struct kset *) kzalloc(sizeof(struct kset), GFP_KERNEL))