Skip to content

Commit 4905590

Browse files
author
Al Viro
committed
pick_link(): take reserving space on stack into a new helper
Signed-off-by: Al Viro <[email protected]>
1 parent aef9404 commit 4905590

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

fs/namei.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,38 +1580,42 @@ static inline int may_lookup(struct nameidata *nd)
15801580
return inode_permission(nd->inode, MAY_EXEC);
15811581
}
15821582

1583+
static int reserve_stack(struct nameidata *nd, struct path *link, unsigned seq)
1584+
{
1585+
int error;
1586+
1587+
if (unlikely(nd->total_link_count++ >= MAXSYMLINKS))
1588+
return -ELOOP;
1589+
error = nd_alloc_stack(nd);
1590+
if (likely(!error))
1591+
return 0;
1592+
if (error == -ECHILD) {
1593+
// we must grab link first
1594+
bool grabbed_link = legitimize_path(nd, link, seq);
1595+
// ... and we must unlazy to be able to clean up
1596+
error = unlazy_walk(nd);
1597+
if (unlikely(!grabbed_link))
1598+
error = -ECHILD;
1599+
if (!error)
1600+
error = nd_alloc_stack(nd);
1601+
}
1602+
return error;
1603+
}
1604+
15831605
enum {WALK_TRAILING = 1, WALK_MORE = 2, WALK_NOFOLLOW = 4};
15841606

15851607
static const char *pick_link(struct nameidata *nd, struct path *link,
15861608
struct inode *inode, unsigned seq, int flags)
15871609
{
15881610
struct saved *last;
15891611
const char *res;
1590-
int error;
1612+
int error = reserve_stack(nd, link, seq);
15911613

1592-
if (unlikely(nd->total_link_count++ >= MAXSYMLINKS)) {
1593-
if (!(nd->flags & LOOKUP_RCU))
1594-
path_put(link);
1595-
return ERR_PTR(-ELOOP);
1596-
}
1597-
error = nd_alloc_stack(nd);
15981614
if (unlikely(error)) {
1599-
if (error == -ECHILD) {
1600-
// we must grab link first
1601-
bool grabbed_link = legitimize_path(nd, link, seq);
1602-
// ... and we must unlazy to be able to clean up
1603-
error = unlazy_walk(nd);
1604-
if (unlikely(!grabbed_link))
1605-
error = -ECHILD;
1606-
if (!error)
1607-
error = nd_alloc_stack(nd);
1608-
}
1609-
if (error) {
1615+
if (!(nd->flags & LOOKUP_RCU))
16101616
path_put(link);
1611-
return ERR_PTR(error);
1612-
}
1617+
return ERR_PTR(error);
16131618
}
1614-
16151619
last = nd->stack + nd->depth++;
16161620
last->link = *link;
16171621
clear_delayed_call(&last->done);

0 commit comments

Comments
 (0)