Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5961673ybi; Wed, 31 Jul 2019 06:09:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/D2yr8FIHj7UlGrPJedihtNjVcEtCp0fIMS/UURZz+PoALrRXC40OD6D85Ou5NYQ7RKnC X-Received: by 2002:a65:6093:: with SMTP id t19mr34217059pgu.79.1564578554479; Wed, 31 Jul 2019 06:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564578554; cv=none; d=google.com; s=arc-20160816; b=fF8r5LtdJvu4OIxQUEdjYfnS8OhIZkuvjoDdbHIJzXkQ146hsLJEVBEyicYfM00wg5 DxaQXTSw1dlFW/z+FiiE7WSOWKlnR+iNH2sUaSpassGrnad2xD0IVGldiOEGIN9pL1sr 78kmHabDSIMYSR5g29oNAkCw4FQWu5XcL/HQRSDO+RcXeuY8S8H+KXoQGwxwP09UN8Ai kKd6GHmLdiyip/1Gcym20FK0zNarTBqanZOjid8H3dk2mb4hCB2c3pMSsH1QwLb9JwCK ccjzh99s7SWrcCpJWe9DN35HqcruyB7rLRXXynRhD5h6Q0DMEqf7oYQcO2NOZqlSdIJS 4ikQ== 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=ch2STrIX2Scw/iMNHlJ+BSxmDFqXRbAV9pocEKbibec=; b=NX6h+KQ9tFlkBUhJsjy/iM1l90dtZr2kCo4kh7ES5ePnS2RrDEkGxjtzEwM+24CkEt bwNs/pD8XN12ZhXcqemnVuyxGpFiiYP4jNQwS/zGdL67IgJXS+koPzgAOodeJ02BM0LG TV3myfR/KRwFNpGN4rCTN6zYFY5jGWAdzRzsNu5wK/MSIPl+SRPQshihf4oJ6D63CZFS Dwu5AxMx/PQGJSOGRL3ywaYRZf8rlONYRQbBLDr3TG3N98QgQ7Xi2w2eCgbSjPlz5bhb s5lUa850DJFKVK/5ahC+Sq5twyAfq4nTunCuH04AYiY07TEUPWmBFZCyqVXAUiPpVVrc 1+4g== 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 k129si23628963pgk.42.2019.07.31.06.09.00; Wed, 31 Jul 2019 06:09:14 -0700 (PDT) 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 S1727338AbfGaNIj (ORCPT + 99 others); Wed, 31 Jul 2019 09:08:39 -0400 Received: from inva020.nxp.com ([92.121.34.13]:35274 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388167AbfGaNI2 (ORCPT ); Wed, 31 Jul 2019 09:08:28 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 050741A09DF; Wed, 31 Jul 2019 15:08:26 +0200 (CEST) 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 ECFE11A09DE; Wed, 31 Jul 2019 15:08:25 +0200 (CEST) Received: from lorenz.ea.freescale.net (lorenz.ea.freescale.net [10.171.71.5]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 99628205F3; Wed, 31 Jul 2019 15:08:25 +0200 (CEST) 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 Subject: [PATCH v5 13/14] crypto: caam - unregister algorithm only if the registration succeeded Date: Wed, 31 Jul 2019 16:08:14 +0300 Message-Id: <1564578495-9883-14-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1564578495-9883-1-git-send-email-iuliana.prodan@nxp.com> References: <1564578495-9883-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 To know if a registration succeeded added a new struct, caam_akcipher_alg, that keeps, also, the registration status. This status is updated in caam_pkc_init and verified in caam_pkc_exit to unregister an algorithm. Fixes: 1b46c90c8e00 ("crypto: caam - convert top level drivers to libraries") Signed-off-by: Iuliana Prodan Reviewed-by: Horia Geanta --- drivers/crypto/caam/caampkc.c | 49 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index e00a470..5b12b23 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -35,6 +35,11 @@ static u8 *zero_buffer; */ static bool init_done; +struct caam_akcipher_alg { + struct akcipher_alg akcipher; + bool registered; +}; + static void rsa_io_unmap(struct device *dev, struct rsa_edesc *edesc, struct akcipher_request *req) { @@ -1058,22 +1063,24 @@ static void caam_rsa_exit_tfm(struct crypto_akcipher *tfm) caam_jr_free(ctx->dev); } -static struct akcipher_alg caam_rsa = { - .encrypt = caam_rsa_enc, - .decrypt = caam_rsa_dec, - .set_pub_key = caam_rsa_set_pub_key, - .set_priv_key = caam_rsa_set_priv_key, - .max_size = caam_rsa_max_size, - .init = caam_rsa_init_tfm, - .exit = caam_rsa_exit_tfm, - .reqsize = sizeof(struct caam_rsa_req_ctx), - .base = { - .cra_name = "rsa", - .cra_driver_name = "rsa-caam", - .cra_priority = 3000, - .cra_module = THIS_MODULE, - .cra_ctxsize = sizeof(struct caam_rsa_ctx), - }, +static struct caam_akcipher_alg caam_rsa = { + .akcipher = { + .encrypt = caam_rsa_enc, + .decrypt = caam_rsa_dec, + .set_pub_key = caam_rsa_set_pub_key, + .set_priv_key = caam_rsa_set_priv_key, + .max_size = caam_rsa_max_size, + .init = caam_rsa_init_tfm, + .exit = caam_rsa_exit_tfm, + .reqsize = sizeof(struct caam_rsa_req_ctx), + .base = { + .cra_name = "rsa", + .cra_driver_name = "rsa-caam", + .cra_priority = 3000, + .cra_module = THIS_MODULE, + .cra_ctxsize = sizeof(struct caam_rsa_ctx), + }, + } }; /* Public Key Cryptography module initialization handler */ @@ -1101,13 +1108,15 @@ int caam_pkc_init(struct device *ctrldev) if (!zero_buffer) return -ENOMEM; - err = crypto_register_akcipher(&caam_rsa); + err = crypto_register_akcipher(&caam_rsa.akcipher); + if (err) { kfree(zero_buffer); dev_warn(ctrldev, "%s alg registration failed\n", - caam_rsa.base.cra_driver_name); + caam_rsa.akcipher.base.cra_driver_name); } else { init_done = true; + caam_rsa.registered = true; dev_info(ctrldev, "caam pkc algorithms registered in /proc/crypto\n"); } @@ -1119,6 +1128,8 @@ void caam_pkc_exit(void) if (!init_done) return; + if (caam_rsa.registered) + crypto_unregister_akcipher(&caam_rsa.akcipher); + kfree(zero_buffer); - crypto_unregister_akcipher(&caam_rsa); } -- 2.1.0