From patchwork Sat Jul 22 14:53:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 124338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp891970vqg; Sat, 22 Jul 2023 09:44:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlFUsvBn8/AmKMM0kAKLuQALXwCzl4COWX/QkRHJKGbj/Frll5z430RETba0B4NtRO5wvGL3 X-Received: by 2002:a17:906:74cc:b0:98d:e7e3:5ab7 with SMTP id z12-20020a17090674cc00b0098de7e35ab7mr4665307ejl.11.1690044240366; Sat, 22 Jul 2023 09:44:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690044240; cv=none; d=google.com; s=arc-20160816; b=0B038v2nSjfdf5yeOF2+lH3fS0F2ac3QMaOT7LiGzwQCCumTUzkI0kN7o/V5UW7oZ0 jDxqQo67bLwqzS98KZlEFf+VGbWT2yPxSzl63akwOYRJbZzlpuk2so7udI5JFYOz8dGq Q1K7H3QJ/NXznsDYA5kERQ9nJqj8wAbPfoCfgvwzqL8zII0X0mTLXOfQ+//NhrBTmf5V 4q+0gfUYnClJcfCUpaFhKUFSOhzZLENX/kRmwTHsQOhSg1RIv1bMoxA6gj42HZddg8ni +Jtv8WOJVvLF40X9o0R9CLWzxAFzp0tVFba9ldAFKyQFbp1aCErUO1Ap+5hekUuOZiyT F0gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=lfDR0mINkrCKxcAnadMKPEe9Mciru7liyonpOcMXacU=; fh=ffcRNLm3e9Wa8tDEw9979HINKAwO8fkcTeJ4Ayummbs=; b=Tv22bsreuEpm2+lfrD1O09QFr1GMsu1Q2BM8U6Dsysqqg7+y74jTzYsdqS41faQpL0 JF+mPZPNE4+3sFYXH8OhtNVRPaAK9a0ktLh8ucoRF7UiUcWDnynSsuO5oOJphpaQxf6l CUUhXcy2peS7W3J/2XQ+TXXsuV2yt7o+gx8fRuYgVRd73ptguhP/2PNhpKSM0erx/2UH c7+bNYt1yaqu4Rf57Qb+/yuSyl2qv1+dUUvSXfSJiddr2H3Z1lYwEJiBV4cTlnZzOrx7 NjxtgFUbzzx9VJbGISMWMPrdT1vFCB9Y14M031QRTL4X7wzwrXgA8K6BPEgMb4gBpe01 Xg3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=DQxDYxtD; 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 l26-20020a170906a41a00b00992ee70a0afsi3904274ejz.12.2023.07.22.09.43.30; Sat, 22 Jul 2023 09:44:00 -0700 (PDT) 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; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=DQxDYxtD; 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 S229688AbjGVOyP (ORCPT + 99 others); Sat, 22 Jul 2023 10:54:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjGVOyO (ORCPT ); Sat, 22 Jul 2023 10:54:14 -0400 Received: from smtp.smtpout.orange.fr (smtp-15.smtpout.orange.fr [80.12.242.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C1831999 for ; Sat, 22 Jul 2023 07:54:11 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id NDziq9IyeeA2LNDziqDHuc; Sat, 22 Jul 2023 16:54:09 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1690037649; bh=lfDR0mINkrCKxcAnadMKPEe9Mciru7liyonpOcMXacU=; h=From:To:Cc:Subject:Date; b=DQxDYxtDbHTvG6MFjroIFnhP/3V6nQpawqQ2gCrQEhZGf80GXIq9vw1KxfQ8FK67f tGELfSAPJgUCUCNmkgqoiRpHwJD+0N2OdqhjK5zu3rPd9sU4hz1u9nYERSfYVmfOTe ftuMWx0FeVGyzWBCBxI72EAjl7S8nWH2RNBHO6DEJKv2VRg7mnaRPEULO9XumTKLCr g7nIGEt6o9YlmPtObdlvQ8ApLGMeUpOsnu0NYg21FVASxN5/T6JXiAFQGvQgO9onWW sPYZf0O9zDSVOtFJe+lo3BJGiUKwXgPkq+x1KRsuXZQ7RP5fHl57RZN5MsMpmrARLK iVMIU1IinDs6A== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 22 Jul 2023 16:54:09 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: =?utf-8?q?Horia_Geant=C4=83?= , Pankaj Gupta , Gaurav Jain , Herbert Xu , "David S. Miller" Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-crypto@vger.kernel.org Subject: [PATCH 1/2] crypto: caam - Use struct_size() Date: Sat, 22 Jul 2023 16:53:58 +0200 Message-Id: <0fc02b533bd3c3422bec5856bc65bbb66ebf7b58.1690037578.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772139829226764141 X-GMAIL-MSGID: 1772139829226764141 Use struct_size() instead of hand-writing it, when allocating a structure with a flex array. This is less verbose, more robust and more informative. Signed-off-by: Christophe JAILLET Reviewed-by: Gaurav Jain --- drivers/crypto/caam/caamhash.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 80deb003f0a5..9e5924e24f2e 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -708,9 +708,8 @@ static struct ahash_edesc *ahash_edesc_alloc(struct ahash_request *req, gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC; struct ahash_edesc *edesc; - unsigned int sg_size = sg_num * sizeof(struct sec4_sg_entry); - edesc = kzalloc(sizeof(*edesc) + sg_size, flags); + edesc = kzalloc(struct_size(edesc, sec4_sg, sg_num), flags); if (!edesc) { dev_err(ctx->jrdev, "could not allocate extended descriptor\n"); return NULL; From patchwork Sat Jul 22 14:53:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 124351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp917301vqg; Sat, 22 Jul 2023 10:47:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlE2nhQ/UHiz/TNcdvYFDRdGPtYmXszvTcncXWsqQKdj8LKdPeHmLbH2WWr9UZyIrCt7twVO X-Received: by 2002:a17:902:da87:b0:1b3:fb75:dd24 with SMTP id j7-20020a170902da8700b001b3fb75dd24mr5737049plx.48.1690048054732; Sat, 22 Jul 2023 10:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690048054; cv=none; d=google.com; s=arc-20160816; b=S2rx3+I6sKhyLqbqtjUogfEx6kltIB3awBE6cnmthxtsHiuMemeCmWfYiHen66GlrC dKGNT8PlOtD5gOHHfcsiSfg3Fl2G2ucgjyUv7i7aBMVVL+8zk4hsWVH0Z7JJC4oP1zM8 RaUJD+Ot0zEwtzgE3QlHIvSCa427Hf+Sr3YW0qM8D4pmYKQU8SpJ6XW9oXIGp5Yd2dKQ U8H7Te2SOAWBz7p0PUQC+M4NUz0D3A5L4m3SHYwPxqedZqsTRijRWB+VScpECyK4egZx nRzRSrsg3YdtGGStK878AovHwh0maw6ApucPCHuVFiFT0+IOryJV6WEe1gMUG6uahcZl wNpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2EYI+Z2hVmisU1YN5vrLq4/s1ceNP0kl8rsGq7obraQ=; fh=ffcRNLm3e9Wa8tDEw9979HINKAwO8fkcTeJ4Ayummbs=; b=hOPC4UqEXNM1l0K/7rA6zopoLP7PMMEF0vIs4S1hlCUKILX6sb1pQ8irdonkuOsNs7 dM3/rjE5YryWmqy+uYO2UmFifi5XBhjg7FIQQRT446+PSF7cN5eoHzdlWqGgGF2fzesl THAOeviGL8bhDQibXHeAXHuhv5AXqi5P8X3LPJSVz1NvT+gV/Fp/oLRKW6kAtZBkC80E 9i3DsO6P6bIEynXTJnr4tAjU4+C1/tuvg0FkgZsU7shA/wjgGtpu6lP94iztzu6kjiPf jCFeEaAn9ZqQOcl82Nzte0w3r/yvqTHNQ8P6mY27kSl+fhYjxq+v3i/iDjs0/Ajbtsmu DSBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=skGlKg56; 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 lg5-20020a170902fb8500b001b9cca29be1si5098119plb.370.2023.07.22.10.47.21; Sat, 22 Jul 2023 10:47:34 -0700 (PDT) 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; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=skGlKg56; 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 S229866AbjGVOyT (ORCPT + 99 others); Sat, 22 Jul 2023 10:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjGVOyR (ORCPT ); Sat, 22 Jul 2023 10:54:17 -0400 Received: from smtp.smtpout.orange.fr (smtp-15.smtpout.orange.fr [80.12.242.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93B051FCB for ; Sat, 22 Jul 2023 07:54:16 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id NDziq9IyeeA2LNDzqqDHuw; Sat, 22 Jul 2023 16:54:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1690037655; bh=2EYI+Z2hVmisU1YN5vrLq4/s1ceNP0kl8rsGq7obraQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=skGlKg56k8xYk51FfhL+hiU3BM3fmBiRZBr7bNAl/VyQW+DF7g3PK6bJVJnHmP4hy T2v0H5X0K0mhNSijn+vO76Jrx0vEi7vJZ4j8me239gtzXLkRPqKlDjgsOyVtaAu7Jh 3bFucBrc7tpBru+NiFEkQINki5LMTzdYFsieVg4OudHPl6cyvR0FvfBIRUNEFzpz1i XT19us1XmcGenwWJrUqaCxJebdjDRGxG+zljEzk1Y1gr7WOevYQBM06lvRtlu69tEF 7QdRGxznks0JjiYpqZdRieQJiCGQP2yZPw1Ch49gDKPPtx5Lv4skRb71vy1jdLwyrX XQAMqWtkKaK/A== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 22 Jul 2023 16:54:15 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: =?utf-8?q?Horia_Geant=C4=83?= , Pankaj Gupta , Gaurav Jain , Herbert Xu , "David S. Miller" Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-crypto@vger.kernel.org Subject: [PATCH 2/2] crypto: caam - Remove messages related to memory allocation failure Date: Sat, 22 Jul 2023 16:53:59 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: <0fc02b533bd3c3422bec5856bc65bbb66ebf7b58.1690037578.git.christophe.jaillet@wanadoo.fr> References: <0fc02b533bd3c3422bec5856bc65bbb66ebf7b58.1690037578.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: INBOX X-GMAIL-THRID: 1772143828959177866 X-GMAIL-MSGID: 1772143828959177866 On memory allocation failure, the function calling stack is already logged. So there is no need to explicitly log an extra message. Remove them, ans simplify some code accordingly. Signed-off-by: Christophe JAILLET Reviewed-by: Gaurav Jain --- drivers/crypto/caam/caamhash.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index 9e5924e24f2e..641c3afd59ca 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -368,10 +368,8 @@ static int hash_digest_key(struct caam_hash_ctx *ctx, u32 *keylen, u8 *key, int ret; desc = kmalloc(CAAM_CMD_SZ * 8 + CAAM_PTR_SZ * 2, GFP_KERNEL); - if (!desc) { - dev_err(jrdev, "unable to allocate key input memory\n"); + if (!desc) return -ENOMEM; - } init_job_desc(desc, 0); @@ -702,18 +700,14 @@ static struct ahash_edesc *ahash_edesc_alloc(struct ahash_request *req, int sg_num, u32 *sh_desc, dma_addr_t sh_desc_dma) { - struct crypto_ahash *ahash = crypto_ahash_reqtfm(req); - struct caam_hash_ctx *ctx = crypto_ahash_ctx_dma(ahash); struct caam_hash_state *state = ahash_request_ctx_dma(req); gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC; struct ahash_edesc *edesc; edesc = kzalloc(struct_size(edesc, sec4_sg, sg_num), flags); - if (!edesc) { - dev_err(ctx->jrdev, "could not allocate extended descriptor\n"); + if (!edesc) return NULL; - } state->edesc = edesc; @@ -1908,10 +1902,8 @@ caam_hash_alloc(struct caam_hash_template *template, struct crypto_alg *alg; t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL); - if (!t_alg) { - pr_err("failed to allocate t_alg\n"); + if (!t_alg) return ERR_PTR(-ENOMEM); - } t_alg->ahash_alg = template->template_ahash; halg = &t_alg->ahash_alg;