summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>2015-08-26 20:36:17 +0300
committerDmitry Kovalenko <d.kovalenko@samsung.com>2015-08-27 23:44:37 -0700
commitea80e0154da6f2461e754a7479eb6c253a3bf44f (patch)
tree5de3e1efda502e190a33f4037643016655302466
parentfc2233c679282f5cb5f6f0f7baf21f1d10a0029d (diff)
downloadswap-modules-ea80e0154da6f2461e754a7479eb6c253a3bf44f.tar.gz
swap-modules-ea80e0154da6f2461e754a7479eb6c253a3bf44f.tar.bz2
swap-modules-ea80e0154da6f2461e754a7479eb6c253a3bf44f.zip
[FIX] Add chunk_init result checking
Change-Id: Id5534256ac7d492151e51c41d623338032d4fbfb Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
-rw-r--r--kprobe/swap_slots.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/kprobe/swap_slots.c b/kprobe/swap_slots.c
index f0aea189..58869e4a 100644
--- a/kprobe/swap_slots.c
+++ b/kprobe/swap_slots.c
@@ -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)