diff mbox series

[-next] mm: memcg: use meaningful error code for return value

Message ID 20240506133643.1124102-1-xiujianfeng@huawei.com (mailing list archive)
State New
Headers show
Series [-next] mm: memcg: use meaningful error code for return value | expand

Commit Message

Xiu Jianfeng May 6, 2024, 1:36 p.m. UTC
alloc_mem_cgroup_per_node_info() returns 1 if failed, use -ENOMEM
instead, which is more meaningful.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 mm/memcontrol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Matthew Wilcox (Oracle) May 6, 2024, 1:53 p.m. UTC | #1
On Mon, May 06, 2024 at 01:36:43PM +0000, Xiu Jianfeng wrote:
> alloc_mem_cgroup_per_node_info() returns 1 if failed, use -ENOMEM
> instead, which is more meaningful.

This should probably be changed to return true/false instead of
an int.
Michal Hocko May 6, 2024, 2:49 p.m. UTC | #2
On Mon 06-05-24 14:53:47, Matthew Wilcox wrote:
> On Mon, May 06, 2024 at 01:36:43PM +0000, Xiu Jianfeng wrote:
> > alloc_mem_cgroup_per_node_info() returns 1 if failed, use -ENOMEM
> > instead, which is more meaningful.
> 
> This should probably be changed to return true/false instead of
> an int.

Agreed. Or change the only caller to consume the error. Changing to bool
seems like the easiest way.
Xiu Jianfeng May 7, 2024, 11:17 a.m. UTC | #3
On 2024/5/6 21:53, Matthew Wilcox wrote:
> On Mon, May 06, 2024 at 01:36:43PM +0000, Xiu Jianfeng wrote:
>> alloc_mem_cgroup_per_node_info() returns 1 if failed, use -ENOMEM
>> instead, which is more meaningful.
> 
> This should probably be changed to return true/false instead of
> an int.
> 
OK, already sent v2.
diff mbox series

Patch

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d11536ef59ef..657f68b536c4 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5659,7 +5659,7 @@  static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 
 	pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, node);
 	if (!pn)
-		return 1;
+		return -ENOMEM;
 
 	pn->lruvec_stats = kzalloc_node(sizeof(struct lruvec_stats), GFP_KERNEL,
 					node);
@@ -5679,7 +5679,7 @@  static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
 fail:
 	kfree(pn->lruvec_stats);
 	kfree(pn);
-	return 1;
+	return -ENOMEM;
 }
 
 static void free_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)