]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
cgroup: add helper for checking when css is cgroup::self
authorJP Kobryn <inwardvessel@gmail.com>
Fri, 4 Apr 2025 01:10:47 +0000 (18:10 -0700)
committerTejun Heo <tj@kernel.org>
Fri, 4 Apr 2025 20:01:22 +0000 (10:01 -1000)
The cgroup struct has a css field called "self". The main difference
between this css and the others found in the cgroup::subsys array is that
cgroup::self has a NULL subsystem pointer. There are several places where
checks are performed to determine whether the css in question is
cgroup::self or not. Instead of accessing css->ss directly, introduce a
helper function that shows the intent and use where applicable.

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/cgroup.h
kernel/cgroup/cgroup.c

index e7da3c3b098b3aaf3ad2df3955827715db83807b..65d95bb2199fdc3866b13fa3e156481aeb428229 100644 (file)
@@ -347,6 +347,11 @@ static inline bool css_is_dying(struct cgroup_subsys_state *css)
        return css->flags & CSS_DYING;
 }
 
+static inline bool css_is_cgroup(struct cgroup_subsys_state *css)
+{
+       return css->ss == NULL;
+}
+
 static inline void cgroup_get(struct cgroup *cgrp)
 {
        css_get(&cgrp->self);
index e1f0284cbbb8e15a90c97fe7764e01bdb7b96aa7..d98994b106ed578173e5ea5e712551192dca042f 100644 (file)
@@ -1706,7 +1706,7 @@ static void css_clear_dir(struct cgroup_subsys_state *css)
 
        css->flags &= ~CSS_VISIBLE;
 
-       if (!css->ss) {
+       if (css_is_cgroup(css)) {
                if (cgroup_on_dfl(cgrp)) {
                        cgroup_addrm_files(css, cgrp,
                                           cgroup_base_files, false);
@@ -1738,7 +1738,7 @@ static int css_populate_dir(struct cgroup_subsys_state *css)
        if (css->flags & CSS_VISIBLE)
                return 0;
 
-       if (!css->ss) {
+       if (css_is_cgroup(css)) {
                if (cgroup_on_dfl(cgrp)) {
                        ret = cgroup_addrm_files(css, cgrp,
                                                 cgroup_base_files, true);