From: Christoph Lameter If CONFIG_SYSFS is set then free the kmem_cache structure when sysfs tells us its okay. Signed-off-by: Christoph Lameter Reviewed-by: Pekka Enberg Signed-off-by: Andrew Morton --- mm/slub.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff -puN mm/slub.c~slub-fix-sysfs-refcounting mm/slub.c --- a/mm/slub.c~slub-fix-sysfs-refcounting +++ a/mm/slub.c @@ -218,7 +218,10 @@ static void sysfs_slab_remove(struct kme static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; } static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p) { return 0; } -static inline void sysfs_slab_remove(struct kmem_cache *s) {} +static inline void sysfs_slab_remove(struct kmem_cache *s) +{ + kfree(s); +} #endif /******************************************************************** @@ -2488,7 +2491,6 @@ void kmem_cache_destroy(struct kmem_cach if (kmem_cache_close(s)) WARN_ON(1); sysfs_slab_remove(s); - kfree(s); } else up_write(&slub_lock); } @@ -4114,6 +4116,13 @@ static ssize_t slab_attr_store(struct ko return err; } +static void kmem_cache_release(struct kobject *kobj) +{ + struct kmem_cache *s = to_slab(kobj); + + kfree(s); +} + static struct sysfs_ops slab_sysfs_ops = { .show = slab_attr_show, .store = slab_attr_store, @@ -4121,6 +4130,7 @@ static struct sysfs_ops slab_sysfs_ops = static struct kobj_type slab_ktype = { .sysfs_ops = &slab_sysfs_ops, + .release = kmem_cache_release }; static int uevent_filter(struct kset *kset, struct kobject *kobj) @@ -4222,6 +4232,7 @@ static void sysfs_slab_remove(struct kme { kobject_uevent(&s->kobj, KOBJ_REMOVE); kobject_del(&s->kobj); + kobject_put(&s->kobj); } /* _