public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Kang Chen <void0red@gmail.com>
Cc: paskripkin@gmail.com, Larry.Finger@lwfinger.net,
	phil@philpotter.co.uk, gregkh@linuxfoundation.org,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: r8188eu: add a null check of kzalloc in go_add_group_info_attr
Date: Mon, 27 Feb 2023 07:47:36 +0300	[thread overview]
Message-ID: <Y/w16PI4klfJaeXA@kadam> (raw)
In-Reply-To: <20230226132500.3933232-1-void0red@gmail.com>

On Sun, Feb 26, 2023 at 09:25:00PM +0800, Kang Chen wrote:
> kzalloc may fails, pdata_attr might be null and will cause
> illegal address access later.
> 
> Signed-off-by: Kang Chen <void0red@gmail.com>
> ---
>  drivers/staging/r8188eu/core/rtw_p2p.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_p2p.c b/drivers/staging/r8188eu/core/rtw_p2p.c
> index 93d3c9c43..802e1170a 100644
> --- a/drivers/staging/r8188eu/core/rtw_p2p.c
> +++ b/drivers/staging/r8188eu/core/rtw_p2p.c
> @@ -31,6 +31,8 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
>  	struct sta_priv *pstapriv = &padapter->stapriv;
>  
>  	pdata_attr = kzalloc(MAX_P2P_IE_LEN, GFP_KERNEL);
> +	if (!pdata_attr)
> +		return 0;

Return success here is not a good thing.  We have to fix the caller to
check for errors.  (Fixing a bug half way just makes it harder to find
the bug so it makes the situation worse).

regards,
dan carpenter


  reply	other threads:[~2023-02-27  4:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-26 13:25 [PATCH] staging: r8188eu: add a null check of kzalloc in go_add_group_info_attr Kang Chen
2023-02-27  4:47 ` Dan Carpenter [this message]
2023-02-27  7:11   ` Kang Chen
2023-02-27  7:18     ` Dan Carpenter
2023-02-27  7:23     ` 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=Y/w16PI4klfJaeXA@kadam \
    --to=error27@gmail.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=paskripkin@gmail.com \
    --cc=phil@philpotter.co.uk \
    --cc=void0red@gmail.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