Skip to content

Commit 7398e7f

Browse files
committed
cgroup: Homogenize cgroup_get_from_id() return value
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2077665 commit fa7e439 Author: Michal Koutný <mkoutny@suse.com> Date: Fri, 26 Aug 2022 18:52:37 +0200 cgroup: Homogenize cgroup_get_from_id() return value Cgroup id is user provided datum hence extend its return domain to include possible error reason (similar to cgroup_get_from_fd()). This change also fixes commit d4ccaf5 ("bpf: Introduce cgroup iter") that would use NULL instead of proper error handling in d4ccaf5 ("bpf: Introduce cgroup iter"). Additionally, neither of: fc_appid_store, bpf_iter_attach_cgroup, mem_cgroup_get_from_ino (callers of cgroup_get_from_fd) is built without CONFIG_CGROUPS (depends via CONFIG_BLK_CGROUP, direct, transitive CONFIG_MEMCG respectively) transitive, so drop the singular definition not needed with !CONFIG_CGROUPS. Fixes: d4ccaf5 ("bpf: Introduce cgroup iter") Signed-off-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent 5f4c90d commit 7398e7f

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

block/blk-cgroup-fc-appid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ int blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len)
1919
return -EINVAL;
2020

2121
cgrp = cgroup_get_from_id(cgrp_id);
22-
if (!cgrp)
23-
return -ENOENT;
22+
if (IS_ERR(cgrp))
23+
return PTR_ERR(cgrp);
2424
css = cgroup_get_e_css(cgrp, &io_cgrp_subsys);
2525
if (!css) {
2626
ret = -ENOENT;

include/linux/cgroup.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,6 @@ static inline bool task_under_cgroup_hierarchy(struct task_struct *task,
752752

753753
static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen)
754754
{}
755-
756-
static inline struct cgroup *cgroup_get_from_id(u64 id)
757-
{
758-
return NULL;
759-
}
760755
#endif /* !CONFIG_CGROUPS */
761756

762757
#ifdef CONFIG_CGROUPS

kernel/cgroup/cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6020,7 +6020,7 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen)
60206020
/*
60216021
* cgroup_get_from_id : get the cgroup associated with cgroup id
60226022
* @id: cgroup id
6023-
* On success return the cgrp, on failure return NULL
6023+
* On success return the cgrp or ERR_PTR on failure
60246024
* Only cgroups within current task's cgroup NS are valid.
60256025
*/
60266026
struct cgroup *cgroup_get_from_id(u64 id)
@@ -6056,7 +6056,7 @@ struct cgroup *cgroup_get_from_id(u64 id)
60566056
cgrp = NULL;
60576057
}
60586058
out:
6059-
return cgrp;
6059+
return cgrp ?: ERR_PTR(-ENOENT);
60606060
}
60616061
EXPORT_SYMBOL_GPL(cgroup_get_from_id);
60626062

mm/memcontrol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5146,8 +5146,8 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino)
51465146
struct mem_cgroup *memcg;
51475147

51485148
cgrp = cgroup_get_from_id(ino);
5149-
if (!cgrp)
5150-
return ERR_PTR(-ENOENT);
5149+
if (IS_ERR(cgrp))
5150+
return PTR_ERR(cgrp);
51515151

51525152
css = cgroup_get_e_css(cgrp, &memory_cgrp_subsys);
51535153
if (css)

0 commit comments

Comments
 (0)