Skip to content

Commit 7491f7e

Browse files
committed
cgroup: Make cgroup_get_from_id() prettier
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2077665 commit 7e1eb54 Author: Tejun Heo <tj@kernel.org> Date: Fri, 23 Sep 2022 07:23:06 -1000 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> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent 43b08ea commit 7491f7e

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
@@ -6026,14 +6026,16 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen)
60266026
struct cgroup *cgroup_get_from_id(u64 id)
60276027
{
60286028
struct kernfs_node *kn;
6029-
struct cgroup *cgrp = NULL, *root_cgrp;
6029+
struct cgroup *cgrp, *root_cgrp;
60306030

60316031
kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id);
60326032
if (!kn)
6033-
goto out;
6033+
return ERR_PTR(-ENOENT);
60346034

6035-
if (kernfs_type(kn) != KERNFS_DIR)
6036-
goto put;
6035+
if (kernfs_type(kn) != KERNFS_DIR) {
6036+
kernfs_put(kn);
6037+
return ERR_PTR(-ENOENT);
6038+
}
60376039

60386040
rcu_read_lock();
60396041

@@ -6042,21 +6044,20 @@ struct cgroup *cgroup_get_from_id(u64 id)
60426044
cgrp = NULL;
60436045

60446046
rcu_read_unlock();
6045-
put:
60466047
kernfs_put(kn);
60476048

60486049
if (!cgrp)
6049-
goto out;
6050+
return ERR_PTR(-ENOENT);
60506051

60516052
spin_lock_irq(&css_set_lock);
60526053
root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root);
60536054
spin_unlock_irq(&css_set_lock);
60546055
if (!cgroup_is_descendant(cgrp, root_cgrp)) {
60556056
cgroup_put(cgrp);
6056-
cgrp = NULL;
6057+
return ERR_PTR(-ENOENT);
60576058
}
6058-
out:
6059-
return cgrp ?: ERR_PTR(-ENOENT);
6059+
6060+
return cgrp;
60606061
}
60616062
EXPORT_SYMBOL_GPL(cgroup_get_from_id);
60626063

0 commit comments

Comments
 (0)