From: Joe Perches <joe@perches.com>
To: xkernel.wang@foxmail.com, Larry.Finger@lwfinger.net,
phil@philpotter.co.uk, gregkh@linuxfoundation.org
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 12/12] staging: r8188eu: check the return of kzalloc()
Date: Tue, 03 May 2022 00:08:46 -0700 [thread overview]
Message-ID: <f6421e8f75a030222bf9cc7ef191648f7495a511.camel@perches.com> (raw)
In-Reply-To: <tencent_702C3C4AA9F65F0EE48859211795E3800205@qq.com>
On Tue, 2022-05-03 at 15:02 +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> kzalloc() is a memory allocation function which can return NULL when
> some internal memory errors happen. So it is better to handle the return
> of it to prevent potential wrong memory access.
>
> Besides, to propagate the error to the caller, the type of
> rtw_alloc_hwxmits() is changed to `int` and another check is added to
> its caller.
> Then if kzalloc() fails, the caller will properly jump to the
> corresponding error hanlding code.
It'd be better to use the typical error returns
> diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c
[]
> @@ -176,7 +176,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 free_xmit_extbuf;
if (res)
goto free_xmit_extbuf;
[]
> -void rtw_alloc_hwxmits(struct adapter *padapter)
> +int rtw_alloc_hwxmits(struct adapter *padapter)
> {
> struct hw_xmit *hwxmits;
> struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
> @@ -1495,6 +1497,8 @@ void rtw_alloc_hwxmits(struct adapter *padapter)
> pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
>
> pxmitpriv->hwxmits = kzalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry, GFP_KERNEL);
> + if (!pxmitpriv->hwxmits)
return -ENOMEM;
next prev parent reply other threads:[~2022-05-04 7:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-03 6:56 [PATCH 00/12] staging: some memory-related patches xkernel.wang
2022-05-03 6:57 ` [PATCH 01/12] staging: rtl8712: fix potential memory leak in r8712_xmit_resource_alloc() xkernel.wang
2022-05-03 6:58 ` [PATCH 02/12] staging: rtl8712: fix potential memory leak in _r8712_init_xmit_priv() xkernel.wang
2022-05-03 6:58 ` [PATCH 03/12] staging: rtl8712: fix potential memory leak in r8712_init_drv_sw() xkernel.wang
2022-05-03 6:59 ` [PATCH 04/12] staging: rtl8712: change the type of _r8712_init_recv_priv() xkernel.wang
2022-05-03 6:59 ` [PATCH 05/12] staging: rtl8712: add two validation check in r8712_init_drv_sw() xkernel.wang
2022-05-03 7:00 ` [PATCH 06/12] staging: rtl8723bs: fix a potential memory leak in rtw_init_cmd_priv() xkernel.wang
2022-05-03 7:00 ` [PATCH 07/12] staging: rtl8723bs: fix potential memory leak in _rtw_init_xmit_priv() xkernel.wang
2022-05-03 7:00 ` [PATCH 08/12] staging: rtl8723bs: fix potential memory leak in rtw_init_drv_sw() xkernel.wang
2022-05-03 7:01 ` [PATCH 09/12] staging: r8188eu: fix a potential memory leak in _rtw_init_cmd_priv() xkernel.wang
2022-05-03 7:01 ` [PATCH 10/12] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc() xkernel.wang
2022-05-03 7:02 ` [PATCH 11/12] staging: r8188eu: fix potential memory leak in _rtw_init_xmit_priv() xkernel.wang
2022-05-03 7:02 ` [PATCH 12/12] staging: r8188eu: check the return of kzalloc() xkernel.wang
2022-05-03 7:08 ` Joe Perches [this message]
2022-05-03 8:22 ` xkernel.wang
2022-06-06 6:11 ` [PATCH 00/12] staging: some memory-related patches Greg KH
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=f6421e8f75a030222bf9cc7ef191648f7495a511.camel@perches.com \
--to=joe@perches.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).