SLUB: Fix sysfs refcounting

If CONFIG_SYSFS is set then free the kmem_cache structure when
sysfs tells us its okay.

Otherwise there is the danger (as pointed out by
Al Viro) that sysfs thinks the kobject still exists after
kmem_cache_destroy() removed it.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Reviewed-by: Pekka J Enberg <penberg@cs.helsinki.fi>

+13 -2
+13 -2
mm/slub.c
··· 247 247 static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; } 248 248 static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p) 249 249 { return 0; } 250 - static inline void sysfs_slab_remove(struct kmem_cache *s) {} 250 + static inline void sysfs_slab_remove(struct kmem_cache *s) 251 + { 252 + kfree(s); 253 + } 251 254 #endif 252 255 253 256 /******************************************************************** ··· 2325 2322 if (kmem_cache_close(s)) 2326 2323 WARN_ON(1); 2327 2324 sysfs_slab_remove(s); 2328 - kfree(s); 2329 2325 } else 2330 2326 up_write(&slub_lock); 2331 2327 } ··· 3939 3937 return err; 3940 3938 } 3941 3939 3940 + static void kmem_cache_release(struct kobject *kobj) 3941 + { 3942 + struct kmem_cache *s = to_slab(kobj); 3943 + 3944 + kfree(s); 3945 + } 3946 + 3942 3947 static struct sysfs_ops slab_sysfs_ops = { 3943 3948 .show = slab_attr_show, 3944 3949 .store = slab_attr_store, ··· 3953 3944 3954 3945 static struct kobj_type slab_ktype = { 3955 3946 .sysfs_ops = &slab_sysfs_ops, 3947 + .release = kmem_cache_release 3956 3948 }; 3957 3949 3958 3950 static int uevent_filter(struct kset *kset, struct kobject *kobj) ··· 4055 4045 { 4056 4046 kobject_uevent(&s->kobj, KOBJ_REMOVE); 4057 4047 kobject_del(&s->kobj); 4048 + kobject_put(&s->kobj); 4058 4049 } 4059 4050 4060 4051 /*