Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6318759ybv; Wed, 12 Feb 2020 09:56:27 -0800 (PST) X-Google-Smtp-Source: APXvYqz9HLA2b5Mp3ktPzS852T0Ioz5fZ1EIxp4DIBQjMiBehBF1VACRw+xkDjmpefH0yWtwZpq3 X-Received: by 2002:a9d:4c81:: with SMTP id m1mr10221000otf.5.1581530187115; Wed, 12 Feb 2020 09:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581530187; cv=none; d=google.com; s=arc-20160816; b=BL1d/6pWwAKstU/o+aM+MC/y05To1Fr11MVX4PM4WUJXmEf/vLEtIN3t4dyso+NoeV DReKIunJ2+2U8E5Tab2zWtZThTmWF/XN2BzwhTumF07VH6rhMVN0ynV9c8tU6x7tvxul y3d0W/JXRolwM30c/VxjLQttSsvAGUs4SjV8ujq3cYIqCDYOX/XSfBaJE9lVHXJQH443 NzcgZjNszigmlybnrqEHPhV89b0e1DDd0M3vfqMZZV8nwVn/HzFnciborMpCP9Cp0Caw wAp+BdhvraWsnFwUdgbt0spT7vMrgKXtxl4KgFM6a7sZfwxyILH4mFYwvMx8HGG0ns3y 3OZg== 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=ScvRFyLspLV+u/z+2QdiwwIEvkWm73jTIZB0oMl2mEx4FfS3g79A40ZDK2G5X8iMQP fFK3Asf7g4g6Gi2jko8s4zyVuNgLEz4udfhqp6LRZbsVVKHp7ixu+txp/hBRQHFc/SGH IMb8l1tvvC3OeHmWEh9BMNX42xOR0YTUbVTgS2O90v+J9L7eUPgaYFQDbO1NLdDXJMYK Ytmiah8qGJUb3zdX6UZfAhUCPDuXR/1f7MlRxJophwWKh4oeaRa/ijLnP3RVei62g1Ex 3sioONOF7DoEYyutIqBJrBiVB5nw4jL1gc4jSWQ6kPPNR5H+ST4xtsCad9XZhOexzp6T BrnA== 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 h11si531759otr.197.2020.02.12.09.56.15; Wed, 12 Feb 2020 09:56:27 -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 S1728992AbgBLRz4 (ORCPT + 99 others); Wed, 12 Feb 2020 12:55:56 -0500 Received: from inva020.nxp.com ([92.121.34.13]:35730 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728861AbgBLRzz (ORCPT ); Wed, 12 Feb 2020 12:55:55 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 4A16C1A7A82; Wed, 12 Feb 2020 18:55:53 +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 3D36B1C27C5; Wed, 12 Feb 2020 18:55:53 +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 C8763204D3; Wed, 12 Feb 2020 18:55:52 +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 v6 4/9] crypto: caam - refactor RSA private key _done callbacks Date: Wed, 12 Feb 2020 19:55:19 +0200 Message-Id: <1581530124-9135-5-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1581530124-9135-1-git-send-email-iuliana.prodan@nxp.com> References: <1581530124-9135-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