linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/slub: release kobject if kobject_init_and_add failed in sysfs_slab_add
@ 2022-08-11  2:52 Xin Hao
  2022-08-11  3:31 ` Hyeonggon Yoo
  0 siblings, 1 reply; 3+ messages in thread
From: Xin Hao @ 2022-08-11  2:52 UTC (permalink / raw)
  To: cl
  Cc: penberg, rientjes, iamjoonsoo.kim, akpm, vbabka, roman.gushchin,
	linux-mm, linux-kernel

In kobject_init_and_add() function, the refcount is setted by calling
kobject_init() function, regardless of whether the return value is zero
or not, therefore, we must call kobject_del(&s->kobj) to prevent memory
of s->kobj is leaked.

Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
---
 mm/slub.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index b1281b8654bd..63b0a8a3a71f 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5981,19 +5981,18 @@ static int sysfs_slab_add(struct kmem_cache *s)
 
 	err = sysfs_create_group(&s->kobj, &slab_attr_group);
 	if (err)
-		goto out_del_kobj;
+		goto out;
 
 	if (!unmergeable) {
 		/* Setup first alias */
 		sysfs_slab_alias(s, s->name);
 	}
+	return err;
 out:
 	if (!unmergeable)
 		kfree(name);
-	return err;
-out_del_kobj:
 	kobject_del(&s->kobj);
-	goto out;
+	return err;
 }
 
 void sysfs_slab_unlink(struct kmem_cache *s)
-- 
2.31.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-11  3:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11  2:52 [PATCH] mm/slub: release kobject if kobject_init_and_add failed in sysfs_slab_add Xin Hao
2022-08-11  3:31 ` Hyeonggon Yoo
2022-08-11  3:52   ` haoxin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox