Netdev List
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: netdev@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Subject: [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file()
Date: Sat, 12 Jul 2025 06:41:57 +0100	[thread overview]
Message-ID: <20250712054157.GZ1880847@ZenIV> (raw)

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 <viro@zeniv.linux.org.uk>
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 52b155123985..019ba2609b66 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -3191,7 +3191,6 @@ EXPORT_SYMBOL_GPL(unix_outq_len);
 
 static int unix_open_file(struct sock *sk)
 {
-	struct path path;
 	struct file *f;
 	int fd;
 
@@ -3201,27 +3200,20 @@ static int unix_open_file(struct sock *sk)
 	if (!smp_load_acquire(&unix_sk(sk)->addr))
 		return -ENOENT;
 
-	path = unix_sk(sk)->path;
-	if (!path.dentry)
+	if (!unix_sk(sk)->path.dentry)
 		return -ENOENT;
 
-	path_get(&path);
-
 	fd = get_unused_fd_flags(O_CLOEXEC);
 	if (fd < 0)
-		goto out;
+		return fd;
 
-	f = dentry_open(&path, O_PATH, current_cred());
+	f = dentry_open(&unix_sk(sk)->path, O_PATH, current_cred());
 	if (IS_ERR(f)) {
 		put_unused_fd(fd);
-		fd = PTR_ERR(f);
-		goto out;
+		return PTR_ERR(f);
 	}
 
 	fd_install(fd, f);
-out:
-	path_put(&path);
-
 	return fd;
 }
 

             reply	other threads:[~2025-07-12  5:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-12  5:41 Al Viro [this message]
2025-07-12  6:38 ` [PATCH][RFC] don't bother with path_get()/path_put() in unix_open_file() Kuniyuki Iwashima
2025-07-14  8:24   ` Christian Brauner
2025-07-14 15:04     ` Al Viro
2025-07-14 16:11       ` Kuniyuki Iwashima
2025-07-15  9:46 ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250712054157.GZ1880847@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox