[RFC][PATCH v3 45/55] handle_dots(): return ERR_PTR/NULL instead of -E.../0

Al Viro
2020-03-01T21:53:33Z

all callers prefer such calling conventions

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/namei.c | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 3f15b18af991..20a2fc27dd87 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1785,7 +1785,7 @@ static const char *step_into(struct nameidata *nd, int flags,
return pick_link(nd, &path, inode, seq, flags);
}

-static int handle_dots(struct nameidata *nd, int type, int flags)
+static const char *handle_dots(struct nameidata *nd, int type, int flags)
{
if (type == LAST_DOTDOT) {
int error = 0;
@@ -1793,14 +1793,14 @@ static int handle_dots(struct nameidata *nd, int type, int flags)
if (!nd->root.mnt) {
error = set_root(nd);
if (error)
- return error;
+ return ERR_PTR(error);
}
if (nd->flags & LOOKUP_RCU)
error = follow_dotdot_rcu(nd);
else
error = follow_dotdot(nd);
if (error)
- return error;
+ return ERR_PTR(error);

if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) {
/*
@@ -1811,14 +1811,14 @@ static int handle_dots(struct nameidata *nd, int type, int flags)
*/
smp_rmb();
if (unlikely(__read_seqcount_retry(&mount_lock.seqcount, nd->m_seq)))
- return -EAGAIN;
+ return ERR_PTR(-EAGAIN);
if (unlikely(__read_seqcount_retry(&rename_lock.seqcount, nd->r_seq)))
- return -EAGAIN;
+ return ERR_PTR(-EAGAIN);
}
}
if (!(flags & WALK_MORE) && nd->depth)
put_link(nd);
- return 0;
+ return NULL;
}

static const char *walk_component(struct nameidata *nd, int flags)
@@ -1826,16 +1826,13 @@ static const char *walk_component(struct nameidata *nd, int flags)
struct dentry *dentry;
struct inode *inode;
unsigned seq;
- int err;
/*
* "." and ".." are special - ".." especially so because it has
* to be able to know about the current root directory and
* parent relationships.
*/
- if (unlikely(nd->last_type != LAST_NORM)) {
- err = handle_dots(nd, nd->last_type, flags);
- return ERR_PTR(err);
- }
+ if (unlikely(nd->last_type != LAST_NORM))
+ return handle_dots(nd, nd->last_type, flags);
dentry = lookup_fast(nd, &inode, &seq);
if (IS_ERR(dentry))
return ERR_CAST(dentry);
@@ -3135,17 +3132,17 @@ static const char *open_last_lookups(struct nameidata *nd,
unsigned seq;
struct inode *inode;
struct dentry *dentry;
- const char *link;
+ const char *res;
int error;

nd->flags &= ~LOOKUP_PARENT;
nd->flags |= op->intent;

if (nd->last_type != LAST_NORM) {
- error = handle_dots(nd, nd->last_type, WALK_TRAILING);
- if (likely(!error))
- error = complete_walk(nd);
- return ERR_PTR(error);
+ res = handle_dots(nd, nd->last_type, WALK_TRAILING);
+ if (likely(!res))
+ res = ERR_PTR(complete_walk(nd));
+ return res;
}

if (!(open_flag & O_CREAT)) {
@@ -3209,11 +3206,11 @@ static const char *open_last_lookups(struct nameidata *nd,
}

finish_lookup:
- link = step_into(nd, WALK_TRAILING, dentry, inode, seq);
- if (unlikely(link)) {
+ res = step_into(nd, WALK_TRAILING, dentry, inode, seq);
+ if (unlikely(res)) {
nd->flags |= LOOKUP_PARENT;
nd->flags &= ~(LOOKUP_OPEN|LOOKUP_CREATE|LOOKUP_EXCL);
- return link;
+ return res;
}

if (unlikely((open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) {
--
2.11.0