]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - lib/kobject.c
[ARM] 4915/1: AT91: Update defconfigs (Part 2)
[linux-2.6-omap-h63xx.git] / lib / kobject.c
index 462946ee3e64c14dc28f9c420f18a1273eb92c0a..0d03252f87a8535db2a9fe00632560c6fa337f24 100644 (file)
 #include <linux/stat.h>
 #include <linux/slab.h>
 
-/**
- *     populate_dir - populate directory with attributes.
- *     @kobj:  object we're working on.
- *
- *     Most subsystems have a set of default attributes that 
- *     are associated with an object that registers with them.
- *     This is a helper called during object registration that 
- *     loops through the default attributes of the subsystem 
- *     and creates attributes files for them in sysfs.
+/*
+ * populate_dir - populate directory with attributes.
+ * @kobj: object we're working on.
  *
+ * Most subsystems have a set of default attributes that are associated
+ * with an object that registers with them.  This is a helper called during
+ * object registration that loops through the default attributes of the
+ * subsystem and creates attributes files for them in sysfs.
  */
-
-static int populate_dir(struct kobject * kobj)
+static int populate_dir(struct kobject *kobj)
 {
-       struct kobj_type * t = get_ktype(kobj);
-       struct attribute * attr;
+       struct kobj_type *t = get_ktype(kobj);
+       struct attribute *attr;
        int error = 0;
        int i;
-       
+
        if (t && t->default_attrs) {
                for (i = 0; (attr = t->default_attrs[i]) != NULL; i++) {
-                       if ((error = sysfs_create_file(kobj,attr)))
+                       error = sysfs_create_file(kobj, attr);
+                       if (error)
                                break;
                }
        }
        return error;
 }
 
-static int create_dir(struct kobject * kobj)
+static int create_dir(struct kobject *kobj)
 {
        int error = 0;
        if (kobject_name(kobj)) {
                error = sysfs_create_dir(kobj);
                if (!error) {
-                       if ((error = populate_dir(kobj)))
+                       error = populate_dir(kobj);
+                       if (error)
                                sysfs_remove_dir(kobj);
                }
        }
        return error;
 }
 
-static inline struct kobject * to_kobj(struct list_head * entry)
+static inline struct kobject *to_kobj(struct list_head *entry)
 {
-       return container_of(entry,struct kobject,entry);
+       return container_of(entry, struct kobject, entry);
 }
 
 static int get_kobj_path_length(struct kobject *kobj)
 {
        int length = 1;
-       struct kobject * parent = kobj;
+       struct kobject *parent = kobj;
 
-       /* walk up the ancestors until we hit the one pointing to the 
+       /* walk up the ancestors until we hit the one pointing to the
         * root.
         * Add 1 to strlen for leading '/' of each level.
         */
@@ -84,19 +83,19 @@ static int get_kobj_path_length(struct kobject *kobj)
 
 static void fill_kobj_path(struct kobject *kobj, char *path, int length)
 {
-       struct kobject * parent;
+       struct kobject *parent;
 
        --length;
        for (parent = kobj; parent; parent = parent->parent) {
                int cur = strlen(kobject_name(parent));
                /* back up enough to print this name with '/' */
                length -= cur;
-               strncpy (path + length, kobject_name(parent), cur);
+               strncpy(path + length, kobject_name(parent), cur);
                *(path + --length) = '/';
        }
 
        pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
-                kobj, __FUNCTION__,path);
+                kobj, __FUNCTION__, path);
 }
 
 /**
@@ -148,24 +147,28 @@ static void kobj_kset_leave(struct kobject *kobj)
        kset_put(kobj->kset);
 }
 
-static void kobject_init_internal(struct kobject * kobj)
+static void kobject_init_internal(struct kobject *kobj)
 {
        if (!kobj)
                return;
        kref_init(&kobj->kref);
        INIT_LIST_HEAD(&kobj->entry);
+       kobj->state_in_sysfs = 0;
+       kobj->state_add_uevent_sent = 0;
+       kobj->state_remove_uevent_sent = 0;
+       kobj->state_initialized = 1;
 }
 
 
 static int kobject_add_internal(struct kobject *kobj)
 {
        int error = 0;
-       struct kobject * parent;
+       struct kobject *parent;
 
        if (!kobj)
                return -ENOENT;
 
-       if (!kobj->k_name || !kobj->k_name[0]) {
+       if (!kobj->name || !kobj->name[0]) {
                pr_debug("kobject: (%p): attempted to be registered with empty "
                         "name!\n", kobj);
                WARN_ON(1);
@@ -185,7 +188,7 @@ static int kobject_add_internal(struct kobject *kobj)
        pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
                 kobject_name(kobj), kobj, __FUNCTION__,
                 parent ? kobject_name(parent) : "<NULL>",
-                kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
+                kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
 
        error = create_dir(kobj);
        if (error) {
@@ -228,13 +231,11 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
        if (!name)
                return -ENOMEM;
 
-
        /* Free the old name, if necessary. */
-       kfree(kobj->k_name);
+       kfree(kobj->name);
 
        /* Now, set the new name */
-       kobj->k_name = name;
-       kobj->state_name_set = 1;
+       kobj->name = name;
 
        return 0;
 }
@@ -292,14 +293,8 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
                dump_stack();
        }
 
-       kref_init(&kobj->kref);
-       INIT_LIST_HEAD(&kobj->entry);
+       kobject_init_internal(kobj);
        kobj->ktype = ktype;
-       kobj->state_name_set = 0;
-       kobj->state_in_sysfs = 0;
-       kobj->state_add_uevent_sent = 0;
-       kobj->state_remove_uevent_sent = 0;
-       kobj->state_initialized = 1;
        return;
 
 error:
@@ -402,12 +397,11 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
 EXPORT_SYMBOL_GPL(kobject_init_and_add);
 
 /**
- *     kobject_rename - change the name of an object
- *     @kobj:  object in question.
- *     @new_name: object's new name
+ * kobject_rename - change the name of an object
+ * @kobj: object in question.
+ * @new_name: object's new name
  */
-
-int kobject_rename(struct kobject * kobj, const char *new_name)
+int kobject_rename(struct kobject *kobj, const char *new_name)
 {
        int error = 0;
        const char *devpath = NULL;
@@ -464,11 +458,10 @@ out:
 }
 
 /**
- *     kobject_move - move object to another parent
- *     @kobj:  object in question.
- *     @new_parent: object's new parent (can be NULL)
+ * kobject_move - move object to another parent
+ * @kobj: object in question.
+ * @new_parent: object's new parent (can be NULL)
  */
-
 int kobject_move(struct kobject *kobj, struct kobject *new_parent)
 {
        int error;
@@ -516,11 +509,10 @@ out:
 }
 
 /**
- *     kobject_del - unlink kobject from hierarchy.
- *     @kobj:  object.
+ * kobject_del - unlink kobject from hierarchy.
+ * @kobj: object.
  */
-
-void kobject_del(struct kobject * kobj)
+void kobject_del(struct kobject *kobj)
 {
        if (!kobj)
                return;
@@ -533,27 +525,10 @@ void kobject_del(struct kobject * kobj)
 }
 
 /**
- *     kobject_unregister - remove object from hierarchy and decrement refcount.
- *     @kobj:  object going away.
+ * kobject_get - increment refcount for object.
+ * @kobj: object.
  */
-
-void kobject_unregister(struct kobject * kobj)
-{
-       if (!kobj)
-               return;
-       pr_debug("kobject: '%s' (%p): %s\n",
-                kobject_name(kobj), kobj, __FUNCTION__);
-       kobject_uevent(kobj, KOBJ_REMOVE);
-       kobject_del(kobj);
-       kobject_put(kobj);
-}
-
-/**
- *     kobject_get - increment refcount for object.
- *     @kobj:  object.
- */
-
-struct kobject * kobject_get(struct kobject * kobj)
+struct kobject *kobject_get(struct kobject *kobj)
 {
        if (kobj)
                kref_get(&kobj->kref);
@@ -567,8 +542,7 @@ struct kobject * kobject_get(struct kobject * kobj)
 static void kobject_cleanup(struct kobject *kobj)
 {
        struct kobj_type *t = get_ktype(kobj);
-       const char *name = kobj->k_name;
-       int name_set = kobj->state_name_set;
+       const char *name = kobj->name;
 
        pr_debug("kobject: '%s' (%p): %s\n",
                 kobject_name(kobj), kobj, __FUNCTION__);
@@ -599,7 +573,7 @@ static void kobject_cleanup(struct kobject *kobj)
        }
 
        /* free name if we allocated it */
-       if (name_set && name) {
+       if (name) {
                pr_debug("kobject: '%s': free name\n", name);
                kfree(name);
        }
@@ -611,12 +585,12 @@ static void kobject_release(struct kref *kref)
 }
 
 /**
- *     kobject_put - decrement refcount for object.
- *     @kobj:  object.
+ * kobject_put - decrement refcount for object.
+ * @kobj: object.
  *
- *     Decrement the refcount, and if 0, call kobject_cleanup().
+ * Decrement the refcount, and if 0, call kobject_cleanup().
  */
-void kobject_put(struct kobject * kobj)
+void kobject_put(struct kobject *kobj)
 {
        if (kobj)
                kref_put(&kobj->kref, kobject_release);
@@ -662,7 +636,7 @@ struct kobject *kobject_create(void)
  * @name: the name for the kset
  * @parent: the parent kobject of this kobject, if any.
  *
- * This function creates a kset structure dynamically and registers it
+ * This function creates a kobject structure dynamically and registers it
  * with sysfs.  When you are finished with this structure, call
  * kobject_put() and the structure will be dynamically freed when
  * it is no longer being used.
@@ -690,11 +664,10 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
 EXPORT_SYMBOL_GPL(kobject_create_and_add);
 
 /**
- *     kset_init - initialize a kset for use
- *     @k:     kset 
+ * kset_init - initialize a kset for use
+ * @k: kset
  */
-
-void kset_init(struct kset * k)
+void kset_init(struct kset *k)
 {
        kobject_init_internal(&k->kobj);
        INIT_LIST_HEAD(&k->list);
@@ -732,11 +705,10 @@ struct sysfs_ops kobj_sysfs_ops = {
 };
 
 /**
- *     kset_register - initialize and add a kset.
- *     @k:     kset.
+ * kset_register - initialize and add a kset.
+ * @k: kset.
  */
-
-int kset_register(struct kset * k)
+int kset_register(struct kset *k)
 {
        int err;
 
@@ -751,39 +723,35 @@ int kset_register(struct kset * k)
        return 0;
 }
 
-
 /**
- *     kset_unregister - remove a kset.
- *     @k:     kset.
+ * kset_unregister - remove a kset.
+ * @k: kset.
  */
-
-void kset_unregister(struct kset * k)
+void kset_unregister(struct kset *k)
 {
        if (!k)
                return;
        kobject_put(&k->kobj);
 }
 
-
 /**
- *     kset_find_obj - search for object in kset.
- *     @kset:  kset we're looking in.
- *     @name:  object's name.
+ * kset_find_obj - search for object in kset.
+ * @kset: kset we're looking in.
+ * @name: object's name.
  *
- *     Lock kset via @kset->subsys, and iterate over @kset->list,
- *     looking for a matching kobject. If matching object is found
- *     take a reference and return the object.
+ * Lock kset via @kset->subsys, and iterate over @kset->list,
+ * looking for a matching kobject. If matching object is found
+ * take a reference and return the object.
  */
-
-struct kobject * kset_find_obj(struct kset * kset, const char * name)
+struct kobject *kset_find_obj(struct kset *kset, const char *name)
 {
-       struct list_head * entry;
-       struct kobject * ret = NULL;
+       struct list_head *entry;
+       struct kobject *ret = NULL;
 
        spin_lock(&kset->list_lock);
-       list_for_each(entry,&kset->list) {
-               struct kobject * k = to_kobj(entry);
-               if (kobject_name(k) && !strcmp(kobject_name(k),name)) {
+       list_for_each(entry, &kset->list) {
+               struct kobject *k = to_kobj(entry);
+               if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
                        ret = kobject_get(k);
                        break;
                }
@@ -877,7 +845,6 @@ struct kset *kset_create_and_add(const char *name,
 }
 EXPORT_SYMBOL_GPL(kset_create_and_add);
 
-EXPORT_SYMBOL(kobject_unregister);
 EXPORT_SYMBOL(kobject_get);
 EXPORT_SYMBOL(kobject_put);
 EXPORT_SYMBOL(kobject_del);