From 6f92e9048b5a008ac0d1dd2a81e0e8aeeffa9549 Mon Sep 17 00:00:00 2001 From: Michal Koutný Date: May 29 2023 13:51:35 +0000 Subject: cgroup: Make cgroup_get_from_id() prettier (bsc#1205650). --- diff --git a/patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch b/patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch new file mode 100644 index 0000000..b48d21f --- /dev/null +++ b/patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch @@ -0,0 +1,80 @@ +From: Tejun Heo +Date: Fri, 23 Sep 2022 07:23:06 -1000 +Subject: cgroup: Make cgroup_get_from_id() prettier +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Git-commit: 7e1eb5437d3c3fdb61d45378579aab383cafc694 +Patch-mainline: v6.1-rc1 +References: bsc#1205650 + +After merging 836ac87d ("cgroup: fix cgroup_get_from_id") into for-6.1, its +combination with two commits in for-6.1 - 4534dee9 ("cgroup: cgroup: Honor +caller's cgroup NS when resolving cgroup id") and fa7e439c ("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 +Cc: Ming Lei +Cc: Michal Koutný + +Acked-by: Michal Koutný +--- + kernel/cgroup/cgroup.c | 19 ++++++++++--------- + 1 file changed, 10 insertions(+), 9 deletions(-) + +diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c +index 0d93cd17548c..c1f1ef6090da 100644 +--- a/kernel/cgroup/cgroup.c ++++ b/kernel/cgroup/cgroup.c +@@ -6066,14 +6066,16 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) + struct cgroup *cgroup_get_from_id(u64 id) + { + struct kernfs_node *kn; +- struct cgroup *cgrp = NULL, *root_cgrp; ++ struct cgroup *cgrp, *root_cgrp; + + kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id); + if (!kn) +- goto out; ++ return ERR_PTR(-ENOENT); + +- if (kernfs_type(kn) != KERNFS_DIR) +- goto put; ++ if (kernfs_type(kn) != KERNFS_DIR) { ++ kernfs_put(kn); ++ return ERR_PTR(-ENOENT); ++ } + + rcu_read_lock(); + +@@ -6082,21 +6084,20 @@ struct cgroup *cgroup_get_from_id(u64 id) + cgrp = NULL; + + rcu_read_unlock(); +-put: + kernfs_put(kn); + + if (!cgrp) +- goto out; ++ return ERR_PTR(-ENOENT); + + spin_lock_irq(&css_set_lock); + root_cgrp = current_cgns_cgroup_from_root(&cgrp_dfl_root); + spin_unlock_irq(&css_set_lock); + if (!cgroup_is_descendant(cgrp, root_cgrp)) { + cgroup_put(cgrp); +- cgrp = NULL; ++ return ERR_PTR(-ENOENT); + } +-out: +- return cgrp ?: ERR_PTR(-ENOENT); ++ ++ return cgrp; + } + EXPORT_SYMBOL_GPL(cgroup_get_from_id); + + diff --git a/series.conf b/series.conf index 30a9dd1..9823540 100644 --- a/series.conf +++ b/series.conf @@ -16710,6 +16710,7 @@ patches.suse/cgroup-cgroup-Honor-caller-s-cgroup-NS-when-resolving-cgroup-id.patch patches.suse/cgroup-Homogenize-cgroup_get_from_id-return-value.patch patches.suse/cgroup-cpuset-Enable-update_tasks_cpumask-on-top_cpuset.patch + patches.suse/cgroup-Make-cgroup_get_from_id-prettier.patch patches.suse/livepatch-fix-race-between-fork-and-KLP-transition.patch patches.suse/livepatch-Add-a-missing-newline-character-in-klp_mod.patch patches.suse/kbuild-remove-the-target-in-signal-traps-when-interr.patch