Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1172361ybl; Wed, 29 Jan 2020 16:51:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzIiHW6I9sFpdVv+X4JJUO4gZR8Emw6cji6T8hztoU/eu5nR88HGH433pBu/D+ci7zfoNun X-Received: by 2002:a9d:6758:: with SMTP id w24mr1652343otm.155.1580345507087; Wed, 29 Jan 2020 16:51:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580345507; cv=none; d=google.com; s=arc-20160816; b=aRfyxqdlK+AfAyRQtCrtEf2Q1PYQ45XK1vlNdfgvDPG12S4cDiWmdLPZzhiB4tjjYE ZqSyJCULZgwcdLhK6Z7yKi07hHn7MxzAAvJ6CgyDRTi4d5z28oZsg7wqmorymfYNKYoo AIUicdXm+SqeWE9ag6pZx6KYRPwfvrquP5H/dYJ8ZwyE0wv8DvqWwpUzMDmeavoABazd Yln448scscL28H/9rXSJJpx2+ADFpZLhm3xa/NtO+zyebJh31KwRi+4+rTPLKBzZIJqr nTLR+JRQ/TdvvSeyvXJt0KKqqaJoeNJoKz44lvzeVW+H+dUOoqvgCSkIycW3qVwzebC7 sF2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=hF8LbrLUAI4yUrtKbQLHBfSy0+Z7LnoP7BM5ynrVuNk=; b=hF5hFU2mEZFCorBVHo8n2AkIqtjiEUZNRHdDjcEyalgPrjM7iYhCe2mj0zQGSaWbMV kZybyhfgkWQKpM2IQzsFIpz5gSYWSU13Q63bwItzGcjVFQCt1673VQt/Tdl8DvK3TsYm lKuN0RiafrUGh0osWesoErARfIuW5UhMECRTeIvQvjjx/VE8CEhqFI5Qqtx9azGueyhA fZ/DACFd6wvGTqxahNsTAQDXgvBCGAf8wZVq+KrkPBtxbyNbyIkJzpPNpGKf1QMvEzaP 7eV4oI4uzO9Rzl9niwqVY1mudnkvp60prxPT03L+VtMb9woNRKSwcLJg+wuNrbmApO6O q8rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p71si2022486oic.138.2020.01.29.16.51.36; Wed, 29 Jan 2020 16:51:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727319AbgA3Ats (ORCPT + 99 others); Wed, 29 Jan 2020 19:49:48 -0500 Received: from inva020.nxp.com ([92.121.34.13]:42250 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbgA3Atr (ORCPT ); Wed, 29 Jan 2020 19:49:47 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 412581A0A46; Thu, 30 Jan 2020 01:49:45 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 318CF1A4E40; Thu, 30 Jan 2020 01:49:45 +0100 (CET) Received: from lorenz.ea.freescale.net (lorenz.ea.freescale.net [10.171.71.5]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id BEDEC203BF; Thu, 30 Jan 2020 01:49:44 +0100 (CET) From: Iuliana Prodan To: Herbert Xu , Horia Geanta , Aymen Sghaier Cc: "David S. Miller" , Silvano Di Ninno , Franck Lenormand , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx , Iuliana Prodan Subject: [PATCH v5 4/9] crypto: caam - refactor RSA private key _done callbacks Date: Thu, 30 Jan 2020 02:49:19 +0200 Message-Id: <1580345364-7606-5-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1580345364-7606-1-git-send-email-iuliana.prodan@nxp.com> References: <1580345364-7606-1-git-send-email-iuliana.prodan@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Create a common rsa_priv_f_done function, which based on private key form calls the specific unmap function. Signed-off-by: Iuliana Prodan Reviewed-by: Horia Geanta --- drivers/crypto/caam/caampkc.c | 61 +++++++++++++------------------------------ 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index 6619c51..ebf1677 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -132,29 +132,13 @@ static void rsa_pub_done(struct device *dev, u32 *desc, u32 err, void *context) akcipher_request_complete(req, ecode); } -static void rsa_priv_f1_done(struct device *dev, u32 *desc, u32 err, - void *context) -{ - struct akcipher_request *req = context; - struct rsa_edesc *edesc; - int ecode = 0; - - if (err) - ecode = caam_jr_strstatus(dev, err); - - edesc = container_of(desc, struct rsa_edesc, hw_desc[0]); - - rsa_priv_f1_unmap(dev, edesc, req); - rsa_io_unmap(dev, edesc, req); - kfree(edesc); - - akcipher_request_complete(req, ecode); -} - -static void rsa_priv_f2_done(struct device *dev, u32 *desc, u32 err, - void *context) +static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err, + void *context) { struct akcipher_request *req = context; + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); + struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); + struct caam_rsa_key *key = &ctx->key; struct rsa_edesc *edesc; int ecode = 0; @@ -163,26 +147,17 @@ static void rsa_priv_f2_done(struct device *dev, u32 *desc, u32 err, edesc = container_of(desc, struct rsa_edesc, hw_desc[0]); - rsa_priv_f2_unmap(dev, edesc, req); - rsa_io_unmap(dev, edesc, req); - kfree(edesc); - - akcipher_request_complete(req, ecode); -} - -static void rsa_priv_f3_done(struct device *dev, u32 *desc, u32 err, - void *context) -{ - struct akcipher_request *req = context; - struct rsa_edesc *edesc; - int ecode = 0; - - if (err) - ecode = caam_jr_strstatus(dev, err); - - edesc = container_of(desc, struct rsa_edesc, hw_desc[0]); + switch (key->priv_form) { + case FORM1: + rsa_priv_f1_unmap(dev, edesc, req); + break; + case FORM2: + rsa_priv_f2_unmap(dev, edesc, req); + break; + case FORM3: + rsa_priv_f3_unmap(dev, edesc, req); + } - rsa_priv_f3_unmap(dev, edesc, req); rsa_io_unmap(dev, edesc, req); kfree(edesc); @@ -691,7 +666,7 @@ static int caam_rsa_dec_priv_f1(struct akcipher_request *req) /* Initialize Job Descriptor */ init_rsa_priv_f1_desc(edesc->hw_desc, &edesc->pdb.priv_f1); - ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f1_done, req); + ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f_done, req); if (!ret) return -EINPROGRESS; @@ -724,7 +699,7 @@ static int caam_rsa_dec_priv_f2(struct akcipher_request *req) /* Initialize Job Descriptor */ init_rsa_priv_f2_desc(edesc->hw_desc, &edesc->pdb.priv_f2); - ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f2_done, req); + ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f_done, req); if (!ret) return -EINPROGRESS; @@ -757,7 +732,7 @@ static int caam_rsa_dec_priv_f3(struct akcipher_request *req) /* Initialize Job Descriptor */ init_rsa_priv_f3_desc(edesc->hw_desc, &edesc->pdb.priv_f3); - ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f3_done, req); + ret = caam_jr_enqueue(jrdev, edesc->hw_desc, rsa_priv_f_done, req); if (!ret) return -EINPROGRESS; -- 2.1.0