public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: QintaoShen <unSimple1993@163.com>
Cc: davem@davemloft.net, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, unSimple1993@163.com
Subject: Re: [PATCH v1] crypto: stm32: Check for NULL return of kmalloc_array()
Date: Fri, 25 Mar 2022 16:16:19 +1200	[thread overview]
Message-ID: <Yj1CE0IPS+JB9V8I@gondor.apana.org.au> (raw)
In-Reply-To: <1648114692-11175-1-git-send-email-unSimple1993@163.com>

QintaoShen <unSimple1993@163.com> wrote:
> As the potential failure of memory allocation, kmalloc_array() may return
> NULL and lead to NULL pointer dereference because of the usage of 'rctx->hw_context'.
> 
> Therefore, it is better to check the return value of kmalloc_array().
> 
> Signed-off-by: QintaoShen <unSimple1993@163.com>
> ---
> drivers/crypto/stm32/stm32-hash.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c
> index d33006d..f1a1a13 100644
> --- a/drivers/crypto/stm32/stm32-hash.c
> +++ b/drivers/crypto/stm32/stm32-hash.c
> @@ -970,7 +970,8 @@ static int stm32_hash_export(struct ahash_request *req, void *out)
>        rctx->hw_context = kmalloc_array(3 + HASH_CSR_REGISTER_NUMBER,
>                                         sizeof(u32),
>                                         GFP_KERNEL);
> -
> +       if (!rctx->hw_context)
> +               return -ENOMEM;

This patch introduces a runtime PM imbalance.  Please fix.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      reply	other threads:[~2022-03-25  4:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24  9:38 [PATCH v1] crypto: stm32: Check for NULL return of kmalloc_array() QintaoShen
2022-03-25  4:16 ` Herbert Xu [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=Yj1CE0IPS+JB9V8I@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=unSimple1993@163.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