]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/namei.c
debugfs: fix sparse warnings
[karo-tx-linux.git] / fs / namei.c
index c9b05a71c39cbdcf10415984d8644d8c16a68a6e..941c8e8228c041d90652313f13e72f2b6e975716 100644 (file)
@@ -362,11 +362,31 @@ int deny_write_access(struct file * file)
        return 0;
 }
 
-void path_release(struct nameidata *nd)
+/**
+ * path_get - get a reference to a path
+ * @path: path to get the reference to
+ *
+ * Given a path increment the reference count to the dentry and the vfsmount.
+ */
+void path_get(struct path *path)
 {
-       dput(nd->path.dentry);
-       mntput(nd->path.mnt);
+       mntget(path->mnt);
+       dget(path->dentry);
 }
+EXPORT_SYMBOL(path_get);
+
+/**
+ * path_put - put a reference to a path
+ * @path: path to put the reference to
+ *
+ * Given a path decrement the reference count to the dentry and the vfsmount.
+ */
+void path_put(struct path *path)
+{
+       dput(path->dentry);
+       mntput(path->mnt);
+}
+EXPORT_SYMBOL(path_put);
 
 /**
  * release_open_intent - free up open intent resources
@@ -529,16 +549,16 @@ walk_init_root(const char *name, struct nameidata *nd)
        struct fs_struct *fs = current->fs;
 
        read_lock(&fs->lock);
-       if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
-               nd->path.mnt = mntget(fs->altrootmnt);
-               nd->path.dentry = dget(fs->altroot);
+       if (fs->altroot.dentry && !(nd->flags & LOOKUP_NOALT)) {
+               nd->path = fs->altroot;
+               path_get(&fs->altroot);
                read_unlock(&fs->lock);
                if (__emul_lookup_dentry(name,nd))
                        return 0;
                read_lock(&fs->lock);
        }
-       nd->path.mnt = mntget(fs->rootmnt);
-       nd->path.dentry = dget(fs->root);
+       nd->path = fs->root;
+       path_get(&fs->root);
        read_unlock(&fs->lock);
        return 1;
 }
@@ -551,7 +571,7 @@ static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *l
                goto fail;
 
        if (*link == '/') {
-               path_release(nd);
+               path_put(&nd->path);
                if (!walk_init_root(link, nd))
                        /* weird __emul_prefix() stuff did it */
                        goto out;
@@ -567,18 +587,18 @@ out:
         */
        name = __getname();
        if (unlikely(!name)) {
-               path_release(nd);
+               path_put(&nd->path);
                return -ENOMEM;
        }
        strcpy(name, nd->last.name);
        nd->last.name = name;
        return 0;
 fail:
-       path_release(nd);
+       path_put(&nd->path);
        return PTR_ERR(link);
 }
 
-static inline void dput_path(struct path *path, struct nameidata *nd)
+static void path_put_conditional(struct path *path, struct nameidata *nd)
 {
        dput(path->dentry);
        if (path->mnt != nd->path.mnt)
@@ -618,8 +638,7 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata
                if (dentry->d_inode->i_op->put_link)
                        dentry->d_inode->i_op->put_link(dentry, nd, cookie);
        }
-       dput(dentry);
-       mntput(path->mnt);
+       path_put(path);
 
        return error;
 }
@@ -651,8 +670,8 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
        nd->depth--;
        return err;
 loop:
-       dput_path(path, nd);
-       path_release(nd);
+       path_put_conditional(path, nd);
+       path_put(&nd->path);
        return err;
 }
 
@@ -736,8 +755,8 @@ static __always_inline void follow_dotdot(struct nameidata *nd)
                struct dentry *old = nd->path.dentry;
 
                 read_lock(&fs->lock);
-               if (nd->path.dentry == fs->root &&
-                   nd->path.mnt == fs->rootmnt) {
+               if (nd->path.dentry == fs->root.dentry &&
+                   nd->path.mnt == fs->root.mnt) {
                         read_unlock(&fs->lock);
                        break;
                }
@@ -993,10 +1012,10 @@ return_reval:
 return_base:
                return 0;
 out_dput:
-               dput_path(&next, nd);
+               path_put_conditional(&next, nd);
                break;
        }
-       path_release(nd);
+       path_put(&nd->path);
 return_err:
        return err;
 }
@@ -1026,8 +1045,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
                result = __link_path_walk(name, nd);
        }
 
-       dput(save.path.dentry);
-       mntput(save.path.mnt);
+       path_put(&save.path);
 
        return result;
 }
@@ -1049,8 +1067,7 @@ static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
 
        if (!nd->path.dentry->d_inode ||
            S_ISDIR(nd->path.dentry->d_inode->i_mode)) {
-               struct dentry *old_dentry = nd->path.dentry;
-               struct vfsmount *old_mnt = nd->path.mnt;
+               struct path old_path = nd->path;
                struct qstr last = nd->last;
                int last_type = nd->last_type;
                struct fs_struct *fs = current->fs;
@@ -1061,19 +1078,17 @@ static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
                 */
                nd->last_type = LAST_ROOT;
                read_lock(&fs->lock);
-               nd->path.mnt = mntget(fs->rootmnt);
-               nd->path.dentry = dget(fs->root);
+               nd->path = fs->root;
+               path_get(&fs->root);
                read_unlock(&fs->lock);
                if (path_walk(name, nd) == 0) {
                        if (nd->path.dentry->d_inode) {
-                               dput(old_dentry);
-                               mntput(old_mnt);
+                               path_put(&old_path);
                                return 1;
                        }
-                       path_release(nd);
+                       path_put(&nd->path);
                }
-               nd->path.dentry = old_dentry;
-               nd->path.mnt = old_mnt;
+               nd->path = old_path;
                nd->last = last;
                nd->last_type = last_type;
        }
@@ -1084,29 +1099,22 @@ void set_fs_altroot(void)
 {
        char *emul = __emul_prefix();
        struct nameidata nd;
-       struct vfsmount *mnt = NULL, *oldmnt;
-       struct dentry *dentry = NULL, *olddentry;
+       struct path path = {}, old_path;
        int err;
        struct fs_struct *fs = current->fs;
 
        if (!emul)
                goto set_it;
        err = path_lookup(emul, LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_NOALT, &nd);
-       if (!err) {
-               mnt = nd.path.mnt;
-               dentry = nd.path.dentry;
-       }
+       if (!err)
+               path = nd.path;
 set_it:
        write_lock(&fs->lock);
-       oldmnt = fs->altrootmnt;
-       olddentry = fs->altroot;
-       fs->altrootmnt = mnt;
-       fs->altroot = dentry;
+       old_path = fs->altroot;
+       fs->altroot = path;
        write_unlock(&fs->lock);
-       if (olddentry) {
-               dput(olddentry);
-               mntput(oldmnt);
-       }
+       if (old_path.dentry)
+               path_put(&old_path);
 }
 
 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
@@ -1124,21 +1132,21 @@ static int do_path_lookup(int dfd, const char *name,
 
        if (*name=='/') {
                read_lock(&fs->lock);
-               if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
-                       nd->path.mnt = mntget(fs->altrootmnt);
-                       nd->path.dentry = dget(fs->altroot);
+               if (fs->altroot.dentry && !(nd->flags & LOOKUP_NOALT)) {
+                       nd->path = fs->altroot;
+                       path_get(&fs->altroot);
                        read_unlock(&fs->lock);
                        if (__emul_lookup_dentry(name,nd))
                                goto out; /* found in altroot */
                        read_lock(&fs->lock);
                }
-               nd->path.mnt = mntget(fs->rootmnt);
-               nd->path.dentry = dget(fs->root);
+               nd->path = fs->root;
+               path_get(&fs->root);
                read_unlock(&fs->lock);
        } else if (dfd == AT_FDCWD) {
                read_lock(&fs->lock);
-               nd->path.mnt = mntget(fs->pwdmnt);
-               nd->path.dentry = dget(fs->pwd);
+               nd->path = fs->pwd;
+               path_get(&fs->pwd);
                read_unlock(&fs->lock);
        } else {
                struct dentry *dentry;
@@ -1158,8 +1166,8 @@ static int do_path_lookup(int dfd, const char *name,
                if (retval)
                        goto fput_fail;
 
-               nd->path.mnt = mntget(file->f_path.mnt);
-               nd->path.dentry = dget(dentry);
+               nd->path = file->f_path;
+               path_get(&file->f_path);
 
                fput_light(file, fput_needed);
        }
@@ -1230,7 +1238,7 @@ static int __path_lookup_intent_open(int dfd, const char *name,
        if (IS_ERR(nd->intent.open.file)) {
                if (err == 0) {
                        err = PTR_ERR(nd->intent.open.file);
-                       path_release(nd);
+                       path_put(&nd->path);
                }
        } else if (err != 0)
                release_open_intent(nd);
@@ -1806,11 +1814,11 @@ ok:
        return 0;
 
 exit_dput:
-       dput_path(&path, nd);
+       path_put_conditional(&path, nd);
 exit:
        if (!IS_ERR(nd->intent.open.file))
                release_open_intent(nd);
-       path_release(nd);
+       path_put(&nd->path);
        return error;
 
 do_link:
@@ -1979,7 +1987,7 @@ asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
                dput(dentry);
        }
        mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-       path_release(&nd);
+       path_put(&nd.path);
 out:
        putname(tmp);
 
@@ -2039,7 +2047,7 @@ asmlinkage long sys_mkdirat(int dfd, const char __user *pathname, int mode)
        dput(dentry);
 out_unlock:
        mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-       path_release(&nd);
+       path_put(&nd.path);
 out:
        putname(tmp);
 out_err:
@@ -2147,7 +2155,7 @@ static long do_rmdir(int dfd, const char __user *pathname)
 exit2:
        mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
 exit1:
-       path_release(&nd);
+       path_put(&nd.path);
 exit:
        putname(name);
        return error;
@@ -2231,7 +2239,7 @@ static long do_unlinkat(int dfd, const char __user *pathname)
        if (inode)
                iput(inode);    /* truncate the inode here */
 exit1:
-       path_release(&nd);
+       path_put(&nd.path);
 exit:
        putname(name);
        return error;
@@ -2308,7 +2316,7 @@ asmlinkage long sys_symlinkat(const char __user *oldname,
        dput(dentry);
 out_unlock:
        mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-       path_release(&nd);
+       path_put(&nd.path);
 out:
        putname(to);
 out_putname:
@@ -2404,9 +2412,9 @@ asmlinkage long sys_linkat(int olddfd, const char __user *oldname,
 out_unlock:
        mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
 out_release:
-       path_release(&nd);
+       path_put(&nd.path);
 out:
-       path_release(&old_nd);
+       path_put(&old_nd.path);
 exit:
        putname(to);
 
@@ -2634,9 +2642,9 @@ exit4:
 exit3:
        unlock_rename(new_dir, old_dir);
 exit2:
-       path_release(&newnd);
+       path_put(&newnd.path);
 exit1:
-       path_release(&oldnd);
+       path_put(&oldnd.path);
 exit:
        return error;
 }
@@ -2810,7 +2818,6 @@ EXPORT_SYMBOL(page_symlink);
 EXPORT_SYMBOL(page_symlink_inode_operations);
 EXPORT_SYMBOL(path_lookup);
 EXPORT_SYMBOL(vfs_path_lookup);
-EXPORT_SYMBOL(path_release);
 EXPORT_SYMBOL(permission);
 EXPORT_SYMBOL(vfs_permission);
 EXPORT_SYMBOL(file_permission);