diff options
author | Richard Braun <rbraun@sceen.net> | 2013-06-09 16:58:51 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2013-06-09 16:58:51 +0200 |
commit | cf79b6a9a9d4ceef4f69d0e8c691cd198863cd67 (patch) | |
tree | e4e4e1aa025ed9b75a44b4ac2841ac8bcf4ffd4f /kern | |
parent | b99130d97a40c8337d152669add0fce6c65e7377 (diff) |
Fix object construction in the slab allocator
There is currently no actual use of constructors, which is why this bug has
been long overlooked.
* kern/slab.c (kmem_cpu_pool_fill): Call constructor on buffers unless
verification is enabled for the cache, or the constructor is NULL.
Diffstat (limited to 'kern')
-rw-r--r-- | kern/slab.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/kern/slab.c b/kern/slab.c index 56fadbf..5c697cd 100644 --- a/kern/slab.c +++ b/kern/slab.c @@ -615,18 +615,24 @@ static inline void kmem_cpu_pool_push(struct kmem_cpu_pool *cpu_pool, void *obj) static int kmem_cpu_pool_fill(struct kmem_cpu_pool *cpu_pool, struct kmem_cache *cache) { - void *obj; + kmem_cache_ctor_t ctor; + void *buf; int i; + ctor = (cpu_pool->flags & KMEM_CF_VERIFY) ? NULL : cache->ctor; + simple_lock(&cache->lock); for (i = 0; i < cpu_pool->transfer_size; i++) { - obj = kmem_cache_alloc_from_slab(cache); + buf = kmem_cache_alloc_from_slab(cache); - if (obj == NULL) + if (buf == NULL) break; - kmem_cpu_pool_push(cpu_pool, obj); + if (ctor != NULL) + ctor(buf); + + kmem_cpu_pool_push(cpu_pool, buf); } simple_unlock(&cache->lock); |