Skip to content

Commit 1f531e3

Browse files
Al Virobrauner
authored andcommitted
don't bother with path_get()/path_put() in unix_open_file()
Once unix_sock ->path is set, we are guaranteed that its ->path will remain unchanged (and pinned) until the socket is closed. OTOH, dentry_open() does not modify the path passed to it. IOW, there's no need to copy unix_sk(sk)->path in unix_open_file() - we can just pass it to dentry_open() and be done with that. Signed-off-by: Al Viro <[email protected]> Link: https://lore.kernel.org/20250712054157.GZ1880847@ZenIV Reviewed-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent a683a5b commit 1f531e3

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

net/unix/af_unix.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,7 +3201,6 @@ EXPORT_SYMBOL_GPL(unix_outq_len);
32013201

32023202
static int unix_open_file(struct sock *sk)
32033203
{
3204-
struct path path;
32053204
struct file *f;
32063205
int fd;
32073206

@@ -3211,27 +3210,20 @@ static int unix_open_file(struct sock *sk)
32113210
if (!smp_load_acquire(&unix_sk(sk)->addr))
32123211
return -ENOENT;
32133212

3214-
path = unix_sk(sk)->path;
3215-
if (!path.dentry)
3213+
if (!unix_sk(sk)->path.dentry)
32163214
return -ENOENT;
32173215

3218-
path_get(&path);
3219-
32203216
fd = get_unused_fd_flags(O_CLOEXEC);
32213217
if (fd < 0)
3222-
goto out;
3218+
return fd;
32233219

3224-
f = dentry_open(&path, O_PATH, current_cred());
3220+
f = dentry_open(&unix_sk(sk)->path, O_PATH, current_cred());
32253221
if (IS_ERR(f)) {
32263222
put_unused_fd(fd);
3227-
fd = PTR_ERR(f);
3228-
goto out;
3223+
return PTR_ERR(f);
32293224
}
32303225

32313226
fd_install(fd, f);
3232-
out:
3233-
path_put(&path);
3234-
32353227
return fd;
32363228
}
32373229

0 commit comments

Comments
 (0)