mm: slub: remove dead and buggy code from sysfs_slab_add()
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Fri, 30 Sep 2022 08:47:42 +0000 (10:47 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Mon, 24 Oct 2022 10:19:06 +0000 (12:19 +0200)
commit979857ea2deae05454d257f119bedfe84a2c74d9
tree510da8eba9877ebfd098beca665b9c73f1a1baf1
parent247f34f7b80357943234f93f247a1ae6b6c3a740
mm: slub: remove dead and buggy code from sysfs_slab_add()

The function sysfs_slab_add() has two callers:

One is slab_sysfs_init(), which first initializes slab_kset, and only
when that succeeds sets slab_state to FULL, and then proceeds to call
sysfs_slab_add() for all previously created slabs.

The other is __kmem_cache_create(), but only after a

if (slab_state <= UP)
return 0;

check.

So in other words, sysfs_slab_add() is never called without
slab_kset (aka the return value of cache_kset()) being non-NULL.

And this is just as well, because if we ever did take this path and
called kobject_init(&s->kobj), and then later when called again from
slab_sysfs_init() would end up calling kobject_init_and_add(), we
would hit

if (kobj->state_initialized) {
/* do not error out as sometimes we can recover */
pr_err("kobject (%p): tried to init an initialized object, something is seriously wrong.\n",
dump_stack();
}

in kobject.c.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c