From patchwork Tue Oct 18 07:26:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li zeming X-Patchwork-Id: 3990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1822203wrs; Tue, 18 Oct 2022 00:33:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43r01tg86NzDP5Vol1jhgHw+1G6FC80Lig8Rl9WnDTKS8d3rGOSI/L1mTQ2mQjlqmgivli X-Received: by 2002:a17:90b:3805:b0:20d:4e77:371f with SMTP id mq5-20020a17090b380500b0020d4e77371fmr2135868pjb.170.1666078416224; Tue, 18 Oct 2022 00:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666078416; cv=none; d=google.com; s=arc-20160816; b=uUv4bJl/9Sq1mFmjDXaSoJu1VrTQa3Bj0JY/ojZfM2SHMNqRlOXVcNECVEASWuenPl YmVwdPyJ5/KHp7zb9F+bS1MR8c2pIWLFwarJUb12eVsUHd+8BlKAd0HOaG+BNLiYzdD6 hP2l5IgbSMkyffri6yYEcMZGyuEdY7wWx/Q/prBGMWD34gG0c10p6+CE6AowYxuIOmcW WRjBMkfaN3I59vldV2JsLhDetKLRDCq86SCzfDcYdrXl8zQYhg/nvuxJf+B7HJvo8IRn Ok9BZzBiQeN6s2iV/Y0SxWCGjGX36BnMMP6mOeXC1uAIzTT5OOrubvTYUSVkGkVLAdZ+ GggA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=GR/gaBvwqXxqf2RzFxupsjbAatya8fM326wE4AQS0d4=; b=zdStEbvFzGF3ITIrjo/KtjlIZyA4kbEhyFzI9QYyBogxWzq2yJHY9Xi8AJSH+pnb+t Qkwr/N0/krjN4IelmaUu7l2NeKBZ/ycJYarDgnACe7wdFKqkvrWls0M+BTzQj4SsdzmU 91dhH3J35gq2vWDZv3QtPsEq+L7p55KzaYNu18dZQxpYf+SC3CCZlqdsQvCwqH2EVbnG kuUUtq0LP5vpB2d3PA8MMbkQokvjuAcfkZVrrt7MmfKutJlO3g/ln/fn5LkYXoRBRiWI Nup0I/GBMzVmRa1sEZeec2X2q/BreP74FoKd2pYoWdk2wEzaQGSsGO7bomQeYTTvJQ2L 7a4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s200-20020a632cd1000000b0042ff6b15129si13535412pgs.2.2022.10.18.00.33.23; Tue, 18 Oct 2022 00:33:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbiJRH01 (ORCPT + 99 others); Tue, 18 Oct 2022 03:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbiJRH00 (ORCPT ); Tue, 18 Oct 2022 03:26:26 -0400 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 12EC01900A; Tue, 18 Oct 2022 00:26:23 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 189201E80D76; Tue, 18 Oct 2022 15:25:42 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gJH4XJN1_3v4; Tue, 18 Oct 2022 15:25:39 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 4B8E81E80D17; Tue, 18 Oct 2022 15:25:39 +0800 (CST) From: Li zeming To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Li zeming Subject: [PATCH] integrity: iint: Optimize integrity_iintcache_init and integrity_inode_free function Date: Tue, 18 Oct 2022 15:26:11 +0800 Message-Id: <20221018072611.198802-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747009841312664157?= X-GMAIL-MSGID: =?utf-8?q?1747009841312664157?= These functions are optimized as follows. 1. Remove void * variable foo cast type. 2. iint_cache Added memory allocation check. Signed-off-by: Li zeming --- security/integrity/iint.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/security/integrity/iint.c b/security/integrity/iint.c index 8638976f7990..7c902b92482e 100644 --- a/security/integrity/iint.c +++ b/security/integrity/iint.c @@ -160,7 +160,7 @@ void integrity_inode_free(struct inode *inode) static void init_once(void *foo) { - struct integrity_iint_cache *iint = (struct integrity_iint_cache *) foo; + struct integrity_iint_cache *iint = foo; memset(iint, 0, sizeof(*iint)); iint->ima_file_status = INTEGRITY_UNKNOWN; @@ -177,6 +177,9 @@ static int __init integrity_iintcache_init(void) iint_cache = kmem_cache_create("iint_cache", sizeof(struct integrity_iint_cache), 0, SLAB_PANIC, init_once); + if (!iint_cache) + return -ENOMEM; + return 0; } DEFINE_LSM(integrity) = {