libata: convert the remaining SATA drivers to new init model
[powerpc.git] / lib / kobject.c
index f664551..cecf2fb 100644 (file)
@@ -157,7 +157,7 @@ static void unlink(struct kobject * kobj)
 }
 
 /**
- *     kobject_add - add an object to the hierarchy.
+ *     kobject_shadow_add - add an object to the hierarchy.
  *     @kobj:  object.
  *     @shadow_parent: sysfs directory to add to.
  */
@@ -174,6 +174,7 @@ int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent)
        if (!*kobj->k_name) {
                pr_debug("kobject attempted to be registered with no name!\n");
                WARN_ON(1);
+               kobject_put(kobj);
                return -EINVAL;
        }
        parent = kobject_get(kobj->parent);
@@ -190,8 +191,8 @@ int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent)
 
                list_add_tail(&kobj->entry,&kobj->kset->list);
                spin_unlock(&kobj->kset->list_lock);
+               kobj->parent = parent;
        }
-       kobj->parent = parent;
 
        error = create_dir(kobj, shadow_parent);
        if (error) {
@@ -311,13 +312,43 @@ EXPORT_SYMBOL(kobject_set_name);
 int kobject_rename(struct kobject * kobj, const char *new_name)
 {
        int error = 0;
+       const char *devpath = NULL;
+       char *devpath_string = NULL;
+       char *envp[2];
 
        kobj = kobject_get(kobj);
        if (!kobj)
                return -EINVAL;
        if (!kobj->parent)
                return -EINVAL;
+
+       devpath = kobject_get_path(kobj, GFP_KERNEL);
+       if (!devpath) {
+               error = -ENOMEM;
+               goto out;
+       }
+       devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
+       if (!devpath_string) {
+               error = -ENOMEM;
+               goto out;
+       }
+       sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
+       envp[0] = devpath_string;
+       envp[1] = NULL;
+       /* Note : if we want to send the new name alone, not the full path,
+        * we could probably use kobject_name(kobj); */
+
        error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name);
+
+       /* This function is mostly/only used for network interface.
+        * Some hotplug package track interfaces by their name and
+        * therefore want to know when the name is changed by the user. */
+       if (!error)
+               kobject_uevent_env(kobj, KOBJ_MOVE, envp);
+
+out:
+       kfree(devpath_string);
+       kfree(devpath);
        kobject_put(kobj);
 
        return error;
@@ -488,7 +519,7 @@ static struct kobj_type dir_ktype = {
 };
 
 /**
- *     kobject__kset_add_dir - add sub directory of object.
+ *     kobject_kset_add_dir - add sub directory of object.
  *     @kset:          kset the directory is belongs to.
  *     @parent:        object in which a directory is created.
  *     @name:  directory name.
@@ -514,8 +545,8 @@ struct kobject *kobject_kset_add_dir(struct kset *kset,
        kobject_set_name(k, name);
        ret = kobject_register(k);
        if (ret < 0) {
-               printk(KERN_WARNING "kobject_add_dir: "
-                       "kobject_register error: %d\n", ret);
+               printk(KERN_WARNING "%s: kobject_register error: %d\n",
+                       __func__, ret);
                kobject_del(k);
                return NULL;
        }
@@ -523,6 +554,13 @@ struct kobject *kobject_kset_add_dir(struct kset *kset,
        return k;
 }
 
+/**
+ *     kobject_add_dir - add sub directory of object.
+ *     @parent:        object in which a directory is created.
+ *     @name:  directory name.
+ *
+ *     Add a plain directory object as child of given object.
+ */
 struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
 {
        return kobject_kset_add_dir(NULL, parent, name);
@@ -621,7 +659,6 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
 
 void subsystem_init(struct subsystem * s)
 {
-       init_rwsem(&s->rwsem);
        kset_init(&s->kset);
 }
 
@@ -630,8 +667,7 @@ void subsystem_init(struct subsystem * s)
  *     @s:     the subsystem we're registering.
  *
  *     Once we register the subsystem, we want to make sure that 
- *     the kset points back to this subsystem for correct usage of 
- *     the rwsem. 
+ *     the kset points back to this subsystem.
  */
 
 int subsystem_register(struct subsystem * s)