]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
do_readlinkat(): import pathname only once
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 1 Nov 2025 04:48:31 +0000 (00:48 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 13 Jan 2026 20:16:44 +0000 (15:16 -0500)
Take getname_flags() and putname() outside of retry loop.

Since getname_flags() is the only thing that cares about LOOKUP_EMPTY,
don't bother with setting LOOKUP_EMPTY in lookup_flags - just pass it
to getname_flags() and be done with that.

The things could be further simplified by use of cleanup.h stuff, but
let's not clutter the patch with that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/stat.c

index 6c79661e1b9612be73bd629c005ab8fa54b5fbb1..ee9ae2c3273a91525d4dcb43f230cb1ae3d2df34 100644 (file)
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -566,13 +566,13 @@ static int do_readlinkat(int dfd, const char __user *pathname,
        struct path path;
        struct filename *name;
        int error;
-       unsigned int lookup_flags = LOOKUP_EMPTY;
+       unsigned int lookup_flags = 0;
 
        if (bufsiz <= 0)
                return -EINVAL;
 
+       name = getname_flags(pathname, LOOKUP_EMPTY);
 retry:
-       name = getname_flags(pathname, lookup_flags);
        error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
        if (unlikely(error)) {
                putname(name);
@@ -593,11 +593,11 @@ retry:
                error = (name->name[0] == '\0') ? -ENOENT : -EINVAL;
        }
        path_put(&path);
-       putname(name);
        if (retry_estale(error, lookup_flags)) {
                lookup_flags |= LOOKUP_REVAL;
                goto retry;
        }
+       putname(name);
        return error;
 }