namei.c: let follow_link() do put_link() on failure
no need for kludgy "set cookie to ERR_PTR(...) because we failed before we did actual ->follow_link() and want to suppress put_link()", no pointless check in put_link() itself. Callers checked if follow_link() has failed anyway; might as well break out of their loops if that happened, without bothering to call put_link() first. [AV: folded fixes from hch] Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
1d674107ea
commit
6d7b5aaed7
74
fs/namei.c
74
fs/namei.c
@ -605,7 +605,7 @@ static inline void path_to_nameidata(const struct path *path,
|
|||||||
static inline void put_link(struct nameidata *nd, struct path *link, void *cookie)
|
static inline void put_link(struct nameidata *nd, struct path *link, void *cookie)
|
||||||
{
|
{
|
||||||
struct inode *inode = link->dentry->d_inode;
|
struct inode *inode = link->dentry->d_inode;
|
||||||
if (!IS_ERR(cookie) && inode->i_op->put_link)
|
if (inode->i_op->put_link)
|
||||||
inode->i_op->put_link(link->dentry, nd, cookie);
|
inode->i_op->put_link(link->dentry, nd, cookie);
|
||||||
path_put(link);
|
path_put(link);
|
||||||
}
|
}
|
||||||
@ -613,19 +613,19 @@ static inline void put_link(struct nameidata *nd, struct path *link, void *cooki
|
|||||||
static __always_inline int
|
static __always_inline int
|
||||||
follow_link(struct path *link, struct nameidata *nd, void **p)
|
follow_link(struct path *link, struct nameidata *nd, void **p)
|
||||||
{
|
{
|
||||||
int error;
|
|
||||||
struct dentry *dentry = link->dentry;
|
struct dentry *dentry = link->dentry;
|
||||||
|
int error;
|
||||||
|
char *s;
|
||||||
|
|
||||||
BUG_ON(nd->flags & LOOKUP_RCU);
|
BUG_ON(nd->flags & LOOKUP_RCU);
|
||||||
|
|
||||||
if (link->mnt == nd->path.mnt)
|
if (link->mnt == nd->path.mnt)
|
||||||
mntget(link->mnt);
|
mntget(link->mnt);
|
||||||
|
|
||||||
if (unlikely(current->total_link_count >= 40)) {
|
error = -ELOOP;
|
||||||
*p = ERR_PTR(-ELOOP); /* no ->put_link(), please */
|
if (unlikely(current->total_link_count >= 40))
|
||||||
path_put(&nd->path);
|
goto out_put_nd_path;
|
||||||
return -ELOOP;
|
|
||||||
}
|
|
||||||
cond_resched();
|
cond_resched();
|
||||||
current->total_link_count++;
|
current->total_link_count++;
|
||||||
|
|
||||||
@ -633,30 +633,37 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
|
|||||||
nd_set_link(nd, NULL);
|
nd_set_link(nd, NULL);
|
||||||
|
|
||||||
error = security_inode_follow_link(link->dentry, nd);
|
error = security_inode_follow_link(link->dentry, nd);
|
||||||
if (error) {
|
if (error)
|
||||||
*p = ERR_PTR(error); /* no ->put_link(), please */
|
goto out_put_nd_path;
|
||||||
path_put(&nd->path);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
nd->last_type = LAST_BIND;
|
nd->last_type = LAST_BIND;
|
||||||
*p = dentry->d_inode->i_op->follow_link(dentry, nd);
|
*p = dentry->d_inode->i_op->follow_link(dentry, nd);
|
||||||
error = PTR_ERR(*p);
|
error = PTR_ERR(*p);
|
||||||
if (!IS_ERR(*p)) {
|
if (IS_ERR(*p))
|
||||||
char *s = nd_get_link(nd);
|
goto out_put_link;
|
||||||
error = 0;
|
|
||||||
if (s)
|
error = 0;
|
||||||
error = __vfs_follow_link(nd, s);
|
s = nd_get_link(nd);
|
||||||
else if (nd->last_type == LAST_BIND) {
|
if (s) {
|
||||||
nd->flags |= LOOKUP_JUMPED;
|
error = __vfs_follow_link(nd, s);
|
||||||
nd->inode = nd->path.dentry->d_inode;
|
} else if (nd->last_type == LAST_BIND) {
|
||||||
if (nd->inode->i_op->follow_link) {
|
nd->flags |= LOOKUP_JUMPED;
|
||||||
/* stepped on a _really_ weird one */
|
nd->inode = nd->path.dentry->d_inode;
|
||||||
path_put(&nd->path);
|
if (nd->inode->i_op->follow_link) {
|
||||||
error = -ELOOP;
|
/* stepped on a _really_ weird one */
|
||||||
}
|
path_put(&nd->path);
|
||||||
|
error = -ELOOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (unlikely(error))
|
||||||
|
put_link(nd, link, *p);
|
||||||
|
|
||||||
|
return error;
|
||||||
|
|
||||||
|
out_put_nd_path:
|
||||||
|
path_put(&nd->path);
|
||||||
|
out_put_link:
|
||||||
|
path_put(link);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1383,9 +1390,10 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
|
|||||||
void *cookie;
|
void *cookie;
|
||||||
|
|
||||||
res = follow_link(&link, nd, &cookie);
|
res = follow_link(&link, nd, &cookie);
|
||||||
if (!res)
|
if (res)
|
||||||
res = walk_component(nd, path, &nd->last,
|
break;
|
||||||
nd->last_type, LOOKUP_FOLLOW);
|
res = walk_component(nd, path, &nd->last,
|
||||||
|
nd->last_type, LOOKUP_FOLLOW);
|
||||||
put_link(nd, &link, cookie);
|
put_link(nd, &link, cookie);
|
||||||
} while (res > 0);
|
} while (res > 0);
|
||||||
|
|
||||||
@ -1777,8 +1785,9 @@ static int path_lookupat(int dfd, const char *name,
|
|||||||
struct path link = path;
|
struct path link = path;
|
||||||
nd->flags |= LOOKUP_PARENT;
|
nd->flags |= LOOKUP_PARENT;
|
||||||
err = follow_link(&link, nd, &cookie);
|
err = follow_link(&link, nd, &cookie);
|
||||||
if (!err)
|
if (err)
|
||||||
err = lookup_last(nd, &path);
|
break;
|
||||||
|
err = lookup_last(nd, &path);
|
||||||
put_link(nd, &link, cookie);
|
put_link(nd, &link, cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2475,9 +2484,8 @@ static struct file *path_openat(int dfd, const char *pathname,
|
|||||||
nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
|
nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
|
||||||
error = follow_link(&link, nd, &cookie);
|
error = follow_link(&link, nd, &cookie);
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
filp = ERR_PTR(error);
|
goto out_filp;
|
||||||
else
|
filp = do_last(nd, &path, op, pathname);
|
||||||
filp = do_last(nd, &path, op, pathname);
|
|
||||||
put_link(nd, &link, cookie);
|
put_link(nd, &link, cookie);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user