Commit 60ef60c7 authored by Al Viro's avatar Al Viro

__nd_alloc_stack(): make it return bool

... and adjust the caller (reserve_stack()).  Rename to nd_alloc_stack(),
while we are at it.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 4542576b
...@@ -529,24 +529,17 @@ static void restore_nameidata(void) ...@@ -529,24 +529,17 @@ static void restore_nameidata(void)
kfree(now->stack); kfree(now->stack);
} }
static int __nd_alloc_stack(struct nameidata *nd) static bool nd_alloc_stack(struct nameidata *nd)
{ {
struct saved *p; struct saved *p;
if (nd->flags & LOOKUP_RCU) { p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved), nd->flags & LOOKUP_RCU ? GFP_ATOMIC : GFP_KERNEL);
GFP_ATOMIC); if (unlikely(!p))
if (unlikely(!p)) return false;
return -ECHILD;
} else {
p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
GFP_KERNEL);
if (unlikely(!p))
return -ENOMEM;
}
memcpy(p, nd->internal, sizeof(nd->internal)); memcpy(p, nd->internal, sizeof(nd->internal));
nd->stack = p; nd->stack = p;
return 0; return true;
} }
/** /**
...@@ -1573,8 +1566,6 @@ static inline int may_lookup(struct nameidata *nd) ...@@ -1573,8 +1566,6 @@ static inline int may_lookup(struct nameidata *nd)
static int reserve_stack(struct nameidata *nd, struct path *link, unsigned seq) static int reserve_stack(struct nameidata *nd, struct path *link, unsigned seq)
{ {
int error;
if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) if (unlikely(nd->total_link_count++ >= MAXSYMLINKS))
return -ELOOP; return -ELOOP;
...@@ -1582,21 +1573,21 @@ static int reserve_stack(struct nameidata *nd, struct path *link, unsigned seq) ...@@ -1582,21 +1573,21 @@ static int reserve_stack(struct nameidata *nd, struct path *link, unsigned seq)
return 0; return 0;
if (likely(nd->stack != nd->internal)) if (likely(nd->stack != nd->internal))
return 0; return 0;
if (likely(nd_alloc_stack(nd)))
error = __nd_alloc_stack(nd);
if (likely(!error))
return 0; return 0;
if (error == -ECHILD) {
// we must grab link first if (nd->flags & LOOKUP_RCU) {
// we need to grab link before we do unlazy. And we can't skip
// unlazy even if we fail to grab the link - cleanup needs it
bool grabbed_link = legitimize_path(nd, link, seq); bool grabbed_link = legitimize_path(nd, link, seq);
// ... and we must unlazy to be able to clean up
error = unlazy_walk(nd); if (unlazy_walk(nd) != 0 || !grabbed_link)
if (unlikely(!grabbed_link)) return -ECHILD;
error = -ECHILD;
if (!error) if (nd_alloc_stack(nd))
error = __nd_alloc_stack(nd); return 0;
} }
return error; return -ENOMEM;
} }
enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4}; enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment