[PATCH 1/3] cgroup: Return -ENODEV consistently for a dead cgroup
From: Tejun Heo
Date: Wed Sep 02 2026 - 19:26:56 EST
cgroup_kn_lock_live() returns NULL when the cgroup behind a kernfs node has
already been removed. Most callers turn that into -ENODEV, but the
cgroup.type, cgroup.max.descendants, cgroup.max.depth, cgroup.pressure,
cgroup.freeze and cgroup.kill writers return -ENOENT. The divergence is
accidental. Return -ENODEV from all of them, matching cgroup.procs and
cgroup.subtree_control.
Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
---
kernel/cgroup/cgroup.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index c3a12fee7528..37bc8a67a40f 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3791,7 +3791,7 @@ static ssize_t cgroup_type_write(struct kernfs_open_file *of, char *buf,
/* drain dying csses before we re-apply (threaded) subtree control */
cgrp = cgroup_kn_lock_live(of->kn, true);
if (!cgrp)
- return -ENOENT;
+ return -ENODEV;
/* threaded can only be enabled */
ret = cgroup_enable_threaded(cgrp);
@@ -3834,7 +3834,7 @@ static ssize_t cgroup_max_descendants_write(struct kernfs_open_file *of,
cgrp = cgroup_kn_lock_live(of->kn, false);
if (!cgrp)
- return -ENOENT;
+ return -ENODEV;
WRITE_ONCE(cgrp->max_descendants, descendants);
@@ -3877,7 +3877,7 @@ static ssize_t cgroup_max_depth_write(struct kernfs_open_file *of,
cgrp = cgroup_kn_lock_live(of->kn, false);
if (!cgrp)
- return -ENOENT;
+ return -ENODEV;
WRITE_ONCE(cgrp->max_depth, depth);
@@ -4193,7 +4193,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of,
cgrp = cgroup_kn_lock_live(of->kn, false);
if (!cgrp)
- return -ENOENT;
+ return -ENODEV;
psi = cgroup_psi(cgrp);
if (psi->enabled != enable) {
@@ -4269,7 +4269,7 @@ static ssize_t cgroup_freeze_write(struct kernfs_open_file *of,
cgrp = cgroup_kn_lock_live(of->kn, false);
if (!cgrp)
- return -ENOENT;
+ return -ENODEV;
cgroup_freeze(cgrp, freeze);
@@ -4331,7 +4331,7 @@ static ssize_t cgroup_kill_write(struct kernfs_open_file *of, char *buf,
cgrp = cgroup_kn_lock_live(of->kn, false);
if (!cgrp)
- return -ENOENT;
+ return -ENODEV;
/*
* Killing is a process directed operation, i.e. the whole thread-group
--
2.55.0