[PATCH v3 bpf-next 01/11] cgroup: Remove unnecessary list_empty()

Yafang Shao
2023-10-29T06:14:50Z

The root hasn't been removed from the root_list, so the list can't be NULL.
However, if it had been removed, attempting to destroy it once more is not
possible. Let's replace this with WARN_ON_ONCE() for clarity.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
kernel/cgroup/cgroup.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 1fb7f56..3053d42 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1345,10 +1345,9 @@ static void cgroup_destroy_root(struct cgroup_root *root)

spin_unlock_irq(&css_set_lock);

- if (!list_empty(&root->root_list)) {
- list_del(&root->root_list);
- cgroup_root_count--;
- }
+ WARN_ON_ONCE(list_empty(&root->root_list));
+ list_del(&root->root_list);
+ cgroup_root_count--;

cgroup_favor_dynmods(root, false);
cgroup_exit_root_id(root);
--
1.8.3.1