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 2/2] staging: r8188eu: fix potential memory leak in _rtw_init_xmit_priv()
Date: Thu, 31 Mar 2022 10:35:55 +0300 [thread overview]
Message-ID: <20220331073555.GK3293@kadam> (raw)
In-Reply-To: <tencent_2F72CC5068850B2BEDFC2B8058303FE6520A@qq.com>
On Wed, Mar 30, 2022 at 11:29:22PM +0800, xkernel.wang@foxmail.com wrote:
> @@ -134,7 +134,12 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
> msleep(10);
> res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
> if (res == _FAIL) {
> - goto exit;
> + pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
> + for (; i >= 0; i--) {
This frees one more element than you intended. It should be:
while (--i >= 0) {
> + rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
> + pxmitbuf++;
> + }
> + goto free_xmitbuf;
> }
> }
>
> @@ -153,7 +158,7 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
>
> if (!pxmitpriv->pallocated_xmit_extbuf) {
> res = _FAIL;
> - goto exit;
> + goto free_pxmitbuf;
> }
>
> pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_xmit_extbuf), 4);
> @@ -169,8 +174,12 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
>
> res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, max_xmit_extbuf_size + XMITBUF_ALIGN_SZ);
> if (res == _FAIL) {
> - res = _FAIL;
> - goto exit;
> + pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
> + for (; i >= 0; i--) {
Same thing here.
> + rtw_os_xmit_resource_free(padapter, pxmitbuf, (max_xmit_extbuf_size + XMITBUF_ALIGN_SZ));
> + pxmitbuf++;
> + }
> + goto free_xmit_extbuf;
> }
>
> list_add_tail(&pxmitbuf->list, &pxmitpriv->free_xmit_extbuf_queue.queue);
[ snip ]
> diff --git a/drivers/staging/r8188eu/os_dep/xmit_linux.c b/drivers/staging/r8188eu/os_dep/xmit_linux.c
> index 565ac5b..7aa39b5 100644
> --- a/drivers/staging/r8188eu/os_dep/xmit_linux.c
> +++ b/drivers/staging/r8188eu/os_dep/xmit_linux.c
> @@ -95,8 +95,14 @@ void rtw_os_xmit_resource_free(struct adapter *padapter,
> {
> int i;
>
> - for (i = 0; i < 8; i++)
> + if (!pxmitbuf->pallocated_buf)
> + return;
> +
> + for (i = 0; i < 8; i++) {
> + if (!pxmitbuf->pxmit_urb[i])
> + break;
> usb_free_urb(pxmitbuf->pxmit_urb[i]);
> + }
>
> kfree(pxmitbuf->pallocated_buf);
No need to modify rtw_os_xmit_resource_free(). Passing a NULL to
usb_free_urb() or kfree() is a no op.
regards,
dan carpenter
next prev parent reply other threads:[~2022-03-31 7:36 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 [this message]
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
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=20220331073555.GK3293@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.