]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
cgroup: compare css to cgroup::self in helper for distingushing css
authorJP Kobryn <inwardvessel@gmail.com>
Thu, 15 May 2025 00:19:33 +0000 (17:19 -0700)
committerTejun Heo <tj@kernel.org>
Mon, 19 May 2025 20:21:24 +0000 (10:21 -1000)
Adjust the implementation of css_is_cgroup() so that it compares the given
css to cgroup::self. Rename the function to css_is_self() in order to
reflect that. Change the existing css->ss NULL check to a warning in the
true branch. Finally, adjust call sites to use the new function name.

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 1f5b0a4a33566d16952a90cd7c0739927e1a2ce1..989c08b096912453ca91dfea475388fa500f2954 100644 (file)
@@ -347,9 +347,15 @@ 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)
+static inline bool css_is_self(struct cgroup_subsys_state *css)
 {
-       return css->ss == NULL;
+       if (css == &css->cgroup->self) {
+               /* cgroup::self should not have subsystem association */
+               WARN_ON(css->ss != NULL);
+               return true;
+       }
+
+       return false;
 }
 
 static inline void cgroup_get(struct cgroup *cgrp)
index 83b35c22da951fb65e6a8a1527cea2783217fe1d..ce6a60b9b5850a37ab31ba4865a5ff9d9c04957c 100644 (file)
@@ -1706,7 +1706,7 @@ static void css_clear_dir(struct cgroup_subsys_state *css)
 
        css->flags &= ~CSS_VISIBLE;
 
-       if (css_is_cgroup(css)) {
+       if (css_is_self(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_is_cgroup(css)) {
+       if (css_is_self(css)) {
                if (cgroup_on_dfl(cgrp)) {
                        ret = cgroup_addrm_files(css, cgrp,
                                                 cgroup_base_files, true);
@@ -5406,7 +5406,7 @@ static void css_free_rwork_fn(struct work_struct *work)
 
        percpu_ref_exit(&css->refcnt);
 
-       if (ss) {
+       if (!css_is_self(css)) {
                /* css free path */
                struct cgroup_subsys_state *parent = css->parent;
                int id = css->id;
@@ -5460,7 +5460,7 @@ static void css_release_work_fn(struct work_struct *work)
        css->flags |= CSS_RELEASED;
        list_del_rcu(&css->sibling);
 
-       if (ss) {
+       if (!css_is_self(css)) {
                struct cgroup *parent_cgrp;
 
                /* css release path */