From patchwork Fri Feb 24 21:50:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li kunyu X-Patchwork-Id: 60795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp140944wrd; Wed, 22 Feb 2023 21:35:14 -0800 (PST) X-Google-Smtp-Source: AK7set9vBXSaNTY/kiEEtbKhB2CvEO9+lkkaEchKk5Xok1GI6tbGdgwpV/x97nOqPVZJu3a+Uw9y X-Received: by 2002:a17:906:150:b0:894:4341:77d6 with SMTP id 16-20020a170906015000b00894434177d6mr17563869ejh.1.1677130513977; Wed, 22 Feb 2023 21:35:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677130513; cv=none; d=google.com; s=arc-20160816; b=EhmOzmeL2lj2SGi2XBGyxeD4uj+9JnZ7x3b/HI/NeBEDnvjWisYwimsu1fmOxmF7ns wiTyRhgBy/uzbTBdd01hdTYC8M9AK8CoHYTrzbUw1gWe3PO95fXKmDuUuGJ8wOM1OUFY ORRfAwC/84g0yWaZxiP/+Tg7znE79qVexIZe+Wp74nu8ur0FCyGoTiFrI0M5zMKUXSqQ TOm4lldmwxmGmoRwNpHv4WIbIylS400y6ZhCVw+7oJEa2j42vjZEbMnQbJMWjXGLcOoo Nu73wtOOFfgt60Oxwu9ti8hL6cuFp0Ltr2RRCSMrseXSKMEvSQMoK9CW8ze9l5gp/qI4 Ub8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=3W+bZC1rcB1CIWF1GZC6W0oxeVkeaDhE95dqzNFokmI=; b=Mxl1+NTdQmpEAJE/r02BBiIMm9LX5LnDyUufvVHYVBcBC7YiGy2tbaoOLcK+Pmpcyl bli2N4pbtTWFYSKXhvHgxMB+Vf2KdNxmJzPDRwa81fdbRxUPr86BPJCgp6ryyn4jWupj cwNvhyjCL4Fq0QRTbJj4sKguwvr/bt1aqmDamu/JvRB/H1USrSGRjpNB5bvBUCZ0pdq8 mNBeZ+BKRScu31Gf9nRKgPZIh10ZB9mQIgs5Q6LjpiyKO+DxQ1piEJApIPowgTAixiBw nztwVxYLuK8x2YiDsBVi6LSR7YNrNnbBOGNXjdlfziEqiLCmJQOWcn25bbJuHTfENB5j I8GQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mt23-20020a170907619700b008b178b41ec1si19617470ejc.284.2023.02.22.21.34.49; Wed, 22 Feb 2023 21:35:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233247AbjBWFT2 (ORCPT + 99 others); Thu, 23 Feb 2023 00:19:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233234AbjBWFTS (ORCPT ); Thu, 23 Feb 2023 00:19:18 -0500 Received: from mail.nfschina.com (unknown [42.101.60.237]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FBDA47432; Wed, 22 Feb 2023 21:19:05 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 5896C1A00A14; Thu, 23 Feb 2023 13:19:44 +0800 (CST) X-Virus-Scanned: amavisd-new at nfschina.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (localhost.localdomain [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yXrtiH0GntNQ; Thu, 23 Feb 2023 13:19:40 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: kunyu@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 10B9E1A0092F; Thu, 23 Feb 2023 13:19:40 +0800 (CST) From: Li kunyu To: herbert@gondor.apana.org.au, davem@davemloft.net, mcoquelin.stm32@gmail.com Cc: linux-crypto@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Li kunyu Subject: [PATCH] stm32: stm32-hash: Add kmalloc_array allocation check Date: Sat, 25 Feb 2023 05:50:19 +0800 Message-Id: <20230224215019.3687-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=0.9 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_24_48, RDNS_NONE,SPF_HELO_NONE,SPF_NONE autolearn=no 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758598806285808630?= X-GMAIL-MSGID: =?utf-8?q?1758598806285808630?= If rctx->hw_context allocation of the context pointer failed. Returning -ENOMEM and assigning NULL to the out pointer should improve the robustness of the function. Signed-off-by: Li kunyu --- drivers/crypto/stm32/stm32-hash.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c index d33006d43f76..18e79f62be96 100644 --- a/drivers/crypto/stm32/stm32-hash.c +++ b/drivers/crypto/stm32/stm32-hash.c @@ -970,6 +970,10 @@ 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 == NULL) { + out = NULL; + return -ENOMEM; + } preg = rctx->hw_context;