summaryrefslogtreecommitdiffstats
path: root/drivers/staging/batman-adv/originator.c
diff options
context:
space:
mode:
authorSimon Wunderlich <siwu@hrz.tu-chemnitz.de>2010-01-02 11:30:47 +0100
committerGreg Kroah-Hartman <gregkh@suse.de>2010-03-03 16:42:35 -0800
commitc4bf05d3960981a4291bcc9580f3d73eb4dcbe84 (patch)
tree9d9f214988a259ba96f522ee65e741cec1b9bef9 /drivers/staging/batman-adv/originator.c
parente9b764506aeb06ada6a7d0a24eda3e6eb70bade1 (diff)
downloadop-kernel-dev-c4bf05d3960981a4291bcc9580f3d73eb4dcbe84.zip
op-kernel-dev-c4bf05d3960981a4291bcc9580f3d73eb4dcbe84.tar.gz
Staging: batman-adv: check all kmalloc()s
there are some kmallocs left which are not checked whether they succeeds or not, which might lead to corrupted data structures if the system memory is full. This patch should clean up the remaining unchecked kmalloc()s. Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de> Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/batman-adv/originator.c')
-rw-r--r--drivers/staging/batman-adv/originator.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/drivers/staging/batman-adv/originator.c b/drivers/staging/batman-adv/originator.c
index 6a1fdf2..71bd2cf 100644
--- a/drivers/staging/batman-adv/originator.c
+++ b/drivers/staging/batman-adv/originator.c
@@ -77,6 +77,9 @@ create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
bat_dbg(DBG_BATMAN, "Creating new last-hop neighbor of originator\n");
neigh_node = kmalloc(sizeof(struct neigh_node), GFP_ATOMIC);
+ if (!neigh_node)
+ return NULL;
+
memset(neigh_node, 0, sizeof(struct neigh_node));
INIT_LIST_HEAD(&neigh_node->list);
@@ -127,6 +130,9 @@ struct orig_node *get_orig_node(uint8_t *addr)
bat_dbg(DBG_BATMAN, "Creating new originator: %s \n", orig_str);
orig_node = kmalloc(sizeof(struct orig_node), GFP_ATOMIC);
+ if (!orig_node)
+ return NULL;
+
memset(orig_node, 0, sizeof(struct orig_node));
INIT_LIST_HEAD(&orig_node->neigh_list);
@@ -138,13 +144,20 @@ struct orig_node *get_orig_node(uint8_t *addr)
size = num_ifs * sizeof(TYPE_OF_WORD) * NUM_WORDS;
orig_node->bcast_own = kmalloc(size, GFP_ATOMIC);
+ if (!orig_node->bcast_own)
+ goto free_orig_node;
+
memset(orig_node->bcast_own, 0, size);
size = num_ifs * sizeof(uint8_t);
orig_node->bcast_own_sum = kmalloc(size, GFP_ATOMIC);
+ if (!orig_node->bcast_own_sum)
+ goto free_bcast_own;
+
memset(orig_node->bcast_own_sum, 0, size);
- hash_add(orig_hash, orig_node);
+ if (hash_add(orig_hash, orig_node) < 0)
+ goto free_bcast_own_sum;
if (orig_hash->elements * 4 > orig_hash->size) {
swaphash = hash_resize(orig_hash, orig_hash->size * 2);
@@ -157,6 +170,13 @@ struct orig_node *get_orig_node(uint8_t *addr)
}
return orig_node;
+free_bcast_own_sum:
+ kfree(orig_node->bcast_own_sum);
+free_bcast_own:
+ kfree(orig_node->bcast_own);
+free_orig_node:
+ kfree(orig_node);
+ return NULL;
}
static bool purge_orig_neighbors(struct orig_node *orig_node,
OpenPOWER on IntegriCloud