aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slub.c
diff options
context:
space:
mode:
authorChristoph Lameter <cl@linux.com>2012-07-06 16:25:13 -0400
committerPekka Enberg <penberg@kernel.org>2012-07-09 05:13:42 -0400
commit20cea9683ecc6dd75a80c0dd02dc69c64e95be75 (patch)
treec52994730d2d280f9300197cc4f561b15e3dd4b2 /mm/slub.c
parent18004c5d4084d965aa1396392706b8688306427a (diff)
mm, sl[aou]b: Move kmem_cache_create mutex handling to common code
Move the mutex handling into the common kmem_cache_create() function. Then we can also move more checks out of SLAB's kmem_cache_create() into the common code. Reviewed-by: Glauber Costa <glommer@parallels.com> Signed-off-by: Christoph Lameter <cl@linux.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'mm/slub.c')
-rw-r--r--mm/slub.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/mm/slub.c b/mm/slub.c
index 8c4fd37541d7..0e0504ed6ff1 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3911,7 +3911,6 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
3911 struct kmem_cache *s; 3911 struct kmem_cache *s;
3912 char *n; 3912 char *n;
3913 3913
3914 mutex_lock(&slab_mutex);
3915 s = find_mergeable(size, align, flags, name, ctor); 3914 s = find_mergeable(size, align, flags, name, ctor);
3916 if (s) { 3915 if (s) {
3917 s->refcount++; 3916 s->refcount++;
@@ -3924,37 +3923,36 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
3924 3923
3925 if (sysfs_slab_alias(s, name)) { 3924 if (sysfs_slab_alias(s, name)) {
3926 s->refcount--; 3925 s->refcount--;
3927 goto err; 3926 return NULL;
3928 } 3927 }
3929 mutex_unlock(&slab_mutex);
3930 return s; 3928 return s;
3931 } 3929 }
3932 3930
3933 n = kstrdup(name, GFP_KERNEL); 3931 n = kstrdup(name, GFP_KERNEL);
3934 if (!n) 3932 if (!n)
3935 goto err; 3933 return NULL;
3936 3934
3937 s = kmalloc(kmem_size, GFP_KERNEL); 3935 s = kmalloc(kmem_size, GFP_KERNEL);
3938 if (s) { 3936 if (s) {
3939 if (kmem_cache_open(s, n, 3937 if (kmem_cache_open(s, n,
3940 size, align, flags, ctor)) { 3938 size, align, flags, ctor)) {
3939 int r;
3940
3941 list_add(&s->list, &slab_caches); 3941 list_add(&s->list, &slab_caches);
3942 mutex_unlock(&slab_mutex); 3942 mutex_unlock(&slab_mutex);
3943 if (sysfs_slab_add(s)) { 3943 r = sysfs_slab_add(s);
3944 mutex_lock(&slab_mutex); 3944 mutex_lock(&slab_mutex);
3945 list_del(&s->list); 3945
3946 kfree(n); 3946 if (!r)
3947 kfree(s); 3947 return s;
3948 goto err; 3948
3949 } 3949 list_del(&s->list);
3950 return s; 3950 kmem_cache_close(s);
3951 } 3951 }
3952 kfree(s); 3952 kfree(s);
3953 } 3953 }
3954 kfree(n); 3954 kfree(n);
3955err: 3955 return NULL;
3956 mutex_unlock(&slab_mutex);
3957 return s;
3958} 3956}
3959 3957
3960#ifdef CONFIG_SMP 3958#ifdef CONFIG_SMP