Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp493847imm; Thu, 31 May 2018 04:26:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJFz0pLjQ0Q3vNhdMxTIkGvdaVJrP8EyvnoYWwGJrAVShSFfXdbJzeiPhQqShyfkYQ4egzG X-Received: by 2002:a17:902:57d0:: with SMTP id g16-v6mr6574843plj.222.1527766009193; Thu, 31 May 2018 04:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527766009; cv=none; d=google.com; s=arc-20160816; b=QL8Ilua//1ZAvShwjrbEu2d/fT2p/OyL4Zhq0XGzT4JoYiveMRi3QE7K25KddP9DzP Oc6MB99d2tSfly9g4yNs9uGasxa1A8iKcJuJvJ5w7S1CmTAIl2ILTU3VzpaWo+vvQfPq rq1TvDLcVzlLrB+EZIMTaNKQxhvY39g/udC6iHpPjT0hT2/YHY/IbBAN8bStlgKZ5eJ5 V7C/ULcAiBh1VZy1YsUuBnG7OxapuA7qUHTYoet+1hllPCkrXE7RePca1qawoJ9LTuo5 KXGSX26rNIGxNmVSbIqFmh0bDG2Ekwd9HVfaV3//Gb5zQKg2lKAu0hwltfhONh93keFg 3mOA== 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=Nkgb/TuW0WAah49scU0Z77KjDdJqrhIC2A3LN25SdDc=; b=E1VLlqKoAG3U5XzzPkEjxvcCudbhkZT+1et9MkMHmRegedPoGem0j9s0gBY+vdvvch MQlhBdwst85zX1pTVg/wimCME8GpJkzlLqF+bPdilD5eNSPrcMJixFRli2Ekq8OMjGu4 2sW+6+gvEvBsR8UTedwU6+jvkUKZlko5tAohukOOjHo/Go0Uxh8BIe+wd7NDklpOAKzM oSFXKUVmrdDhCZYEhIxVgvmK16Hnedk2UEUmhezts8SA37N5fk9Vxu57iYhJmytptmLR iLM4RsA4DqEK7MhMd2qkojFhuzsz6CW4lH5XuQnESfKDPgE0MkeOJHsoRj6jZGa31j0Z ujxA== 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 m6-v6si29229360pgq.611.2018.05.31.04.26.35; Thu, 31 May 2018 04:26:49 -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 S1754993AbeEaLZ1 (ORCPT + 99 others); Thu, 31 May 2018 07:25:27 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8227 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754683AbeEaLWn (ORCPT ); Thu, 31 May 2018 07:22:43 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 990F55B096723; Thu, 31 May 2018 19:22:29 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.382.0; Thu, 31 May 2018 19:22:25 +0800 From: Yisheng Xie To: CC: , Yisheng Xie , "Ingo Molnar" , Peter Zijlstra Subject: [PATCH v2 14/21] sched/debug: use match_string() helper Date: Thu, 31 May 2018 19:11:19 +0800 Message-ID: <1527765086-19873-15-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1527765086-19873-1-git-send-email-xieyisheng1@huawei.com> References: <1527765086-19873-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 instead of open coded variant. Cc: Ingo Molnar Cc: Peter Zijlstra Signed-off-by: Yisheng Xie --- v2: - rename i to ret to show the change in returned value meaning - per Andy kernel/sched/debug.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index 15b10e2..5591147 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -111,20 +111,19 @@ static int sched_feat_set(char *cmp) cmp += 3; } - for (i = 0; i < __SCHED_FEAT_NR; i++) { - if (strcmp(cmp, sched_feat_names[i]) == 0) { - if (neg) { - sysctl_sched_features &= ~(1UL << i); - sched_feat_disable(i); - } else { - sysctl_sched_features |= (1UL << i); - sched_feat_enable(i); - } - break; - } + i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp); + if (i < 0) + return i; + + if (neg) { + sysctl_sched_features &= ~(1UL << i); + sched_feat_disable(i); + } else { + sysctl_sched_features |= (1UL << i); + sched_feat_enable(i); } - return i; + return 0; } static ssize_t @@ -133,7 +132,7 @@ static int sched_feat_set(char *cmp) { char buf[64]; char *cmp; - int i; + int ret; struct inode *inode; if (cnt > 63) @@ -148,10 +147,10 @@ static int sched_feat_set(char *cmp) /* Ensure the static_key remains in a consistent state */ inode = file_inode(filp); inode_lock(inode); - i = sched_feat_set(cmp); + ret = sched_feat_set(cmp); inode_unlock(inode); - if (i == __SCHED_FEAT_NR) - return -EINVAL; + if (ret < 0) + return ret; *ppos += cnt; -- 1.7.12.4