link_path_walk: nd->depth massage, part 1
nd->stack[0] is unused until the handling of trailing symlinks and we want to get rid of that. Having fucked that transformation up several times, I went for bloody pedantic series of provably equivalent transformations. Sorry. Step 1: keep nd->depth higher by one in link_path_walk() - increment upon entry, decrement on exits, adjust the arithmetics inside and surround the calls of functions that care about nd->depth value (nd_alloc_stack(), get_link(), put_link()) with decrement/increment pairs. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
894bc8c466
commit
071bf50137
22
fs/namei.c
22
fs/namei.c
@ -1763,6 +1763,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
|
|||||||
if (!*name)
|
if (!*name)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
nd->depth++;
|
||||||
/* At this point we know we have a real path component. */
|
/* At this point we know we have a real path component. */
|
||||||
for(;;) {
|
for(;;) {
|
||||||
u64 hash_len;
|
u64 hash_len;
|
||||||
@ -1823,15 +1824,18 @@ Walked:
|
|||||||
if (err) {
|
if (err) {
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
|
nd->depth--;
|
||||||
err = nd_alloc_stack(nd);
|
err = nd_alloc_stack(nd);
|
||||||
|
nd->depth++;
|
||||||
if (unlikely(err)) {
|
if (unlikely(err)) {
|
||||||
path_to_nameidata(&nd->link, nd);
|
path_to_nameidata(&nd->link, nd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
nd->depth++;
|
nd->depth++;
|
||||||
|
nd->depth--;
|
||||||
s = get_link(nd);
|
s = get_link(nd);
|
||||||
|
nd->depth++;
|
||||||
|
|
||||||
if (unlikely(IS_ERR(s))) {
|
if (unlikely(IS_ERR(s))) {
|
||||||
err = PTR_ERR(s);
|
err = PTR_ERR(s);
|
||||||
@ -1841,7 +1845,9 @@ Walked:
|
|||||||
err = 0;
|
err = 0;
|
||||||
if (unlikely(!s)) {
|
if (unlikely(!s)) {
|
||||||
/* jumped */
|
/* jumped */
|
||||||
|
nd->depth--;
|
||||||
put_link(nd);
|
put_link(nd);
|
||||||
|
nd->depth++;
|
||||||
nd->depth--;
|
nd->depth--;
|
||||||
} else {
|
} else {
|
||||||
if (*s == '/') {
|
if (*s == '/') {
|
||||||
@ -1855,7 +1861,7 @@ Walked:
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
nd->inode = nd->path.dentry->d_inode;
|
nd->inode = nd->path.dentry->d_inode;
|
||||||
nd->stack[nd->depth].name = name;
|
nd->stack[nd->depth - 1].name = name;
|
||||||
if (!*s)
|
if (!*s)
|
||||||
goto OK;
|
goto OK;
|
||||||
name = s;
|
name = s;
|
||||||
@ -1869,19 +1875,25 @@ Walked:
|
|||||||
}
|
}
|
||||||
terminate_walk(nd);
|
terminate_walk(nd);
|
||||||
Err:
|
Err:
|
||||||
while (unlikely(nd->depth)) {
|
while (unlikely(nd->depth > 1)) {
|
||||||
|
nd->depth--;
|
||||||
put_link(nd);
|
put_link(nd);
|
||||||
|
nd->depth++;
|
||||||
nd->depth--;
|
nd->depth--;
|
||||||
}
|
}
|
||||||
|
nd->depth--;
|
||||||
return err;
|
return err;
|
||||||
OK:
|
OK:
|
||||||
if (unlikely(nd->depth)) {
|
if (unlikely(nd->depth > 1)) {
|
||||||
name = nd->stack[nd->depth].name;
|
name = nd->stack[nd->depth - 1].name;
|
||||||
err = walk_component(nd, LOOKUP_FOLLOW);
|
err = walk_component(nd, LOOKUP_FOLLOW);
|
||||||
|
nd->depth--;
|
||||||
put_link(nd);
|
put_link(nd);
|
||||||
|
nd->depth++;
|
||||||
nd->depth--;
|
nd->depth--;
|
||||||
goto Walked;
|
goto Walked;
|
||||||
}
|
}
|
||||||
|
nd->depth--;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user