Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp225264imm; Mon, 21 May 2018 05:10:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdW0/tNThnBzQV7hviGVfBac0+AhXgMCLMvxrkbwDeCB1RGrPNAV5hr5f9hl2FbllpUppp X-Received: by 2002:a63:8649:: with SMTP id x70-v6mr12449833pgd.226.1526904651488; Mon, 21 May 2018 05:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526904651; cv=none; d=google.com; s=arc-20160816; b=DsFUYlUoHBjMWDfCqhJGPsxOmZnF9/HhonLDGcwG2Zy6ZG+3GXhIwiQVCg285NiCvb sNoY4fPrcb+G6g3Jvo1hc9b+mb/dxgc/yVw/tkRn/iSYDwJlJy3lTzYOAm29XVK5OSRi vCpQR4sbdtZ47pVk/4TJM5VWo5AfJfTxtiriz1UIW1oGXBsb+Zhk0tHBaUrgs+yG0zWS EJPox2t5+OSIl16FfnWSks9+y4C4YQIgkYUu7uuCnqJfAbu3Pc38MTH7d/iHb7mthjoD m8u8uptr0b+HgE7LudRc3E6tDXAIwmSu76CBzUzxv1jwC9eHeLv3jYH7oLXydycl8X5X lCBQ== 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:arc-authentication-results; bh=CDdeMMgPLeOKTRDkvuh8asC8dsniNhngAIU6Tpz+V34=; b=Q2Epk65gcheNJUFg+OUDT3aHzx7+qjB8Uyi6h2hEcQQw9dOm7B3CFezVVZTMyMvvTn x43zNwestpsQCT5vnxL2NEG8rQIESXCU2T3cJ2Gqn4F8G5igX8xKul2XkvXSJme8B5v5 pAlaUu+K7EHv8tgQ7I24TmhxV+nDfQgkgvcERJi5upQVA1W0Bmx2PbL7bphhsZbf2i87 5uGxOz2ibjfYxS48lBZ5JhqrqyrwFOfiNy75nF15eSIyKfkol6sJjttQy36DkpAx5s9X F+y2A1LBOqTKu1D9esvlapOKw4X/B54QbZ3eyMJvCnwDy3OBAuX3F3VwFTPj1ek3xvvk 3iSg== 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 w64-v6si14400116pfw.201.2018.05.21.05.10.37; Mon, 21 May 2018 05:10:51 -0700 (PDT) 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 S1753134AbeEUMJm (ORCPT + 99 others); Mon, 21 May 2018 08:09:42 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7718 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752992AbeEUMJ0 (ORCPT ); Mon, 21 May 2018 08:09:26 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B2BD3E253539E; Mon, 21 May 2018 20:09:06 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.382.0; Mon, 21 May 2018 20:09:01 +0800 From: Yisheng Xie To: CC: Yisheng Xie , Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E. Hallyn" , , Subject: [PATCH 25/33] ima: use match_string() helper Date: Mon, 21 May 2018 19:58:02 +0800 Message-ID: <1526903890-35761-26-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com> References: <1526903890-35761-1-git-send-email-xieyisheng1@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 match_string() returns the index of an array for a matching string, which can be used intead of open coded variant. Cc: Mimi Zohar Cc: Dmitry Kasatkin Cc: James Morris Cc: "Serge E. Hallyn" Cc: linux-integrity@vger.kernel.org Cc: linux-security-module@vger.kernel.org Signed-off-by: Yisheng Xie --- security/integrity/ima/ima_main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 74d0bd7..f807093 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -61,14 +61,11 @@ static int __init hash_setup(char *str) goto out; } - for (i = 0; i < HASH_ALGO__LAST; i++) { - if (strcmp(str, hash_algo_name[i]) == 0) { - ima_hash_algo = i; - break; - } - } - if (i == HASH_ALGO__LAST) + i = match_string(hash_algo_name, HASH_ALGO__LAST, str); + if (i < 0) return 1; + + ima_hash_algo = i; out: hash_setup_done = 1; return 1; -- 1.7.12.4