From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 602D4C433EF for ; Fri, 25 Mar 2022 04:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348572AbiCYESA (ORCPT ); Fri, 25 Mar 2022 00:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348284AbiCYER7 (ORCPT ); Fri, 25 Mar 2022 00:17:59 -0400 Received: from fornost.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68CBCC6255; Thu, 24 Mar 2022 21:16:25 -0700 (PDT) Received: from gwarestrin.arnor.me.apana.org.au ([192.168.103.7]) by fornost.hmeau.com with smtp (Exim 4.92 #5 (Debian)) id 1nXbN6-0003Na-0k; Fri, 25 Mar 2022 15:16:21 +1100 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Fri, 25 Mar 2022 16:16:20 +1200 Date: Fri, 25 Mar 2022 16:16:19 +1200 From: Herbert Xu To: QintaoShen 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() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1648114692-11175-1-git-send-email-unSimple1993@163.com> X-Newsgroups: apana.lists.os.linux.cryptoapi,apana.lists.os.linux.kernel Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org QintaoShen 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 > --- > 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 Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt