Skip to content

Commit e68ecc1

Browse files
committed
Merge patch series "Minor namespace code simplication"
Joel Savitz <[email protected]> says: The two patches are independent of each other. The first patch removes unnecssary NULL guards from free_nsproxy() and create_new_namespaces() in line with other usage of the put_*_ns() call sites. The second patch slightly reduces the size of the kernel when CONFIG_CGROUPS is not selected. * patches from https://lore.kernel.org/[email protected]: include/cgroup: separate {get,put}_cgroup_ns no-op case kernel/nsproxy: remove unnecessary guards Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents bb01e8c + 79fb8d8 commit e68ecc1

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

include/linux/cgroup.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,17 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags,
785785
int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen,
786786
struct cgroup_namespace *ns);
787787

788+
static inline void get_cgroup_ns(struct cgroup_namespace *ns)
789+
{
790+
refcount_inc(&ns->ns.count);
791+
}
792+
793+
static inline void put_cgroup_ns(struct cgroup_namespace *ns)
794+
{
795+
if (refcount_dec_and_test(&ns->ns.count))
796+
free_cgroup_ns(ns);
797+
}
798+
788799
#else /* !CONFIG_CGROUPS */
789800

790801
static inline void free_cgroup_ns(struct cgroup_namespace *ns) { }
@@ -795,19 +806,10 @@ copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,
795806
return old_ns;
796807
}
797808

798-
#endif /* !CONFIG_CGROUPS */
809+
static inline void get_cgroup_ns(struct cgroup_namespace *ns) { }
810+
static inline void put_cgroup_ns(struct cgroup_namespace *ns) { }
799811

800-
static inline void get_cgroup_ns(struct cgroup_namespace *ns)
801-
{
802-
if (ns)
803-
refcount_inc(&ns->ns.count);
804-
}
805-
806-
static inline void put_cgroup_ns(struct cgroup_namespace *ns)
807-
{
808-
if (ns && refcount_dec_and_test(&ns->ns.count))
809-
free_cgroup_ns(ns);
810-
}
812+
#endif /* !CONFIG_CGROUPS */
811813

812814
#ifdef CONFIG_CGROUPS
813815

kernel/nsproxy.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,13 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
128128
out_net:
129129
put_cgroup_ns(new_nsp->cgroup_ns);
130130
out_cgroup:
131-
if (new_nsp->pid_ns_for_children)
132-
put_pid_ns(new_nsp->pid_ns_for_children);
131+
put_pid_ns(new_nsp->pid_ns_for_children);
133132
out_pid:
134-
if (new_nsp->ipc_ns)
135-
put_ipc_ns(new_nsp->ipc_ns);
133+
put_ipc_ns(new_nsp->ipc_ns);
136134
out_ipc:
137-
if (new_nsp->uts_ns)
138-
put_uts_ns(new_nsp->uts_ns);
135+
put_uts_ns(new_nsp->uts_ns);
139136
out_uts:
140-
if (new_nsp->mnt_ns)
141-
put_mnt_ns(new_nsp->mnt_ns);
137+
put_mnt_ns(new_nsp->mnt_ns);
142138
out_ns:
143139
kmem_cache_free(nsproxy_cachep, new_nsp);
144140
return ERR_PTR(err);
@@ -189,18 +185,12 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
189185

190186
void free_nsproxy(struct nsproxy *ns)
191187
{
192-
if (ns->mnt_ns)
193-
put_mnt_ns(ns->mnt_ns);
194-
if (ns->uts_ns)
195-
put_uts_ns(ns->uts_ns);
196-
if (ns->ipc_ns)
197-
put_ipc_ns(ns->ipc_ns);
198-
if (ns->pid_ns_for_children)
199-
put_pid_ns(ns->pid_ns_for_children);
200-
if (ns->time_ns)
201-
put_time_ns(ns->time_ns);
202-
if (ns->time_ns_for_children)
203-
put_time_ns(ns->time_ns_for_children);
188+
put_mnt_ns(ns->mnt_ns);
189+
put_uts_ns(ns->uts_ns);
190+
put_ipc_ns(ns->ipc_ns);
191+
put_pid_ns(ns->pid_ns_for_children);
192+
put_time_ns(ns->time_ns);
193+
put_time_ns(ns->time_ns_for_children);
204194
put_cgroup_ns(ns->cgroup_ns);
205195
put_net(ns->net_ns);
206196
kmem_cache_free(nsproxy_cachep, ns);

0 commit comments

Comments
 (0)