Skip to content

Commit c5971b8

Browse files
author
Al Viro
committed
take post-lookup part of do_last() out of loop
now we can have open_last_lookups() directly from the loop in path_openat() - the rest of do_last() never returns a symlink to follow, so we can bloody well leave the loop first. Rename the rest of that thing from do_last() to do_open() and make it return an int. Signed-off-by: Al Viro <[email protected]>
1 parent 0f70595 commit c5971b8

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

fs/namei.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,31 +3220,26 @@ static const char *open_last_lookups(struct nameidata *nd,
32203220
/*
32213221
* Handle the last step of open()
32223222
*/
3223-
static const char *do_last(struct nameidata *nd,
3223+
static int do_open(struct nameidata *nd,
32243224
struct file *file, const struct open_flags *op)
32253225
{
32263226
int open_flag = op->open_flag;
32273227
bool do_truncate;
32283228
int acc_mode;
3229-
const char *link;
32303229
int error;
32313230

3232-
link = open_last_lookups(nd, file, op);
3233-
if (unlikely(link))
3234-
return link;
3235-
32363231
if (!(file->f_mode & FMODE_CREATED))
32373232
audit_inode(nd->name, nd->path.dentry, 0);
32383233
if (open_flag & O_CREAT) {
32393234
if (d_is_dir(nd->path.dentry))
3240-
return ERR_PTR(-EISDIR);
3235+
return -EISDIR;
32413236
error = may_create_in_sticky(nd->dir_mode, nd->dir_uid,
32423237
d_backing_inode(nd->path.dentry));
32433238
if (unlikely(error))
3244-
return ERR_PTR(error);
3239+
return error;
32453240
}
32463241
if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
3247-
return ERR_PTR(-ENOTDIR);
3242+
return -ENOTDIR;
32483243

32493244
do_truncate = false;
32503245
acc_mode = op->acc_mode;
@@ -3255,7 +3250,7 @@ static const char *do_last(struct nameidata *nd,
32553250
} else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
32563251
error = mnt_want_write(nd->path.mnt);
32573252
if (error)
3258-
return ERR_PTR(error);
3253+
return error;
32593254
do_truncate = true;
32603255
}
32613256
error = may_open(&nd->path, acc_mode, open_flag);
@@ -3271,7 +3266,7 @@ static const char *do_last(struct nameidata *nd,
32713266
}
32723267
if (do_truncate)
32733268
mnt_drop_write(nd->path.mnt);
3274-
return ERR_PTR(error);
3269+
return error;
32753270
}
32763271

32773272
struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode, int open_flag)
@@ -3374,8 +3369,10 @@ static struct file *path_openat(struct nameidata *nd,
33743369
} else {
33753370
const char *s = path_init(nd, flags);
33763371
while (!(error = link_path_walk(s, nd)) &&
3377-
(s = do_last(nd, file, op)) != NULL)
3372+
(s = open_last_lookups(nd, file, op)) != NULL)
33783373
;
3374+
if (!error)
3375+
error = do_open(nd, file, op);
33793376
terminate_walk(nd);
33803377
}
33813378
if (likely(!error)) {

0 commit comments

Comments
 (0)