Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1502877imm; Tue, 22 May 2018 05:14:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrnESj/k+bwMQGAaOCjU2JOOkbbP7scef+mOcdLJ++XU56Wl5BQQP1TEd2U0SPKKyheUjZM X-Received: by 2002:a17:902:1007:: with SMTP id b7-v6mr23866168pla.88.1526991243343; Tue, 22 May 2018 05:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526991243; cv=none; d=google.com; s=arc-20160816; b=fyr5zmW6rwE+IAs9ISmIn9q5TnF6J33eOjORy54TL+w/wzLm1xjEvE1/qTrflKLtq0 O/nCd+81lpRiBEHpbjwFhtgu1MZj6EEXblyJOwbbP1jqMDXhWiuQNMhkSemcKimaUejT i5wiXs/6KPZ9VvfjGMLZG2L6vkt0dZDmPpyd0LdRxZpbDzhglS1YxbMG5y/gtKTyn1a6 RKkGNMSm++ZyMa8LsAzL1AemTdxWjsyd5tsaJJvEMJMf8hyMMmaVmcRFI2EeFIwLFf4p jWUoS4EmmIqgh467q8S2yYx2oyAgWxBzkE51kFB8wUfcH3zYCNWE74EeE86NRxcp9JIg IIlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=5sAMsOeQDPQhAa+0g4Q7238iBcLt66DDoJKUKa+uD0Q=; b=x4m/blfEQQvucQKgpEFOWi9QRLxA5j2+KUGd8+sdLIraTCiC3FOolt62Cx9lt0U46+ e9JeLjhg58nwCV4tRx+KxUrbsqpKybpKR10Tqht8FRBARECSXaDfHtA0WZwgL3wqMOeH vXrf6TlNK4s330HVI0dNbqxrXrstFFv6+bbY2tBg1n+GPX2OmOTQNt3Z9YJ8kurcu/sI CcU+ZNsDQzxR+TCPRb3TVMg3Q64JIoTU2Fc8KYVk1ClBl1DuKtScykILTjoak4j7YO6O Hq/huMGQxiumlD0i12A6vBR4P1Zz1Gri08A5mf0A8V6P8Km3EyTmCvcrF5bEJ/KUCHkM rpYg== 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 d7-v6si16595273pfe.214.2018.05.22.05.13.48; Tue, 22 May 2018 05:14:03 -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 S1752829AbeEVMMU (ORCPT + 99 others); Tue, 22 May 2018 08:12:20 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33304 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751441AbeEVMMG (ORCPT ); Tue, 22 May 2018 08:12:06 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id A4FCA532829FD; Tue, 22 May 2018 20:12:03 +0800 (CST) Received: from [127.0.0.1] (10.177.29.40) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.382.0; Tue, 22 May 2018 20:12:02 +0800 Subject: Re: [PATCH 27/33] sched/debug: use match_string() helper To: Andy Shevchenko References: <1526903890-35761-1-git-send-email-xieyisheng1@huawei.com> <1526903890-35761-28-git-send-email-xieyisheng1@huawei.com> CC: Linux Kernel Mailing List , Ingo Molnar , Peter Zijlstra From: Yisheng Xie Message-ID: <8a7108ce-a109-a1b5-ace7-38a189d2352d@huawei.com> Date: Tue, 22 May 2018 20:10:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.40] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On 2018/5/22 6:13, Andy Shevchenko wrote: > On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie wrote: >> match_string() returns the index of an array for a matching string, >> which can be used intead of open coded variant. >> >> Cc: Ingo Molnar >> Cc: Peter Zijlstra >> Signed-off-by: Yisheng Xie >> --- >> kernel/sched/debug.c | 20 +++++++++----------- >> 1 file changed, 9 insertions(+), 11 deletions(-) >> >> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c >> index 15b10e2..9e34499 100644 >> --- a/kernel/sched/debug.c >> +++ b/kernel/sched/debug.c >> @@ -111,16 +111,14 @@ 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) { > > Why not > > if (i < 0) > return i; if i >=0 it will also return i. so need return i just if (i < 0), right ? > > ? > >> + if (neg) { >> + sysctl_sched_features &= ~(1UL << i); >> + sched_feat_disable(i); >> + } else { >> + sysctl_sched_features |= (1UL << i); >> + sched_feat_enable(i); >> } >> } >> >> @@ -150,7 +148,7 @@ static int sched_feat_set(char *cmp) >> inode_lock(inode); >> i = sched_feat_set(cmp); >> inode_unlock(inode); > >> - if (i == __SCHED_FEAT_NR) >> + if (i < 0) >> return -EINVAL; > > Now it would be > > if (i < 0) > return i; Right, will change it in next version Thanks Yisheng Xie >