Skip to contentSkip to conversation

mwifiex: correctly handling kzalloc

PATCH Applied Insu Yun 2 participants 2 messages Dec 30, 2015 – Jan 7, 2016

Subsystems (3)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH v2 1/1 mwifiex: correctly handling kzalloc

Since kzalloc can be failed in memory pressure,
it needs to be handled, otherwise NULL dereference could be happened

---
 drivers/net/wireless/mwifiex/sdio.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/wireless/mwifiex/sdio.c +11 -0
index 78a8474..a8af72d 100644
@@ -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);
Signature · 1 line
1.9.1
Applied
#1 lore raw
Quoted 5 lines

Since kzalloc can be failed in memory pressure,
it needs to be handled, otherwise NULL dereference could be happened

Thanks, applied to wireless-drivers-next.git.

Kalle Valo