[PATCH 3/3] kernel/nsproxy: utilize cleanup helper for nsproxy references

Joel Savitz posted 3 patches 6 months, 2 weeks ago
[PATCH 3/3] kernel/nsproxy: utilize cleanup helper for nsproxy references
Posted by Joel Savitz 6 months, 2 weeks ago
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