memcg: mem_cgroup_get_from_ino() returns NULL on error

Change mem_cgroup_get_from_ino() to return NULL on error instead of
ERR_PTR values.  This simplifies the API: NULL indicates failure, and a
valid pointer indicates success with a CSS reference held that the caller
must release via mem_cgroup_put().

Link: https://lkml.kernel.org/r/20251225232116.294540-4-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: SeongJae Park <sj@kernel.org>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
master
Shakeel Butt 2025-12-25 15:21:11 -08:00 committed by Andrew Morton
parent 1d89d7fd59
commit 510e129002
2 changed files with 3 additions and 5 deletions

View File

@ -3624,17 +3624,15 @@ struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino)
{
struct cgroup *cgrp;
struct cgroup_subsys_state *css;
struct mem_cgroup *memcg;
struct mem_cgroup *memcg = NULL;
cgrp = cgroup_get_from_id(ino);
if (IS_ERR(cgrp))
return ERR_CAST(cgrp);
return NULL;
css = cgroup_get_e_css(cgrp, &memory_cgrp_subsys);
if (css)
memcg = container_of(css, struct mem_cgroup, css);
else
memcg = ERR_PTR(-ENOENT);
cgroup_put(cgrp);

View File

@ -130,7 +130,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
if (shrinker->flags & SHRINKER_MEMCG_AWARE) {
memcg = mem_cgroup_get_from_ino(ino);
if (!memcg || IS_ERR(memcg))
if (!memcg)
return -ENOENT;
if (!mem_cgroup_online(memcg)) {