diff options
author | Joonsoo Kim <iamjoonsoo.kim@lge.com> | 2013-12-02 03:49:40 -0500 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2014-02-08 05:10:35 -0500 |
commit | e5c58dfdcbd36f6b4c4c92c31cf6753d22da630a (patch) | |
tree | 77d6714ad9b14aefdef667c6efe72c58a5a6c6c7 /mm | |
parent | 9cef2e2b6589406562bf12a9a633d7d7630340a1 (diff) |
slab: introduce helper functions to get/set free object
In the following patches, to get/set free objects from the freelist
is changed so that simple casting doesn't work for it. Therefore,
introduce helper functions.
Acked-by: Christoph Lameter <cl@linux.com>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/slab.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -2548,9 +2548,15 @@ static void *alloc_slabmgmt(struct kmem_cache *cachep, | |||
2548 | return freelist; | 2548 | return freelist; |
2549 | } | 2549 | } |
2550 | 2550 | ||
2551 | static inline unsigned int *slab_freelist(struct page *page) | 2551 | static inline unsigned int get_free_obj(struct page *page, unsigned int idx) |
2552 | { | 2552 | { |
2553 | return (unsigned int *)(page->freelist); | 2553 | return ((unsigned int *)page->freelist)[idx]; |
2554 | } | ||
2555 | |||
2556 | static inline void set_free_obj(struct page *page, | ||
2557 | unsigned int idx, unsigned int val) | ||
2558 | { | ||
2559 | ((unsigned int *)(page->freelist))[idx] = val; | ||
2554 | } | 2560 | } |
2555 | 2561 | ||
2556 | static void cache_init_objs(struct kmem_cache *cachep, | 2562 | static void cache_init_objs(struct kmem_cache *cachep, |
@@ -2595,7 +2601,7 @@ static void cache_init_objs(struct kmem_cache *cachep, | |||
2595 | if (cachep->ctor) | 2601 | if (cachep->ctor) |
2596 | cachep->ctor(objp); | 2602 | cachep->ctor(objp); |
2597 | #endif | 2603 | #endif |
2598 | slab_freelist(page)[i] = i; | 2604 | set_free_obj(page, i, i); |
2599 | } | 2605 | } |
2600 | } | 2606 | } |
2601 | 2607 | ||
@@ -2614,7 +2620,7 @@ static void *slab_get_obj(struct kmem_cache *cachep, struct page *page, | |||
2614 | { | 2620 | { |
2615 | void *objp; | 2621 | void *objp; |
2616 | 2622 | ||
2617 | objp = index_to_obj(cachep, page, slab_freelist(page)[page->active]); | 2623 | objp = index_to_obj(cachep, page, get_free_obj(page, page->active)); |
2618 | page->active++; | 2624 | page->active++; |
2619 | #if DEBUG | 2625 | #if DEBUG |
2620 | WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid); | 2626 | WARN_ON(page_to_nid(virt_to_page(objp)) != nodeid); |
@@ -2635,7 +2641,7 @@ static void slab_put_obj(struct kmem_cache *cachep, struct page *page, | |||
2635 | 2641 | ||
2636 | /* Verify double free bug */ | 2642 | /* Verify double free bug */ |
2637 | for (i = page->active; i < cachep->num; i++) { | 2643 | for (i = page->active; i < cachep->num; i++) { |
2638 | if (slab_freelist(page)[i] == objnr) { | 2644 | if (get_free_obj(page, i) == objnr) { |
2639 | printk(KERN_ERR "slab: double free detected in cache " | 2645 | printk(KERN_ERR "slab: double free detected in cache " |
2640 | "'%s', objp %p\n", cachep->name, objp); | 2646 | "'%s', objp %p\n", cachep->name, objp); |
2641 | BUG(); | 2647 | BUG(); |
@@ -2643,7 +2649,7 @@ static void slab_put_obj(struct kmem_cache *cachep, struct page *page, | |||
2643 | } | 2649 | } |
2644 | #endif | 2650 | #endif |
2645 | page->active--; | 2651 | page->active--; |
2646 | slab_freelist(page)[page->active] = objnr; | 2652 | set_free_obj(page, page->active, objnr); |
2647 | } | 2653 | } |
2648 | 2654 | ||
2649 | /* | 2655 | /* |
@@ -4216,7 +4222,7 @@ static void handle_slab(unsigned long *n, struct kmem_cache *c, | |||
4216 | 4222 | ||
4217 | for (j = page->active; j < c->num; j++) { | 4223 | for (j = page->active; j < c->num; j++) { |
4218 | /* Skip freed item */ | 4224 | /* Skip freed item */ |
4219 | if (slab_freelist(page)[j] == i) { | 4225 | if (get_free_obj(page, j) == i) { |
4220 | active = false; | 4226 | active = false; |
4221 | break; | 4227 | break; |
4222 | } | 4228 | } |