Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2122149ybc; Sun, 17 Nov 2019 14:33:53 -0800 (PST) X-Google-Smtp-Source: APXvYqwyi+zRs2MUrK6VW9JbajLBfc0QNTcBQTcImpP1lIoMdhmWapNZTVpUzCR1E7Pkmy+r8ZUB X-Received: by 2002:a17:906:e297:: with SMTP id gg23mr22151597ejb.41.1574030033219; Sun, 17 Nov 2019 14:33:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574030033; cv=none; d=google.com; s=arc-20160816; b=e4JP+KztZCmq5Yz7x3nRmESLVQpRFGSyS9N9k8YsT1Ux04JiK6cF+fqbT2G2TWK8Vj UVSt3kjhCFkgnAi7MgR/6S0vSGXJLvTy2NTK1S+unnzZl/wTS7dem60BdD5D3nSQc88j +Kj63zicLacDY0KBQ5FlHzdvmhcLLvBO0dhucaP4hcVb4gAnFGe2L4uu4coMaNaeKgl6 29X4r+UMPcY/ZUWSKoL2yNQIk2SS+kiJNB0sOd3u+UK7DMe4uNqZY/ijKWWHm3zHF8JB q71a7m/jKM6RZTviUtBymCMGQuUerg57SvEcMCzB7HRxdhHcVMN4Yoy/t9fh/LXxqbvx 4CeQ== 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=e/3d61QWmpOKcsnt7SbBRTXS6Eba5mWu/PSWrvVJz8I=; b=PWHSJkVCyltmIghdUE33kC6edsx/npw4n/EgHRH8WImzO0DhBsyEGg0mKkjimIlhlH EBg4yjNo8kyJjCDYB9dH1a/K3AgsbdoWbh7nWgr9k15oXRzvchj4ejBqhTNgmLNkdV39 qvuFXjKROD4ePQCGB1jApgHKuxDjWaJOKvMy9EDUgbe0Cy6dSog3u7yhU555vN6qcrhG mUxi4IlTYXpwf+VqnZd/bF7/GW4g3wRp8cj4d1/3ilQjLr1NbLInMIQYiYP+fRphyY6w bS9GsQQzTlVpVKCQNQX8t36KHQv5K+0Ggc7CZRAJfmVJlMcFUzrzdkHloaTEFy8YC/+s Mg1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 ce20si10195148ejb.183.2019.11.17.14.33.28; Sun, 17 Nov 2019 14:33:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1727000AbfKQWbn (ORCPT + 99 others); Sun, 17 Nov 2019 17:31:43 -0500 Received: from inva021.nxp.com ([92.121.34.21]:44654 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726171AbfKQWbH (ORCPT ); Sun, 17 Nov 2019 17:31:07 -0500 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id A70EB200310; Sun, 17 Nov 2019 23:31:04 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 997C32000AA; Sun, 17 Nov 2019 23:31:04 +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 33CBC20395; Sun, 17 Nov 2019 23:31:04 +0100 (CET) From: Iuliana Prodan To: Herbert Xu , Horia Geanta , Aymen Sghaier Cc: "David S. Miller" , Tom Lendacky , Gary Hook , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx , Iuliana Prodan Subject: [PATCH 05/12] crypto: caam - refactor RSA private key _done callbacks Date: Mon, 18 Nov 2019 00:30:38 +0200 Message-Id: <1574029845-22796-6-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1574029845-22796-1-git-send-email-iuliana.prodan@nxp.com> References: <1574029845-22796-1-git-send-email-iuliana.prodan@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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