linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: xkernel.wang@foxmail.com
Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk,
	gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] staging: r8188eu: properly handle the kzalloc()
Date: Thu, 31 Mar 2022 09:37:33 +0300	[thread overview]
Message-ID: <20220331063733.GJ3293@kadam> (raw)
In-Reply-To: <tencent_12789CD2DEBF33C818B3542E170737854506@qq.com>

On Wed, Mar 30, 2022 at 11:16:07PM +0800, xkernel.wang@foxmail.com wrote:
> diff --git a/drivers/staging/r8188eu/core/rtw_p2p.c b/drivers/staging/r8188eu/core/rtw_p2p.c
> index e2b6cf2..f1a5df8 100644
> --- a/drivers/staging/r8188eu/core/rtw_p2p.c
> +++ b/drivers/staging/r8188eu/core/rtw_p2p.c
> @@ -27,15 +27,14 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
>  	struct list_head *phead, *plist;
>  	u32 len = 0;
>  	u16 attr_len = 0;
> -	u8 tmplen, *pdata_attr, *pstart, *pcur;
> +	u8 pdata_attr[MAX_P2P_IE_LEN] = { 0x00 };
> +	u8 tmplen, *pstart, *pcur;
>  	struct sta_info *psta = NULL;
>  	struct adapter *padapter = pwdinfo->padapter;
>  	struct sta_priv *pstapriv = &padapter->stapriv;
>  
>  	DBG_88E("%s\n", __func__);
>  
> -	pdata_attr = kzalloc(MAX_P2P_IE_LEN, GFP_KERNEL);
> -
>  	pstart = pdata_attr;
>  	pcur = pdata_attr;
>  
> @@ -106,7 +105,6 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
>  	if (attr_len > 0)
>  		len = rtw_set_p2p_attr_content(pbuf, P2P_ATTR_GROUP_INFO, attr_len, pdata_attr);
>  
> -	kfree(pdata_attr);
>  	return len;
>  }
>  

This part is fine.  This change is can be pulled into a separate patch
and reviewed by itself.

> diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c
> index 46fe62c..5888979 100644
> --- a/drivers/staging/r8188eu/core/rtw_xmit.c
> +++ b/drivers/staging/r8188eu/core/rtw_xmit.c
> @@ -179,7 +179,9 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
>  
>  	pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
>  
> -	rtw_alloc_hwxmits(padapter);
> +	res = rtw_alloc_hwxmits(padapter);
> +	if (res == _FAIL)
> +		goto exit;

There needs to be some cleanup if rtw_alloc_hwxmits() fails.

>  	rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
>  
>  	for (i = 0; i < 4; i++)
> @@ -202,7 +204,6 @@ s32	_rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
>  	rtw_hal_init_xmit_priv(padapter);
>  
>  exit:
> -
>  	return res;

This whitespace change has nothing to do with allocating memory.  Leave
it out.

>  }
>  
> @@ -1516,7 +1517,7 @@ s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe)
>  	return res;
>  }
>  
> -void rtw_alloc_hwxmits(struct adapter *padapter)
> +s32 rtw_alloc_hwxmits(struct adapter *padapter)
>  {
>  	struct hw_xmit *hwxmits;
>  	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
> @@ -1525,6 +1526,9 @@ void rtw_alloc_hwxmits(struct adapter *padapter)
>  
>  	pxmitpriv->hwxmits = kzalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry, GFP_KERNEL);
>  
> +	if (!pxmitpriv->hwxmits)

Don't leave a blank line between the allocation and the check.

> +		return _FAIL;
> +
>  	hwxmits = pxmitpriv->hwxmits;
>  
>  	if (pxmitpriv->hwxmit_entry == 5) {

regards,
dan carpenter

      parent reply	other threads:[~2022-03-31  6:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-30 15:16 [PATCH 1/2] staging: r8188eu: properly handle the kzalloc() xkernel.wang
2022-03-30 15:29 ` [PATCH 2/2] staging: r8188eu: fix potential memory leak in _rtw_init_xmit_priv() xkernel.wang
2022-03-31  6:04   ` Greg KH
2022-03-31  7:35   ` Dan Carpenter
2022-03-31  8:21     ` Xiaoke Wang
2022-03-31  8:49       ` Dan Carpenter
     [not found]     ` <2022033116214474301568@foxmail.com>
2022-03-31  8:33       ` Xiaoke Wang
2022-03-31  9:20         ` Dan Carpenter
2022-03-31  6:03 ` [PATCH 1/2] staging: r8188eu: properly handle the kzalloc() Greg KH
2022-03-31  6:37 ` Dan Carpenter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220331063733.GJ3293@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=phil@philpotter.co.uk \
    --cc=xkernel.wang@foxmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).