Skip to content

Commit 60ef60c

Browse files
author
Al Viro
committed
__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: Al Viro <[email protected]>
1 parent 4542576 commit 60ef60c

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

fs/namei.c

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -529,24 +529,17 @@ static void restore_nameidata(void)
529529
kfree(now->stack);
530530
}
531531

532-
static int __nd_alloc_stack(struct nameidata *nd)
532+
static bool nd_alloc_stack(struct nameidata *nd)
533533
{
534534
struct saved *p;
535535

536-
if (nd->flags & LOOKUP_RCU) {
537-
p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
538-
GFP_ATOMIC);
539-
if (unlikely(!p))
540-
return -ECHILD;
541-
} else {
542-
p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
543-
GFP_KERNEL);
544-
if (unlikely(!p))
545-
return -ENOMEM;
546-
}
536+
p= kmalloc_array(MAXSYMLINKS, sizeof(struct saved),
537+
nd->flags & LOOKUP_RCU ? GFP_ATOMIC : GFP_KERNEL);
538+
if (unlikely(!p))
539+
return false;
547540
memcpy(p, nd->internal, sizeof(nd->internal));
548541
nd->stack = p;
549-
return 0;
542+
return true;
550543
}
551544

552545
/**
@@ -1573,30 +1566,28 @@ static inline int may_lookup(struct nameidata *nd)
15731566

15741567
static int reserve_stack(struct nameidata *nd, struct path *link, unsigned seq)
15751568
{
1576-
int error;
1577-
15781569
if (unlikely(nd->total_link_count++ >= MAXSYMLINKS))
15791570
return -ELOOP;
15801571

15811572
if (likely(nd->depth != EMBEDDED_LEVELS))
15821573
return 0;
15831574
if (likely(nd->stack != nd->internal))
15841575
return 0;
1585-
1586-
error = __nd_alloc_stack(nd);
1587-
if (likely(!error))
1576+
if (likely(nd_alloc_stack(nd)))
15881577
return 0;
1589-
if (error == -ECHILD) {
1590-
// we must grab link first
1578+
1579+
if (nd->flags & LOOKUP_RCU) {
1580+
// we need to grab link before we do unlazy. And we can't skip
1581+
// unlazy even if we fail to grab the link - cleanup needs it
15911582
bool grabbed_link = legitimize_path(nd, link, seq);
1592-
// ... and we must unlazy to be able to clean up
1593-
error = unlazy_walk(nd);
1594-
if (unlikely(!grabbed_link))
1595-
error = -ECHILD;
1596-
if (!error)
1597-
error = __nd_alloc_stack(nd);
1583+
1584+
if (unlazy_walk(nd) != 0 || !grabbed_link)
1585+
return -ECHILD;
1586+
1587+
if (nd_alloc_stack(nd))
1588+
return 0;
15981589
}
1599-
return error;
1590+
return -ENOMEM;
16001591
}
16011592

16021593
enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4};

0 commit comments

Comments
 (0)