Skip to content

Commit 7e1eb54

Browse files
committed
cgroup: Make cgroup_get_from_id() prettier
After merging 836ac87d ("cgroup: fix cgroup_get_from_id") into for-6.1, its combination with two commits in for-6.1 - 4534dee ("cgroup: cgroup: Honor caller's cgroup NS when resolving cgroup id") and fa7e439 ("cgroup: Homogenize cgroup_get_from_id() return value") - makes the gotos in the error handling path too ugly while not adding anything of value. All that the gotos are saving is one extra kernfs_put() call. Let's remove the gotos and perform error returns directly. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Ming Lei <ming.lei@redhat.com> Cc: Michal Koutný <mkoutny@suse.com>
1 parent 026e14a commit 7e1eb54

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

kernel/cgroup/cgroup.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6066,14 +6066,16 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen)
60666066
struct cgroup *cgroup_get_from_id(u64 id)
60676067
{
60686068
struct kernfs_node *kn;
6069-
struct cgroup *cgrp = NULL, *root_cgrp;
6069+
struct cgroup *cgrp, *root_cgrp;
60706070

60716071
kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id);
60726072
if (!kn)
6073-
goto out;
6073+
return ERR_PTR(-ENOENT);
60746074

6075-
if (kernfs_type(kn) != KERNFS_DIR)
6076-
goto put;
6075+
if (kernfs_type(kn) != KERNFS_DIR) {
6076+
kernfs_put(kn);
6077+
return ERR_PTR(-ENOENT);
6078+
}
60776079

60786080
rcu_read_lock();
60796081

@@ -6082,21 +6084,20 @@ struct cgroup *cgroup_get_from_id(u64 id)
60826084
cgrp = NULL;
60836085

60846086
rcu_read_unlock();
6085-
put:
60866087
kernfs_put(kn);
60876088

60886089
if (!cgrp)
6089-
goto out;
6090+
return ERR_PTR(-ENOENT);
60906091

60916092
spin_lock_irq(&css_set_lock);
60926093
root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root);
60936094
spin_unlock_irq(&css_set_lock);
60946095
if (!cgroup_is_descendant(cgrp, root_cgrp)) {
60956096
cgroup_put(cgrp);
6096-
cgrp = NULL;
6097+
return ERR_PTR(-ENOENT);
60976098
}
6098-
out:
6099-
return cgrp ?: ERR_PTR(-ENOENT);
6099+
6100+
return cgrp;
61006101
}
61016102
EXPORT_SYMBOL_GPL(cgroup_get_from_id);
61026103

0 commit comments

Comments
 (0)