Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2512370ybl; Mon, 20 Jan 2020 04:25:23 -0800 (PST) X-Google-Smtp-Source: APXvYqy8gnPaySMYNSKttSicvnxOMQnUo6M6ecvLVoW4SdYfLel6d6EaqIQYs5FtuIKwcKnvfe7A X-Received: by 2002:aca:c494:: with SMTP id u142mr12879903oif.86.1579523123303; Mon, 20 Jan 2020 04:25:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579523123; cv=none; d=google.com; s=arc-20160816; b=hzA6HM4wruNeF7rwWlRQ+mqINHXkuV0BFWv0wc6OzPuSqmK1MMX+z9fJda3f9bH8O5 zLBpVJQqyXMaXfEmi7CXcVEAWSvZFGzTlyQ/aLORHV1uabOeDvpC2R194p/GNy6XA4Ph JabE6lkAfjHbAaL5R9prbYejPHpD+rZNm+we1wUHXIaQ2QVvvbWE4e+U3qMW9yLBrQFu 4l8ljIljQW3VOc9+HFdTcWR2cXjObUzh0/Izo8G4T0q8bVzsG9z4B0B5QLptEq5S0cC1 Ki69doSc9UIG1Mmw9lgmr5vABaGD8XEhOVnQSJWHXcyCcHnrWSfTBRKvErGGHL1bbS5c u/gA== 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=pnVg+18EP6vMX1JgfSLoEdoMqdCXj/KfWZNGCr36MFnHSEEtU+NB9Th7bPAa008bev yQgHcHVMCtj1cnB0yMfpJOrp+pZukUiVFhzpnosXsTSl4W/korUqDhCyyExqnb1TdxXU ThDmc1E7y0c0hT1LU14tiEx8w5iQKGrbof/k1wByVhbBi/gE4rdVHmMiSaSSfNkbpoeb Vj4d3MyeH+0vTNvmuUd/kxsvipn5n06nWGM8XVSIfxjWsLrSbr9sdfjD2nfW+WGA08CV bmHqasfJIGUuU3C74pmueDHBNoHu7zpc4Dv1a3ZIvJru008G4cDZsFGMMkxW9E+Xv+G+ GatA== 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 t184si17363590oig.184.2020.01.20.04.25.11; Mon, 20 Jan 2020 04:25:23 -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 S1727990AbgATMYU (ORCPT + 99 others); Mon, 20 Jan 2020 07:24:20 -0500 Received: from inva020.nxp.com ([92.121.34.13]:40298 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbgATMYS (ORCPT ); Mon, 20 Jan 2020 07:24:18 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id E88E61A0C0C; Mon, 20 Jan 2020 13:24:15 +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 DBD0F1A0214; Mon, 20 Jan 2020 13:24:15 +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 656EC20414; Mon, 20 Jan 2020 13:24:15 +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 v4 4/9] crypto: caam - refactor RSA private key _done callbacks Date: Mon, 20 Jan 2020 14:24:03 +0200 Message-Id: <1579523048-21078-5-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1579523048-21078-1-git-send-email-iuliana.prodan@nxp.com> References: <1579523048-21078-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 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