The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Joel Savitz <jsavitz@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Joel Savitz <jsavitz@redhat.com>,
	Christian Brauner <brauner@kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: [PATCH 3/3] kernel/nsproxy: utilize cleanup helper for nsproxy references
Date: Fri, 30 May 2025 16:03:06 -0400	[thread overview]
Message-ID: <20250530200305.85319-5-jsavitz@redhat.com> (raw)
In-Reply-To: <20250530200305.85319-2-jsavitz@redhat.com>

A cleanup helper for nsproxy references was added by commit d057c108155a
("nsproxy: add a cleanup helper for nsproxy") however it is only used in
commit 5b08bd408534 ("pidfs: allow retrieval of namespace file
descriptors").

Simplify nsproxy code by using this cleanup helper.

Signed-off-by: Joel Savitz <jsavitz@redhat.com>
---
 kernel/nsproxy.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 20b07120dbfd..c623e9ce3c2a 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -228,7 +228,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
 
 void switch_task_namespaces(struct task_struct *p, struct nsproxy *new)
 {
-	struct nsproxy *ns;
+	struct nsproxy *ns __free(put_nsproxy) = NULL;
 
 	might_sleep();
 
@@ -236,9 +236,6 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new)
 	ns = p->nsproxy;
 	p->nsproxy = new;
 	task_unlock(p);
-
-	if (ns)
-		put_nsproxy(ns);
 }
 
 void exit_task_namespaces(struct task_struct *p)
@@ -368,7 +365,7 @@ static int validate_nsset(struct nsset *nsset, struct pid *pid)
 	unsigned flags = nsset->flags;
 	struct user_namespace *user_ns = NULL;
 	struct pid_namespace *pid_ns = NULL;
-	struct nsproxy *nsp;
+	struct nsproxy *nsp __free(put_nsproxy) = NULL;
 	struct task_struct *tsk;
 
 	/* Take a "snapshot" of the target task's namespaces. */
@@ -483,8 +480,6 @@ static int validate_nsset(struct nsset *nsset, struct pid *pid)
 out:
 	put_user_ns(user_ns);
 	put_pid_ns(pid_ns);
-	if (nsp)
-		put_nsproxy(nsp);
 
 	return ret;
 }
-- 
2.45.2


  parent reply	other threads:[~2025-05-30 20:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 20:03 [PATCH 0/3] kernel/nsproxy: Minor nsproxy code simplification Joel Savitz
2025-05-30 20:03 ` [PATCH 1/3] kernel/nsproxy: remove unnecessary guard in validate_nsset() Joel Savitz
2025-05-30 20:03 ` [PATCH 2/3] kernel/nsproxy: fix put_*() call ordering " Joel Savitz
2025-05-30 20:03 ` Joel Savitz [this message]
2025-06-09 14:23 ` [PATCH 0/3] kernel/nsproxy: Minor nsproxy code simplification Joel Savitz
2025-06-18 19:49   ` Joel Savitz
2025-07-01 16:41     ` Joel Savitz
2025-07-07 14:37       ` Joel Savitz
2025-07-14 12:22 ` 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=20250530200305.85319-5-jsavitz@redhat.com \
    --to=jsavitz@redhat.com \
    --cc=brauner@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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