Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: batman-adv: check kmalloc() return value

kmalloc() may fail, if so drop current packet.

Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
[sven.eckelmann@gmx.de: Removed new introduced deadlock]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Vasiliy Kulikov and committed by
Greg Kroah-Hartman
ff75f96b b001f71e

+13 -5
+6 -2
drivers/staging/batman-adv/routing.c
··· 1232 1232 1233 1233 orig_node->last_frag_packet = jiffies; 1234 1234 1235 - if (list_empty(&orig_node->frag_list)) 1236 - create_frag_buffer(&orig_node->frag_list); 1235 + if (list_empty(&orig_node->frag_list) && 1236 + create_frag_buffer(&orig_node->frag_list)) { 1237 + spin_unlock_irqrestore(&bat_priv->orig_hash_lock, 1238 + flags); 1239 + return NET_RX_DROP; 1240 + } 1237 1241 1238 1242 tmp_frag_entry = 1239 1243 search_frag_packet(&orig_node->frag_list,
+6 -2
drivers/staging/batman-adv/unicast.c
··· 78 78 return; 79 79 } 80 80 81 - void create_frag_buffer(struct list_head *head) 81 + int create_frag_buffer(struct list_head *head) 82 82 { 83 83 int i; 84 84 struct frag_packet_list_entry *tfp; ··· 86 86 for (i = 0; i < FRAG_BUFFER_SIZE; i++) { 87 87 tfp = kmalloc(sizeof(struct frag_packet_list_entry), 88 88 GFP_ATOMIC); 89 + if (!tfp) { 90 + frag_list_free(head); 91 + return -ENOMEM; 92 + } 89 93 tfp->skb = NULL; 90 94 tfp->seqno = 0; 91 95 INIT_LIST_HEAD(&tfp->list); 92 96 list_add(&tfp->list, head); 93 97 } 94 98 95 - return; 99 + return 0; 96 100 } 97 101 98 102 struct frag_packet_list_entry *search_frag_packet(struct list_head *head,
+1 -1
drivers/staging/batman-adv/unicast.h
··· 30 30 struct sk_buff *skb); 31 31 32 32 void create_frag_entry(struct list_head *head, struct sk_buff *skb); 33 - void create_frag_buffer(struct list_head *head); 33 + int create_frag_buffer(struct list_head *head); 34 34 struct frag_packet_list_entry *search_frag_packet(struct list_head *head, 35 35 struct unicast_frag_packet *up); 36 36 void frag_list_free(struct list_head *head);