diff mbox

mwifiex: correctly handling kzalloc

Message ID 1451418925-11735-1-git-send-email-wuninsu@gmail.com
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Insu Yun Dec. 29, 2015, 7:55 p.m. UTC
Since kzalloc can be failed in memory pressure,
it needs to be handled as above kzalloc.

Signed-off-by: Insu Yun <wuninsu@gmail.com>
---
 drivers/net/wireless/mwifiex/sdio.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

David Miller Dec. 29, 2015, 8:09 p.m. UTC | #1
From: Insu Yun <wuninsu@gmail.com>
Date: Tue, 29 Dec 2015 14:55:25 -0500

> Since kzalloc can be failed in memory pressure,
> it needs to be handled as above kzalloc.
> 
> Signed-off-by: Insu Yun <wuninsu@gmail.com>
> ---
>  drivers/net/wireless/mwifiex/sdio.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/wireless/mwifiex/sdio.c b/drivers/net/wireless/mwifiex/sdio.c
> index 78a8474..d114934 100644
> --- a/drivers/net/wireless/mwifiex/sdio.c
> +++ b/drivers/net/wireless/mwifiex/sdio.c
> @@ -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);

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 netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/wireless/mwifiex/sdio.c b/drivers/net/wireless/mwifiex/sdio.c
index 78a8474..d114934 100644
--- a/drivers/net/wireless/mwifiex/sdio.c
+++ b/drivers/net/wireless/mwifiex/sdio.c
@@ -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);