[FIX] Add chunk_init result checking 76/46876/4
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 26 Aug 2015 17:36:17 +0000 (20:36 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Fri, 28 Aug 2015 06:44:37 +0000 (23:44 -0700)
Change-Id: Id5534256ac7d492151e51c41d623338032d4fbfb
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
kprobe/swap_slots.c

index f0aea18..58869e4 100644 (file)
@@ -80,10 +80,8 @@ struct fixed_alloc {
        struct chunk chunk;
 };
 
-static void chunk_init(struct chunk *chunk,
-                      void *data,
-                      size_t size,
-                      size_t size_block)
+static int chunk_init(struct chunk *chunk, void *data,
+                     size_t size, size_t size_block)
 {
        unsigned long i;
        unsigned long *p;
@@ -97,15 +95,16 @@ static void chunk_init(struct chunk *chunk,
        chunk->index = kmalloc(sizeof(*chunk->index)*chunk->count_available,
                               GFP_ATOMIC);
 
-
        if (chunk->index == NULL) {
-               printk(KERN_ERR "%s: failed to allocate memory\n", __FUNCTION__);
-               return;
+               pr_err("%s: failed to allocate memory\n", __func__);
+               return -ENOMEM;
        }
 
        p = chunk->index;
        for (i = 0; i != chunk->count_available; ++p)
                *p = ++i;
+
+       return 0;
 }
 
 static void chunk_uninit(struct chunk *chunk)
@@ -156,6 +155,7 @@ static inline int chunk_free(struct chunk *chunk)
 
 static struct fixed_alloc *create_fixed_alloc(struct slot_manager *sm)
 {
+       int ret;
        void *data;
        struct fixed_alloc *fa;
 
@@ -164,15 +164,21 @@ static struct fixed_alloc *create_fixed_alloc(struct slot_manager *sm)
                return NULL;
 
        data = sm->alloc(sm);
-       if (data == NULL) {
-               kfree(fa);
-               return NULL;
-       }
+       if (data == NULL)
+               goto free_fa;
 
-       chunk_init(&fa->chunk, data,
-                  PAGE_SIZE/sizeof(unsigned long), sm->slot_size);
+       ret = chunk_init(&fa->chunk, data,
+                        PAGE_SIZE / sizeof(unsigned long), sm->slot_size);
+       if (ret)
+               goto free_sm;
 
        return fa;
+
+free_sm:
+       sm->free(sm, data);
+free_fa:
+       kfree(fa);
+       return NULL;
 }
 
 static void free_fixed_alloc(struct slot_manager *sm, struct fixed_alloc *fa)