Skip to content

Commit 4e9654c

Browse files
author
Al Viro
committed
chdir(2): unspaghettify a bit...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f770e4c commit 4e9654c

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

fs/open.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -558,26 +558,19 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
558558
struct path path;
559559
int error;
560560
unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
561-
struct filename *name = getname(filename);
561+
CLASS(filename, name)(filename);
562562
retry:
563563
error = filename_lookup(AT_FDCWD, name, lookup_flags, &path, NULL);
564-
if (error)
565-
goto out;
566-
567-
error = path_permission(&path, MAY_EXEC | MAY_CHDIR);
568-
if (error)
569-
goto dput_and_out;
570-
571-
set_fs_pwd(current->fs, &path);
572-
573-
dput_and_out:
574-
path_put(&path);
575-
if (retry_estale(error, lookup_flags)) {
576-
lookup_flags |= LOOKUP_REVAL;
577-
goto retry;
564+
if (!error) {
565+
error = path_permission(&path, MAY_EXEC | MAY_CHDIR);
566+
if (!error)
567+
set_fs_pwd(current->fs, &path);
568+
path_put(&path);
569+
if (retry_estale(error, lookup_flags)) {
570+
lookup_flags |= LOOKUP_REVAL;
571+
goto retry;
572+
}
578573
}
579-
out:
580-
putname(name);
581574
return error;
582575
}
583576

0 commit comments

Comments
 (0)