Commit 1d957f9b authored by Jan Blunck's avatar Jan Blunck Committed by Linus Torvalds

Introduce path_put()

* Add path_put() functions for releasing a reference to the dentry and
  vfsmount of a struct path in the right order

* Switch from path_release(nd) to path_put(&nd->path)

* Rename dput_path() to path_put_conditional()

[akpm@linux-foundation.org: fix cifs]
Signed-off-by: default avatarJan Blunck <jblunck@suse.de>
Signed-off-by: default avatarAndreas Gruenbacher <agruen@suse.de>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Cc: <linux-fsdevel@vger.kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Steven French <sfrench@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4ac91378
......@@ -260,7 +260,7 @@ osf_statfs(char __user *path, struct osf_statfs __user *buffer, unsigned long bu
retval = user_path_walk(path, &nd);
if (!retval) {
retval = do_osf_statfs(nd.path.dentry, buffer, bufsiz);
path_release(&nd);
path_put(&nd.path);
}
return retval;
}
......
......@@ -711,7 +711,7 @@ asmlinkage int irix_statfs(const char __user *path,
}
dput_and_out:
path_release(&nd);
path_put(&nd.path);
out:
return error;
}
......@@ -1385,7 +1385,7 @@ asmlinkage int irix_statvfs(char __user *fname, struct irix_statvfs __user *buf)
error |= __put_user(0, &buf->f_fstr[i]);
dput_and_out:
path_release(&nd);
path_put(&nd.path);
out:
return error;
}
......@@ -1636,7 +1636,7 @@ asmlinkage int irix_statvfs64(char __user *fname, struct irix_statvfs64 __user *
error |= __put_user(0, &buf->f_fstr[i]);
dput_and_out:
path_release(&nd);
path_put(&nd.path);
out:
return error;
}
......
......@@ -222,7 +222,7 @@ asmlinkage long hpux_statfs(const char __user *path,
error = vfs_statfs_hpux(nd.path.dentry, &tmp);
if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
error = -EFAULT;
path_release(&nd);
path_put(&nd.path);
}
return error;
}
......
......@@ -73,7 +73,7 @@ static long do_spu_create(const char __user *pathname, unsigned int flags,
LOOKUP_OPEN|LOOKUP_CREATE, &nd);
if (!ret) {
ret = spufs_create(&nd, flags, mode, neighbor);
path_release(&nd);
path_put(&nd.path);
}
putname(tmp);
}
......
......@@ -436,7 +436,7 @@ asmlinkage int solaris_statvfs(u32 path, u32 buf)
if (!error) {
struct inode *inode = nd.path.dentry->d_inode;
error = report_statvfs(nd.path.mnt, inode, buf);
path_release(&nd);
path_put(&nd.path);
}
return error;
}
......@@ -466,7 +466,7 @@ asmlinkage int solaris_statvfs64(u32 path, u32 buf)
if (!error) {
struct inode *inode = nd.path.dentry->d_inode;
error = report_statvfs64(nd.path.mnt, inode, buf);
path_release(&nd);
path_put(&nd.path);
}
unlock_kernel();
return error;
......
......@@ -375,7 +375,7 @@ static int lookup_device(const char *path, dev_t *dev)
*dev = inode->i_rdev;
out:
path_release(&nd);
path_put(&nd.path);
return r;
}
......
......@@ -203,7 +203,7 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
goto not_an_MTD_device;
mtdnr = iminor(nd.path.dentry->d_inode);
path_release(&nd);
path_put(&nd.path);
return get_sb_mtd_nr(fs_type, flags, dev_name, data, mtdnr, fill_super,
mnt);
......@@ -214,7 +214,7 @@ not_an_MTD_device:
"MTD: Attempt to mount non-MTD device \"%s\"\n",
dev_name);
out:
path_release(&nd);
path_put(&nd.path);
return ret;
}
......
......@@ -227,7 +227,7 @@ static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd)
newmnt = afs_mntpt_do_automount(nd->path.dentry);
if (IS_ERR(newmnt)) {
path_release(nd);
path_put(&nd->path);
return (void *)newmnt;
}
......
......@@ -383,7 +383,7 @@ done:
return NULL;
out_error:
path_release(nd);
path_put(&nd->path);
return ERR_PTR(status);
}
......
......@@ -1409,7 +1409,7 @@ struct block_device *lookup_bdev(const char *path)
if (!bdev)
goto fail;
out:
path_release(&nd);
path_put(&nd.path);
return bdev;
fail:
bdev = ERR_PTR(error);
......
......@@ -368,7 +368,7 @@ out:
cFYI(1, ("leaving %s" , __FUNCTION__));
return ERR_PTR(rc);
out_err:
path_release(nd);
path_put(&nd->path);
goto out;
}
......
......@@ -80,7 +80,7 @@ static int coda_pioctl(struct inode * inode, struct file * filp,
/* return if it is not a Coda inode */
if ( target_inode->i_sb != inode->i_sb ) {
path_release(&nd);
path_put(&nd.path);
return -EINVAL;
}
......@@ -89,7 +89,7 @@ static int coda_pioctl(struct inode * inode, struct file * filp,
error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
path_release(&nd);
path_put(&nd.path);
return error;
}
......@@ -244,7 +244,7 @@ asmlinkage long compat_sys_statfs(const char __user *path, struct compat_statfs
error = vfs_statfs(nd.path.dentry, &tmp);
if (!error)
error = put_compat_statfs(buf, &tmp);
path_release(&nd);
path_put(&nd.path);
}
return error;
}
......@@ -312,7 +312,7 @@ asmlinkage long compat_sys_statfs64(const char __user *path, compat_size_t sz, s
error = vfs_statfs(nd.path.dentry, &tmp);
if (!error)
error = put_compat_statfs64(buf, &tmp);
path_release(&nd);
path_put(&nd.path);
}
return error;
}
......
......@@ -103,7 +103,7 @@ static int get_target(const char *symname, struct nameidata *nd,
*target = configfs_get_config_item(nd->path.dentry);
if (!*target) {
ret = -ENOENT;
path_release(nd);
path_put(&nd->path);
}
} else
ret = -EPERM;
......@@ -141,7 +141,7 @@ int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symna
ret = create_link(parent_item, target_item, dentry);
config_item_put(target_item);
path_release(&nd);
path_put(&nd.path);
out_put:
config_item_put(parent_item);
......
......@@ -1643,7 +1643,7 @@ int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path)
error = vfs_quota_on_inode(nd.path.dentry->d_inode, type,
format_id);
out_path:
path_release(&nd);
path_put(&nd.path);
return error;
}
......
......@@ -526,7 +526,7 @@ static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
rc = 0;
goto out;
out_free:
path_release(&nd);
path_put(&nd.path);
out:
return rc;
}
......
......@@ -148,7 +148,7 @@ out:
return error;
exit:
release_open_intent(&nd);
path_release(&nd);
path_put(&nd.path);
goto out;
}
......@@ -672,7 +672,7 @@ out:
}
}
release_open_intent(&nd);
path_release(&nd);
path_put(&nd.path);
}
goto out;
}
......
......@@ -2759,7 +2759,7 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
return err;
/* Quotafile not on the same filesystem? */
if (nd.path.mnt->mnt_sb != sb) {
path_release(&nd);
path_put(&nd.path);
return -EXDEV;
}
/* Quotafile not of fs root? */
......@@ -2767,7 +2767,7 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
printk(KERN_WARNING
"EXT3-fs: Quota file not on filesystem root. "
"Journalled quota will not work.\n");
path_release(&nd);
path_put(&nd.path);
return vfs_quota_on(sb, type, format_id, path);
}
......
......@@ -3159,7 +3159,7 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
return err;
/* Quotafile not on the same filesystem? */
if (nd.path.mnt->mnt_sb != sb) {
path_release(&nd);
path_put(&nd.path);
return -EXDEV;
}
/* Quotafile not of fs root? */
......@@ -3167,7 +3167,7 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
printk(KERN_WARNING
"EXT4-fs: Quota file not on filesystem root. "
"Journalled quota will not work.\n");
path_release(&nd);
path_put(&nd.path);
return vfs_quota_on(sb, type, format_id, path);
}
......
......@@ -900,7 +900,7 @@ static struct super_block* get_gfs2_sb(const char *dev_name)
"mount point %s\n", dev_name);
free_nd:
path_release(&nd);
path_put(&nd.path);
out:
return sb;
}
......
......@@ -367,7 +367,7 @@ static int find_inode(const char __user *dirname, struct nameidata *nd,
/* you can only watch an inode if you have read permissions on it */
error = vfs_permission(nd, MAY_READ);
if (error)
path_release(nd);
path_put(&nd->path);
return error;
}
......@@ -676,7 +676,7 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)
ret = create_watch(dev, inode, mask);
mutex_unlock(&dev->up_mutex);
path_release(&nd);
path_put(&nd.path);
fput_and_out:
fput_light(filp, fput_needed);
return ret;
......
......@@ -362,11 +362,18 @@ int deny_write_access(struct file * file)
return 0;
}
void path_release(struct nameidata *nd)
/**
* 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(nd->path.dentry);
mntput(nd->path.mnt);
dput(path->dentry);
mntput(path->mnt);
}
EXPORT_SYMBOL(path_put);
/**
* release_open_intent - free up open intent resources
......@@ -551,7 +558,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 +574,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)
......@@ -651,8 +658,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;
}
......@@ -993,10 +1000,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;
}
......@@ -1070,7 +1077,7 @@ static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
mntput(old_mnt);
return 1;
}
path_release(nd);
path_put(&nd->path);
}
nd->path.dentry = old_dentry;
nd->path.mnt = old_mnt;
......@@ -1230,7 +1237,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 +1813,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 +1986,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 +2046,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 +2154,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 +2238,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 +2315,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 +2411,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 +2641,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 +2817,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);
......
......@@ -1007,7 +1007,7 @@ static noinline int do_loopback(struct nameidata *nd, char *old_name,
out:
up_write(&namespace_sem);
path_release(&old_nd);
path_put(&old_nd.path);
return err;
}
......@@ -1126,8 +1126,8 @@ out1:
out:
up_write(&namespace_sem);
if (!err)
path_release(&parent_nd);
path_release(&old_nd);
path_put(&parent_nd.path);
path_put(&old_nd.path);
return err;
}
......@@ -1512,7 +1512,7 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
retval = do_new_mount(&nd, type_page, flags, mnt_flags,
dev_name, data_page);
dput_out:
path_release(&nd);
path_put(&nd.path);
return retval;
}
......@@ -1768,7 +1768,7 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
error = security_sb_pivotroot(&old_nd, &new_nd);
if (error) {
path_release(&old_nd);
path_put(&old_nd.path);
goto out1;
}
......@@ -1831,15 +1831,15 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
chroot_fs_refs(&user_nd, &new_nd);
security_sb_post_pivotroot(&user_nd, &new_nd);
error = 0;
path_release(&root_parent);
path_release(&parent_nd);
path_put(&root_parent.path);
path_put(&parent_nd.path);
out2:
mutex_unlock(&old_nd.path.dentry->d_inode->i_mutex);
up_write(&namespace_sem);
path_release(&user_nd);
path_release(&old_nd);
path_put(&user_nd.path);
path_put(&old_nd.path);
out1:
path_release(&new_nd);
path_put(&new_nd.path);
out0:
unlock_kernel();
return error;
......
......@@ -148,7 +148,7 @@ out:
dprintk("<-- nfs_follow_mountpoint() = %d\n", err);
return ERR_PTR(err);
out_err:
path_release(nd);
path_put(&nd->path);
goto out;
out_follow:
while (d_mountpoint(nd->path.dentry) &&
......
......@@ -43,7 +43,7 @@ static struct file *do_open(char *name, int flags)
if (!error)
return dentry_open(nd.path.dentry, nd.path.mnt, flags);
path_release(&nd);
path_put(&nd.path);
return ERR_PTR(error);
}
......
......@@ -177,7 +177,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
cache_put(&ek->h, &svc_expkey_cache);
else
err = -ENOMEM;
path_release(&nd);
path_put(&nd.path);
}
cache_flush();
out:
......@@ -630,7 +630,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
kfree(exp.ex_uuid);
kfree(exp.ex_path);
if (nd.path.dentry)
path_release(&nd);
path_put(&nd.path);
out_no_path:
if (dom)
auth_domain_put(dom);
......@@ -1098,7 +1098,7 @@ finish:
cache_put(&fsid_key->h, &svc_expkey_cache);
if (clp)
auth_domain_put(clp);
path_release(&nd);
path_put(&nd.path);
out_unlock:
exp_writeunlock();
out:
......@@ -1150,7 +1150,7 @@ exp_unexport(struct nfsctl_export *nxp)
err = -EINVAL;
exp = exp_get_by_name(dom, nd.path.mnt, nd.path.dentry, NULL);
path_release(&nd);
path_put(&nd.path);
if (IS_ERR(exp))
goto out_domain;
......@@ -1209,7 +1209,7 @@ exp_rootfh(svc_client *clp, char *path, struct knfsd_fh *f, int maxsize)
fh_put(&fh);
exp_put(exp);
out:
path_release(&nd);
path_put(&nd.path);
return err;
}
......
......@@ -415,5 +415,5 @@ nfsd4_shutdown_recdir(void)
if (!rec_dir_init)
return;
rec_dir_init = 0;
path_release(&rec_dir);
path_put(&rec_dir.path);
}
......@@ -3265,7 +3265,7 @@ nfs4_reset_recoverydir(char *recdir)
nfs4_set_recdir(recdir);