public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: walter harms <wharms@bfs.de>
To: Colin King <colin.king@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Wei-Ning Huang <wnhuang@google.com>,
	Thierry Escande <thierry.escande@collabora.com>,
	Wei Yongjun <weiyongjun1@huawei.com>,
	kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] firmware: Google VPD: fix error handling on allocation failures
Date: Wed, 03 May 2017 17:58:25 +0200	[thread overview]
Message-ID: <5909FE21.7050607@bfs.de> (raw)
In-Reply-To: <20170503154924.1659-1-colin.king@canonical.com>



Am 03.05.2017 17:49, schrieb Colin King:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Fix two allocation failure checks. Firstly, ensure info is checked
> for a failed allocation; this fixes a potential null pointer
> dereference issue on info->key.  Secondly, free info is info->key
> fails to allocate to fix a memory leak.
> 
> Detected by CoverityScan, CID#1430064 ("Resource Leak")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/firmware/google/vpd.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c
> index 3ce813110d5e..2eb15b1dabcc 100644
> --- a/drivers/firmware/google/vpd.c
> +++ b/drivers/firmware/google/vpd.c
> @@ -116,9 +116,13 @@ static int vpd_section_attrib_add(const u8 *key, s32 key_len,
>  		return VPD_OK;
>  
>  	info = kzalloc(sizeof(*info), GFP_KERNEL);
> +	if (!info)
> +		return -ENOMEM;
>  	info->key = kzalloc(key_len + 1, GFP_KERNEL);
> -	if (!info->key)
> +	if (!info->key) {
> +		kfree(info);
>  		return -ENOMEM;
> +	}
>  
>  	memcpy(info->key, key, key_len);
>  


the use of key_len+1 looks like preparing space for a string.
so kstrdup() seems more fitting. If this is not a string
there is also a kmemdup().


re,
 wh

      reply	other threads:[~2017-05-03 15:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03 15:49 [PATCH] firmware: Google VPD: fix error handling on allocation failures Colin King
2017-05-03 15:58 ` walter harms [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=5909FE21.7050607@bfs.de \
    --to=wharms@bfs.de \
    --cc=colin.king@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thierry.escande@collabora.com \
    --cc=weiyongjun1@huawei.com \
    --cc=wnhuang@google.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