From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: Ji-Hun Kim <ji_hun.kim@samsung.com>,
gregkh@linuxfoundation.org, forest@alittletooquiet.net
Cc: devel@driverdev.osuosl.org, y.k.oh@samsung.com,
kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org,
julia.lawall@lip6.fr, santhameena13@gmail.com
Subject: Re: [PATCH v2] staging: vt6655: check for memory allocation failures
Date: Thu, 29 Mar 2018 08:00:42 +0000 [thread overview]
Message-ID: <798fbe60-52aa-4fb0-0cd3-e2c067bd6c04@gmail.com> (raw)
In-Reply-To: <1522308157-26463-1-git-send-email-ji_hun.kim@samsung.com>
On 2018/3/29 15:22, Ji-Hun Kim wrote:
> There are no null pointer checking on rd_info and td_info values which
> are allocated by kzalloc. It has potential null pointer dereferencing
> issues. Add return when allocation is failed.
>
> Signed-off-by: Ji-Hun Kim <ji_hun.kim@samsung.com>
> ---
>
> Change: since v1:
>
> - Delete WARN_ON which can makes crashes on some machines.
> - Instead of return directly, goto freeing function for freeing previously
> allocated memory in the for loop after kzalloc() failed.
> - In the freeing function, if td_info and rd_info are not allocated, no
> needs to free.
>
> drivers/staging/vt6655/device_main.c | 64 +++++++++++++++++++++++++-----------
> 1 file changed, 44 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
> index fbc4bc6..ecbba43 100644
> --- a/drivers/staging/vt6655/device_main.c
> +++ b/drivers/staging/vt6655/device_main.c
> @@ -539,7 +539,8 @@ static void device_init_rd0_ring(struct vnt_private *priv)
> i ++, curr += sizeof(struct vnt_rx_desc)) {
> desc = &priv->aRD0Ring[i];
> desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_KERNEL);
> -
> + if (!desc->rd_info)
> + goto error;
> if (!device_alloc_rx_buf(priv, desc))
> dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
>
> @@ -550,6 +551,10 @@ static void device_init_rd0_ring(struct vnt_private *priv)
> if (i > 0)
> priv->aRD0Ring[i-1].next_desc = cpu_to_le32(priv->rd0_pool_dma);
> priv->pCurrRD[0] = &priv->aRD0Ring[0];
> +
> + return;
> +error:
> + device_free_rd0_ring(priv);
> }
>
I think you should return an error number here, because
device_init_rd0_ring() is called by vnt_start().
You should also implement error handling code in vnt_start(), and let
vnt_start() returns an error number too.
The same for device_init_rd1_ring(), device_init_td0_ring() and
device_init_td1_ring().
Best wishes,
Jia-Ju Bai
next prev parent reply other threads:[~2018-03-29 8:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20180329072248epcas2p3d12617d41e964252998dd1d34f740a97@epcas2p3.samsung.com>
2018-03-29 7:22 ` [PATCH v2] staging: vt6655: check for memory allocation failures Ji-Hun Kim
2018-03-29 8:00 ` Jia-Ju Bai [this message]
2018-03-29 10:53 ` ji-hun Kim
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=798fbe60-52aa-4fb0-0cd3-e2c067bd6c04@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=devel@driverdev.osuosl.org \
--cc=forest@alittletooquiet.net \
--cc=gregkh@linuxfoundation.org \
--cc=ji_hun.kim@samsung.com \
--cc=julia.lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=santhameena13@gmail.com \
--cc=y.k.oh@samsung.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