[PATCH 3/8] memcg: mem_cgroup_get_from_ino() returns NULL on error

Shakeel Butt
2025-12-25T23:21:40Z

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().

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
---
mm/memcontrol.c | 6 ++----
mm/shrinker_debug.c | 2 +-
2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e85816960e38..92beb74482fa 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -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);

diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c
index 20eaee3e97f7..8aaeb8f5c3af 100644
--- a/mm/shrinker_debug.c
+++ b/mm/shrinker_debug.c
@@ -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)) {
--
2.47.3