Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1096885imu; Wed, 16 Jan 2019 12:41:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN6g2QCwne4dm/EnflRHEHi8GfCH8z+O3HI+Hg2sfG9LcMPNqygMgEF+ReIg5O68X52wT5Xd X-Received: by 2002:a63:c24c:: with SMTP id l12mr10683396pgg.146.1547671273447; Wed, 16 Jan 2019 12:41:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547671273; cv=none; d=google.com; s=arc-20160816; b=nChzyJQ27nzk7PMCzlUjHezx4NlS5fzEir+GW0PFt2lKkeHB6VgNrp9rSKcsBJiwrL /UYdo6Ssg/I07a9YLOSHf2Mm0meEh3v1fzieqDggVs8E/JF60rJSF8WkMSUO/jSM8OiD sw9v1x0aSEcdh0arQuDfNhxDFFXFIIcUeEsIGLcULFqOI/sxQCG0dYh+czqQUV1kn/7P ZuX41yV34gpmkWgAAlUqYsUwv66nqkBACTYcY3wcdRl0lBYhlzESUj8+mtlUBNpG8v9y i93ban5+uZWgxDXIVAuy7NSfT1fUfW13DBUB0u/qe1+K5BP7fcQel2EtgQqki68DkVY1 qt/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=AUr5JcekR0dRu4nvEpw01SfVKWs5uJC+Xy1nAfphOz0=; b=Ag3gkwIpwuEYiVRzQ6YcT41Nf3IsUyEm9lqSnY5xlJielUNS4kErbrmIIvivf3NCmP PAeVELDdF/rCcAp7ivGIsIrGVXBXzaN/rbxKOYg+pZ2kaS7GLI7z5w227zjcrDvvR0fV DYqQjvpFBn3jp67WbytbfbPwu1Ls84nIEHLi+M4AKcUqUSHDpo2y5HsoMgq1rsOl9PJV ajrczVyT4XxOaD5YFkWRGHXQ3HGYTA24emgh4guovk0vvvrYO9tP2wkCXnOXAMvIub5X vBinh9M6sBglR2HN++x79e2USnk8Ts9zSNXT0AdxsWwkZ/g9H/Y9cMuCT1XKVIt/vO7J vDfQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si7072040plk.257.2019.01.16.12.40.55; Wed, 16 Jan 2019 12:41:13 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730305AbfAPCvc (ORCPT + 99 others); Tue, 15 Jan 2019 21:51:32 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:17553 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729853AbfAPCvc (ORCPT ); Tue, 15 Jan 2019 21:51:32 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 7BC2EBC3D61C7FD6D7C8; Wed, 16 Jan 2019 10:51:20 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Wed, 16 Jan 2019 10:51:10 +0800 From: Xiongfeng Wang To: , CC: , , , , , Subject: [PATCH 2/5] crypto: ccm - use template array registering API to simplify the code Date: Wed, 16 Jan 2019 10:50:31 +0800 Message-ID: <1547607034-40948-3-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1547607034-40948-1-git-send-email-wangxiongfeng2@huawei.com> References: <1547607034-40948-1-git-send-email-wangxiongfeng2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use crypto template array registering API to simplify the code. Signed-off-by: Xiongfeng Wang --- crypto/ccm.c | 81 +++++++++++++++++++----------------------------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/crypto/ccm.c b/crypto/ccm.c index b242fd0..8949aa2 100644 --- a/crypto/ccm.c +++ b/crypto/ccm.c @@ -589,12 +589,6 @@ static int crypto_ccm_create(struct crypto_template *tmpl, struct rtattr **tb) mac_name); } -static struct crypto_template crypto_ccm_tmpl = { - .name = "ccm", - .create = crypto_ccm_create, - .module = THIS_MODULE, -}; - static int crypto_ccm_base_create(struct crypto_template *tmpl, struct rtattr **tb) { @@ -618,12 +612,6 @@ static int crypto_ccm_base_create(struct crypto_template *tmpl, cipher_name); } -static struct crypto_template crypto_ccm_base_tmpl = { - .name = "ccm_base", - .create = crypto_ccm_base_create, - .module = THIS_MODULE, -}; - static int crypto_rfc4309_setkey(struct crypto_aead *parent, const u8 *key, unsigned int keylen) { @@ -854,12 +842,6 @@ static int crypto_rfc4309_create(struct crypto_template *tmpl, goto out; } -static struct crypto_template crypto_rfc4309_tmpl = { - .name = "rfc4309", - .create = crypto_rfc4309_create, - .module = THIS_MODULE, -}; - static int crypto_cbcmac_digest_setkey(struct crypto_shash *parent, const u8 *inkey, unsigned int keylen) { @@ -999,51 +981,40 @@ static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb) return err; } -static struct crypto_template crypto_cbcmac_tmpl = { - .name = "cbcmac", - .create = cbcmac_create, - .free = shash_free_instance, - .module = THIS_MODULE, +static struct crypto_template crypto_ccm_tmpl[] = { + { + .name = "cbcmac", + .create = cbcmac_create, + .free = shash_free_instance, + .module = THIS_MODULE, + }, + { + .name = "ccm_base", + .create = crypto_ccm_base_create, + .module = THIS_MODULE, + }, + { + .name = "ccm", + .create = crypto_ccm_create, + .module = THIS_MODULE, + }, + { + .name = "rfc4309", + .create = crypto_rfc4309_create, + .module = THIS_MODULE, + }, }; static int __init crypto_ccm_module_init(void) { - int err; - - err = crypto_register_template(&crypto_cbcmac_tmpl); - if (err) - goto out; - - err = crypto_register_template(&crypto_ccm_base_tmpl); - if (err) - goto out_undo_cbcmac; - - err = crypto_register_template(&crypto_ccm_tmpl); - if (err) - goto out_undo_base; - - err = crypto_register_template(&crypto_rfc4309_tmpl); - if (err) - goto out_undo_ccm; - -out: - return err; - -out_undo_ccm: - crypto_unregister_template(&crypto_ccm_tmpl); -out_undo_base: - crypto_unregister_template(&crypto_ccm_base_tmpl); -out_undo_cbcmac: - crypto_register_template(&crypto_cbcmac_tmpl); - goto out; + return crypto_register_templates(crypto_ccm_tmpl, + ARRAY_SIZE(crypto_ccm_tmpl)); } static void __exit crypto_ccm_module_exit(void) { - crypto_unregister_template(&crypto_rfc4309_tmpl); - crypto_unregister_template(&crypto_ccm_tmpl); - crypto_unregister_template(&crypto_ccm_base_tmpl); - crypto_unregister_template(&crypto_cbcmac_tmpl); + crypto_unregister_templates(crypto_ccm_tmpl, + ARRAY_SIZE(crypto_ccm_tmpl)); } module_init(crypto_ccm_module_init); -- 1.7.12.4