]> err.no Git - linux-2.6/blobdiff - fs/sysfs/dir.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc
[linux-2.6] / fs / sysfs / dir.c
index aee966c44aacd1a0c7c89847cca9d0966595f62b..83e76b3813c9af674fb2c6fda9c2f891c89e0964 100644 (file)
@@ -361,20 +361,20 @@ static struct dentry_operations sysfs_dentry_ops = {
 struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
 {
        char *dup_name = NULL;
-       struct sysfs_dirent *sd = NULL;
+       struct sysfs_dirent *sd;
 
        if (type & SYSFS_COPY_NAME) {
                name = dup_name = kstrdup(name, GFP_KERNEL);
                if (!name)
-                       goto err_out;
+                       return NULL;
        }
 
        sd = kmem_cache_zalloc(sysfs_dir_cachep, GFP_KERNEL);
        if (!sd)
-               goto err_out;
+               goto err_out1;
 
        if (sysfs_alloc_ino(&sd->s_ino))
-               goto err_out;
+               goto err_out2;
 
        atomic_set(&sd->s_count, 1);
        atomic_set(&sd->s_active, 0);
@@ -386,9 +386,10 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
 
        return sd;
 
- err_out:
-       kfree(dup_name);
+ err_out2:
        kmem_cache_free(sysfs_dir_cachep, sd);
+ err_out1:
+       kfree(dup_name);
        return NULL;
 }
 
@@ -698,17 +699,19 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
 
        /* link in */
        sysfs_addrm_start(&acxt, parent_sd);
+
        if (!sysfs_find_dirent(parent_sd, name)) {
                sysfs_add_one(&acxt, sd);
                sysfs_link_sibling(sd);
        }
-       if (sysfs_addrm_finish(&acxt)) {
-               *p_sd = sd;
-               return 0;
+
+       if (!sysfs_addrm_finish(&acxt)) {
+               sysfs_put(sd);
+               return -EEXIST;
        }
 
-       sysfs_put(sd);
-       return -EEXIST;
+       *p_sd = sd;
+       return 0;
 }
 
 int sysfs_create_subdir(struct kobject *kobj, const char *name,
@@ -759,12 +762,15 @@ static int sysfs_count_nlink(struct sysfs_dirent *sd)
 static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
                                struct nameidata *nd)
 {
+       struct dentry *ret = NULL;
        struct sysfs_dirent * parent_sd = dentry->d_parent->d_fsdata;
        struct sysfs_dirent * sd;
        struct bin_attribute *bin_attr;
        struct inode *inode;
        int found = 0;
 
+       mutex_lock(&sysfs_mutex);
+
        for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) {
                if (sysfs_type(sd) &&
                    !strcmp(sd->s_name, dentry->d_name.name)) {
@@ -775,14 +781,14 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
 
        /* no such entry */
        if (!found)
-               return NULL;
+               goto out_unlock;
 
        /* attach dentry and inode */
        inode = sysfs_get_inode(sd);
-       if (!inode)
-               return ERR_PTR(-ENOMEM);
-
-       mutex_lock(&sysfs_mutex);
+       if (!inode) {
+               ret = ERR_PTR(-ENOMEM);
+               goto out_unlock;
+       }
 
        if (inode->i_state & I_NEW) {
                /* initialize inode according to type */
@@ -812,9 +818,9 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
        sysfs_instantiate(dentry, inode);
        sysfs_attach_dentry(sd, dentry);
 
+ out_unlock:
        mutex_unlock(&sysfs_mutex);
-
-       return NULL;
+       return ret;
 }
 
 const struct inode_operations sysfs_dir_inode_operations = {
@@ -939,6 +945,8 @@ int sysfs_rename_dir(struct kobject *kobj, struct sysfs_dirent *new_parent_sd,
        if (error)
                goto out_drop;
 
+       mutex_lock(&sysfs_mutex);
+
        dup_name = sd->s_name;
        sd->s_name = new_name;
 
@@ -946,8 +954,6 @@ int sysfs_rename_dir(struct kobject *kobj, struct sysfs_dirent *new_parent_sd,
        d_add(new_dentry, NULL);
        d_move(sd->s_dentry, new_dentry);
 
-       mutex_lock(&sysfs_mutex);
-
        sysfs_unlink_sibling(sd);
        sysfs_get(new_parent_sd);
        sysfs_put(sd->s_parent);