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