mwifiex: correctly handling kzalloc
authorInsu Yun <wuninsu@gmail.com>
Wed, 30 Dec 2015 16:01:44 +0000 (11:01 -0500)
committerKalle Valo <kvalo@codeaurora.org>
Thu, 7 Jan 2016 09:11:51 +0000 (11:11 +0200)
Since kzalloc can be failed in memory pressure,
it needs to be handled, otherwise NULL dereference could be happened

Signed-off-by: Insu Yun <wuninsu@gmail.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/marvell/mwifiex/sdio.c

index 78a8474..a8af72d 100644 (file)
@@ -2053,8 +2053,19 @@ static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
        /* Allocate skb pointer buffers */
        card->mpa_rx.skb_arr = kzalloc((sizeof(void *)) *
                                       card->mp_agg_pkt_limit, GFP_KERNEL);
+       if (!card->mpa_rx.skb_arr) {
+               kfree(card->mp_regs);
+               return -ENOMEM;
+       }
+
        card->mpa_rx.len_arr = kzalloc(sizeof(*card->mpa_rx.len_arr) *
                                       card->mp_agg_pkt_limit, GFP_KERNEL);
+       if (!card->mpa_rx.len_arr) {
+               kfree(card->mp_regs);
+               kfree(card->mpa_rx.skb_arr);
+               return -ENOMEM;
+       }
+
        ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
                                             card->mp_tx_agg_buf_size,
                                             card->mp_rx_agg_buf_size);