Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1677601pxb; Fri, 25 Mar 2022 03:33:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWF3fE8GSp26uhK9x1qxUb8s9HeDuiSps3tZDV57i30AkO8o4ts6+gqp2KQAHpHj8O8LP5 X-Received: by 2002:a17:902:a98b:b0:14f:ae28:c660 with SMTP id bh11-20020a170902a98b00b0014fae28c660mr11052435plb.94.1648204415131; Fri, 25 Mar 2022 03:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648204415; cv=none; d=google.com; s=arc-20160816; b=n8PChiL9fPDmeNErMZ8k9vhpG44Mo9egUCwx+g3RM5f1+SulWIwICZVuzKMTWyb/MI swLJaK9WVS4XqKzJz9ad9aNTwFixDCHVUWgGPvqIEuqzSqfNN/uz6ZXsnj5mSmMS0Jh4 73oKgAOgGvMLNpzzQ1oBx5BLr8Wm119ggRR4yXrxdjNwdTiqWwilP2OtXYcT9PZ69kGw cG4rB5y3mWfcduNFeHQZ8syybV/GpxaBodmc8u7bQDodqu1EYA4H9pMhVOSsxVaEtWgB 4Kwfe2x7YHATTnisdDnL1/eeOQK/7iSqy+mXVa9zJWUeQB+SwlHbLraTil3wN9yFsX6E TR7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date; bh=9fW5ic6RI8Duu6/w2kgAgSwUZNpdgvTaLABU1nrbQK4=; b=suuAAYYLG6Glx6GrV0Ct06WokZrNWoT8toCEvxEcdls50M7XG2X6ES4ySIrsA3bm02 qB38kwfBoTDnrhAp9eRzeflS88ArZL/6mb1EOfVs1gYG6y9/TE/vAbx9GRjk26fdgc3A oICaat0PVetS6ivIHOTiEVTnuXbZlmNNdkNGFqb3VbCwJnJ02d0L0GhYxerXuyD3inRW hstITg5Ty+7PWH7l0HbJXsssodNx5Cxs+GYJbkBc2vPtJX27vg79YIWqJ6bkhcYREtLd ULRBOHJFSf+IMQXtYeTG6Va4sihi2I2Hti9V+cF09jrPVKKrfEfAigVmyWs3pNaISjuE q75g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a630b13000000b003861b276bf4si1978121pgl.181.2022.03.25.03.33.10; Fri, 25 Mar 2022 03:33:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348572AbiCYESA (ORCPT + 99 others); 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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