[PATCH] cgroup: replace BUG_ON()s in compare_css_sets() with WARN_ON_ONCE()

From: Shaojie Sun

Date: Thu Nov 05 2026 - 08:07:27 EST


compare_css_sets() walks the cgrp_links lists of two css_sets in
lockstep. Both lists carry exactly one link per hierarchy root, so a
length or ordering mismatch just means the two css_sets are not the same
one, which is what the function already reports with "return false".
The caller keeps walking the hash chain and allocates a new css_set if
nothing matches.

None of these checks is a user-reachable error path; they are invariant
checks on kernel-internal bookkeeping that are expected never to fire,
and each one has a way out.

No functional change for a consistent state.

Signed-off-by: Shaojie Sun <sunshaojie@xxxxxxxxxx>
---
kernel/cgroup/cgroup.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index a284225f8dc9..81c82d137fa2 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1024,10 +1024,12 @@ static bool compare_css_sets(struct css_set *cset,
l2 = l2->next;
/* See if we reached the end - both lists are equal length. */
if (l1 == &cset->cgrp_links) {
- BUG_ON(l2 != &old_cset->cgrp_links);
+ if (WARN_ON_ONCE(l2 != &old_cset->cgrp_links))
+ return false;
break;
} else {
- BUG_ON(l2 == &old_cset->cgrp_links);
+ if (WARN_ON_ONCE(l2 == &old_cset->cgrp_links))
+ return false;
}
/* Locate the cgroups associated with these links. */
link1 = list_entry(l1, struct cgrp_cset_link, cgrp_link);
@@ -1035,7 +1037,8 @@ static bool compare_css_sets(struct css_set *cset,
cgrp1 = link1->cgrp;
cgrp2 = link2->cgrp;
/* Hierarchies should be linked in the same order. */
- BUG_ON(cgrp1->root != cgrp2->root);
+ if (WARN_ON_ONCE(cgrp1->root != cgrp2->root))
+ return false;

/*
* If this hierarchy is the hierarchy of the cgroup
--
2.50.1