Skip to contentSkip to conversation

mwifiex: correctly handling kzalloc

PATCH In review Insu Yun 2 participants 2 messages Dec 29, 2015

Subsystems (3)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 mwifiex: correctly handling kzalloc

Since kzalloc can be failed in memory pressure,
it needs to be handled as above kzalloc.

---
 drivers/net/wireless/mwifiex/sdio.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/mwifiex/sdio.c +6 -0
index 78a8474..d114934 100644
@@ -2053,8 +2053,14 @@ 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)
+		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)
+		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
maintainer
#1 lore raw

From: Insu Yun <[email protected]>
Date: Tue, 29 Dec 2015 14:55:25 -0500

Quoted 17 lines

Since kzalloc can be failed in memory pressure,
it needs to be handled as above kzalloc.

---
 drivers/net/wireless/mwifiex/sdio.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/mwifiex/sdio.c +1 -0
index 78a8474..d114934 100644
@@ -2053,8 +2053,14 @@ 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)

drivers/net/wireless/mwifiex/sdio.c static int mwifiex_init_sdio(struct mwifiex_adapter *adapter) · line 2066

Quoted 10 lines
drivers/net/wireless/mwifiex/sdio.c +5 -0
+		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)
+		return -ENOMEM;
+
 	ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
 					     card->mp_tx_agg_buf_size,
 					     card->mp_rx_agg_buf_size);

You can't just return, you have to release all of the resources acquired above the point where the error happens.
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html