]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kernel/nsproxy: remove unnecessary guards
authorJoel Savitz <jsavitz@redhat.com>
Thu, 8 May 2025 18:49:29 +0000 (14:49 -0400)
committerChristian Brauner <brauner@kernel.org>
Fri, 9 May 2025 11:13:54 +0000 (13:13 +0200)
In free_nsproxy() and the error path of create_new_namesapces() the
put_*_ns() calls are guarded by unnecessary NULL checks.

put_pid_ns(), put_ipc_ns(), put_uts_ns(), and put_time_ns() will never
receive a NULL argument unless their namespace type is disabled, and in
this case all four become no-ops at compile time anyway. put_mnt_ns()
will never receive a null argument at any time.

This unguarded usage is in line with other call sites of put_*_ns().

Signed-off-by: Joel Savitz <jsavitz@redhat.com>
Link: https://lore.kernel.org/20250508184930.183040-2-jsavitz@redhat.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
kernel/nsproxy.c

index c9d97ed2012276137ca8d59c5a6d7bbdf5c84163..5f31fdff8a38f5d932df1ed243e88497ea9b2fea 100644 (file)
@@ -128,17 +128,13 @@ out_time:
 out_net:
        put_cgroup_ns(new_nsp->cgroup_ns);
 out_cgroup:
-       if (new_nsp->pid_ns_for_children)
-               put_pid_ns(new_nsp->pid_ns_for_children);
+       put_pid_ns(new_nsp->pid_ns_for_children);
 out_pid:
-       if (new_nsp->ipc_ns)
-               put_ipc_ns(new_nsp->ipc_ns);
+       put_ipc_ns(new_nsp->ipc_ns);
 out_ipc:
-       if (new_nsp->uts_ns)
-               put_uts_ns(new_nsp->uts_ns);
+       put_uts_ns(new_nsp->uts_ns);
 out_uts:
-       if (new_nsp->mnt_ns)
-               put_mnt_ns(new_nsp->mnt_ns);
+       put_mnt_ns(new_nsp->mnt_ns);
 out_ns:
        kmem_cache_free(nsproxy_cachep, new_nsp);
        return ERR_PTR(err);
@@ -189,18 +185,12 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
 
 void free_nsproxy(struct nsproxy *ns)
 {
-       if (ns->mnt_ns)
-               put_mnt_ns(ns->mnt_ns);
-       if (ns->uts_ns)
-               put_uts_ns(ns->uts_ns);
-       if (ns->ipc_ns)
-               put_ipc_ns(ns->ipc_ns);
-       if (ns->pid_ns_for_children)
-               put_pid_ns(ns->pid_ns_for_children);
-       if (ns->time_ns)
-               put_time_ns(ns->time_ns);
-       if (ns->time_ns_for_children)
-               put_time_ns(ns->time_ns_for_children);
+       put_mnt_ns(ns->mnt_ns);
+       put_uts_ns(ns->uts_ns);
+       put_ipc_ns(ns->ipc_ns);
+       put_pid_ns(ns->pid_ns_for_children);
+       put_time_ns(ns->time_ns);
+       put_time_ns(ns->time_ns_for_children);
        put_cgroup_ns(ns->cgroup_ns);
        put_net(ns->net_ns);
        kmem_cache_free(nsproxy_cachep, ns);