From patchwork Thu Mar 22 14:43:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 10301635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CB70560216 for ; Thu, 22 Mar 2018 14:43:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2D7E28630 for ; Thu, 22 Mar 2018 14:43:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B784C286BC; Thu, 22 Mar 2018 14:43:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CAB628630 for ; Thu, 22 Mar 2018 14:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754401AbeCVOnw (ORCPT ); Thu, 22 Mar 2018 10:43:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:47253 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753456AbeCVOnw (ORCPT ); Thu, 22 Mar 2018 10:43:52 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4C205AE35; Thu, 22 Mar 2018 14:43:51 +0000 (UTC) From: Petr Vorel To: linux-integrity@vger.kernel.org Cc: Petr Vorel , Mimi Zohar , Dmitry Kasatkin Subject: [PATCH v2 1/2] ima: Introduce ima_alloc_alg() to reduce duplicity Date: Thu, 22 Mar 2018 15:43:12 +0100 Message-Id: <20180322144313.28748-2-pvorel@suse.cz> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180322144313.28748-1-pvorel@suse.cz> References: <20180322144313.28748-1-pvorel@suse.cz> Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is preparation for next commit. Signed-off-by: Petr Vorel --- security/integrity/ima/ima_crypto.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 205bc69361ea..ddc18f4633e5 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -62,36 +62,33 @@ MODULE_PARM_DESC(ahash_bufsize, "Maximum ahash buffer size"); static struct crypto_shash *ima_shash_tfm; static struct crypto_ahash *ima_ahash_tfm; -int __init ima_init_crypto(void) +static int ima_alloc_shash(struct crypto_shash **tfm, const char *alg_name) { long rc; - ima_shash_tfm = crypto_alloc_shash(hash_algo_name[ima_hash_algo], 0, 0); - if (IS_ERR(ima_shash_tfm)) { - rc = PTR_ERR(ima_shash_tfm); - pr_err("Can not allocate %s (reason: %ld)\n", - hash_algo_name[ima_hash_algo], rc); + *tfm = crypto_alloc_shash(alg_name, 0, 0); + if (IS_ERR(*tfm)) { + rc = PTR_ERR(*tfm); + pr_err("Can not allocate %s (reason: %ld)\n", alg_name, rc); return rc; } return 0; } +int __init ima_init_crypto(void) +{ + return ima_alloc_shash(&ima_shash_tfm, hash_algo_name[ima_hash_algo]); +} + static struct crypto_shash *ima_alloc_tfm(enum hash_algo algo) { struct crypto_shash *tfm = ima_shash_tfm; - int rc; if (algo < 0 || algo >= HASH_ALGO__LAST) algo = ima_hash_algo; - if (algo != ima_hash_algo) { - tfm = crypto_alloc_shash(hash_algo_name[algo], 0, 0); - if (IS_ERR(tfm)) { - rc = PTR_ERR(tfm); - pr_err("Can not allocate %s (reason: %d)\n", - hash_algo_name[algo], rc); - } - } + if (algo != ima_hash_algo) + ima_alloc_shash(&tfm, hash_algo_name[algo]); return tfm; }