Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18029133ybl; Thu, 2 Jan 2020 17:05:50 -0800 (PST) X-Google-Smtp-Source: APXvYqz1wcuV2ofsF8VojQQqnNT12aqupPBr4Pb9qnhPWoyGRtYfjy0Z6eqe9i8jVn60ntNqiG81 X-Received: by 2002:a05:6808:4c7:: with SMTP id a7mr3404738oie.83.1578013550160; Thu, 02 Jan 2020 17:05:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578013550; cv=none; d=google.com; s=arc-20160816; b=D2DJyesKKfGmC+JKtvmwsQXamwYDx2BYOJ7ofd3pvpoeq0cOl2JBeDAXPTefQjXIcp Os9Q4cOM3XAwjhxAxtpDt3FrCpx8DjcpVtRtYmj6jm0mBKjmzsxY3AJrK5XLz07xwi5N UmZPq/qNjE/1Sh7vbGO1CDNWXs6k3FvaWKzNHtZONgagXeyx1km6FNa5oHdB7x5W9XW6 7Mwrj0BKhLQEVCcHgstaRIqtEbMSG9FVuqsbzaBggXQA37db48954C4A3v32kheTM6Ee ICFqVaqvIwl88Mu0a9asawiRe9eA4FzJNTDftqHhYv06YayR5Vutg0orWNgF5sDvCbf2 z0Qw== 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=sEHXTDwZiegyiaGIfmRVlS9bpKUN4lWnWMNMBLI+g/g6DLr5LsjpNOGOeniPw0LhgO fwXnK4M3oLj6v5T5zTI6dlzZ/mxuWIpD1x3qvHdj6xvNcB1KWfXrxkwwuY1TvkBsEnYD k3Xz1BHUK1bW03Gl24EKuEDWFr26rrnKZpNPJiqUcXIROqYbtl4Qp+NjPQVIM2De4qNI etqbYru83J5yR5DFYC27057pMs4VLQKymhHlRonH5vUVYUAzwJv8wTFjhuHObVV7zz19 UXWNv/A8Pbr92fgxUnHmb/Ipj51YbRA/BDHhTIooimDTrFUTbPoWATUpKggg3JxUGnwV eyVA== 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 88si27167482otr.81.2020.01.02.17.05.38; Thu, 02 Jan 2020 17:05:50 -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 S1726299AbgACBDQ (ORCPT + 99 others); Thu, 2 Jan 2020 20:03:16 -0500 Received: from inva021.nxp.com ([92.121.34.21]:48388 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbgACBDP (ORCPT ); Thu, 2 Jan 2020 20:03:15 -0500 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 0BE48200930; Fri, 3 Jan 2020 02:03:14 +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 E9273200812; Fri, 3 Jan 2020 02:03:13 +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 9033C20567; Fri, 3 Jan 2020 02:03:13 +0100 (CET) From: Iuliana Prodan To: Herbert Xu , Horia Geanta , Aymen Sghaier Cc: "David S. Miller" , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx , Iuliana Prodan Subject: [PATCH v2 04/10] crypto: caam - refactor RSA private key _done callbacks Date: Fri, 3 Jan 2020 03:02:47 +0200 Message-Id: <1578013373-1956-5-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1578013373-1956-1-git-send-email-iuliana.prodan@nxp.com> References: <1578013373-1956-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