Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp225911imm; Mon, 21 May 2018 05:11:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq/IARR6XlMf8EDgCpMTmTSIpDTkZKGeMz19JHOmWXJRWIhSd6uqzcmb7vaeLC0k2rPZWOA X-Received: by 2002:a17:902:868b:: with SMTP id g11-v6mr19762903plo.305.1526904687223; Mon, 21 May 2018 05:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526904687; cv=none; d=google.com; s=arc-20160816; b=jhrVC2fpAVbgHy3nsGUYtL4QztwLf5yBTAHMsy7QeAXtbnP9zf7by8QOKW2u25NrZB eAdO1m3pTMscHXejsy1Ww8EvO244k1XexdznQ5e75+3jKx3/nlJ6tFhFa8XYH4DPLFYi TpdtSxIWtyMLeB5kTQhUntm4Mtts9oVG4wun0TOmF2gHL1UI/cd7uxo+VKFnYro3gjHG oie+GUxP58O6jPOR+fuM15g/2AMxU1DftCpYq9IWNL5KVoNI+ME6l5bZO98b+9TDe7DV dN45tHa7ed8+gzm46xaOTUcY8ijsZnnqoCJKdtXYUp7Sq+Kv8gSaC41Xkoe4MUTzbLI8 aNag== 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=fdpaMHPITEXPGIKhdJIX8BRNLOP/TzUUKBZer0Kee6c=; b=B1JnE50Lkte6BZHmmKiNJD0gbQw9srgWf96GEM6EGbDowPmK2SRfbgCUt0DvcXvhA/ xKJfSs4i1XbiEsOAgpPZ0JOKPgAqIrgN1pV0u5FIKzVg8UOClB3MG5oVbKWglVrhKz9w aE68jAokjwPozrisRjL7tstZ4xNj0wPbysXPrezLqnD5FkxywB/DjNQ2eKHgQiS34BiG naVdoOi7NBc36Uox0WB0PvDrOSI2chu9BXwam7p+E0cvtDL8c3Gb5KyOs+ZoxjX8XvQ2 IgwZmquI3ECX5Z0q2OEs6+v0Z1jVbB+3uZdb/NFj/AwpUyOj2WYe4UrRUuHXLFazSqwG oW9g== 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 l7-v6si14726787plt.197.2018.05.21.05.11.12; Mon, 21 May 2018 05:11:27 -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 S1753167AbeEUMJs (ORCPT + 99 others); Mon, 21 May 2018 08:09:48 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7716 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752999AbeEUMJZ (ORCPT ); Mon, 21 May 2018 08:09:25 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A3F64BA558036; 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 , John Johansen , James Morris , "Serge E. Hallyn" , Subject: [PATCH 26/33] apparmor: use match_string() helper Date: Mon, 21 May 2018 19:58:03 +0800 Message-ID: <1526903890-35761-27-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: John Johansen Cc: James Morris Cc: "Serge E. Hallyn" Cc: linux-security-module@vger.kernel.org Signed-off-by: Yisheng Xie --- security/apparmor/lsm.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index ce2b89e..9b5904f 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -1378,14 +1378,12 @@ static int param_set_audit(const char *val, const struct kernel_param *kp) if (apparmor_initialized && !policy_admin_capable(NULL)) return -EPERM; - for (i = 0; i < AUDIT_MAX_INDEX; i++) { - if (strcmp(val, audit_mode_names[i]) == 0) { - aa_g_audit = i; - return 0; - } - } + i = match_string(audit_mode_names, AUDIT_MAX_INDEX, val); + if (i < 0) + return -EINVAL; - return -EINVAL; + aa_g_audit = i; + return 0; } static int param_get_mode(char *buffer, const struct kernel_param *kp) @@ -1409,14 +1407,13 @@ static int param_set_mode(const char *val, const struct kernel_param *kp) if (apparmor_initialized && !policy_admin_capable(NULL)) return -EPERM; - for (i = 0; i < APPARMOR_MODE_NAMES_MAX_INDEX; i++) { - if (strcmp(val, aa_profile_mode_names[i]) == 0) { - aa_g_profile_mode = i; - return 0; - } - } + i = match_string(aa_profile_mode_names, + APPARMOR_MODE_NAMES_MAX_INDEX, val); + if (i) + return -EINVAL; - return -EINVAL; + aa_g_profile_mode = i; + return 0; } /* -- 1.7.12.4