Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp268101iog; Wed, 29 Jun 2022 23:55:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uSE6Ym7gBeoXSRd7FCanleJULdZAQtuTIjFCRK39vBT9VbjHFsDz4QC0ZprAhXNy6MnMSy X-Received: by 2002:a17:907:2d2b:b0:726:a628:d1ae with SMTP id gs43-20020a1709072d2b00b00726a628d1aemr7164403ejc.336.1656572153157; Wed, 29 Jun 2022 23:55:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656572153; cv=none; d=google.com; s=arc-20160816; b=HeCJ2/sVJPHfFClqVkuVkDG8JH5b3k4DdAV49hXugQj/TTiv78b2Ffz7DxHbS2jJ47 DuYl4/JrgOR0fPtqPkZP4rEU7gkqcGwBn/qSaSTSzNnVVzLReUfiT40uj2GzQ4HBPn5/ IkU6z+zdD06PD+GbQq7efpaqvmjWh3KXncdofhMotKQhujBZ+URrbig618HhnkFwf9za EMEGnhV4a8d9RuTtT9XhwCzRQsLdG/IrOsktJepQoD7kd29JvhnaXTlGNhs6+TYnQTFE EnR0j7ycJUQGDIVV4Xwuoto5vBkhZQTLsfiCdly1xwf9STa6MD+xr+OHFX1uAmyDftri yhxw== 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 :references:message-id:subject:cc:to:from:date; bh=vqNPamdm4uZQX6C5p9Hfwnfrhq+29mpit9kc0NScZVY=; b=xx42eofCmvbIc71gdbsWNqqtISjgNcv+/CnkZ4xO5OVtNEU3r+02njYaQcW10z2x0G 87ZPUBy4rJ0XgHaKfYTc4SxisT0AtqizXOY3kikKO3yDwVSlCWai3W8Bl2kEnhmKKZu6 BSM9iwNuE8uPugvIEfXB0LtMY99SBN4cioBJ7sYA/53tln4c9X9TA23M25Yg9DwdlNJk Snc6EniwrWgpwhrrm4VbTPAYQuO3sV7Z3Bg3vQKHfUB+jC64NdqrI1ljfw3/eRFsh1sz cFLNKhYvwLn0uKWSfDIrn9xORs6jx6ZW6UYz5PaFyOJnIP9kmDGm50z/nvHtpf/dtrHc wI0g== 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 hr5-20020a1709073f8500b00726c7fc61dfsi12122714ejc.103.2022.06.29.23.55.25; Wed, 29 Jun 2022 23:55:52 -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 S229575AbiF3Gsj (ORCPT + 99 others); Thu, 30 Jun 2022 02:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232838AbiF3Gsj (ORCPT ); Thu, 30 Jun 2022 02:48:39 -0400 Received: from fornost.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F1131A069; Wed, 29 Jun 2022 23:48:36 -0700 (PDT) Received: from gwarestrin.arnor.me.apana.org.au ([192.168.103.7]) by fornost.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1o6nyJ-00CwRv-5u; Thu, 30 Jun 2022 16:48:16 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Thu, 30 Jun 2022 14:48:15 +0800 Date: Thu, 30 Jun 2022 14:48:15 +0800 From: Herbert Xu To: Li Qiong Cc: "David S . Miller" , Maxime Coquelin , Alexandre Torgue , "Rafael J . Wysocki" , linux-crypto@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, yuzhe@nfschina.com, renyu@nfschina.com Subject: Re: [PATCH] crypto: stm32 - Handle failure of kmalloc_array() Message-ID: References: <20220622020208.25776-1-liqiong@nfschina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220622020208.25776-1-liqiong@nfschina.com> 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 On Wed, Jun 22, 2022 at 10:02:08AM +0800, Li Qiong wrote: > As the possible failure of the kmalloc_array(), therefore it > should be better to check it and return '-ENOMEM' on error. > > Signed-off-by: Li Qiong > --- > drivers/crypto/stm32/stm32-hash.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/crypto/stm32/stm32-hash.c b/drivers/crypto/stm32/stm32-hash.c > index d33006d43f76..fc03e32e364f 100644 > --- a/drivers/crypto/stm32/stm32-hash.c > +++ b/drivers/crypto/stm32/stm32-hash.c > @@ -970,6 +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; Actually the problem is bigger than that. The driver should not be allocating memory in the export function at all. This memory will be leaked as exported requests won't be finalized. We need to fix this driver to do export properly, or if that's not possible, we should delete this driver. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt