Skip to content

Commit 79fb8d8

Browse files
theyoyojobrauner
authored andcommitted
include/cgroup: separate {get,put}_cgroup_ns no-op case
When CONFIG_CGROUPS is not selected, {get,put}_cgroup_ns become no-ops and therefore it is not necessary to compile in the code for changing the reference count. When CONFIG_CGROUP is selected, there is no valid case where either of {get,put}_cgroup_ns() will be called with a NULL argument. Signed-off-by: Joel Savitz <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 5caa2d8 commit 79fb8d8

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
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

0 commit comments

Comments
 (0)