Received: by 2002:a17:90a:b81:0:0:0:0 with SMTP id 1csp674535pjr; Fri, 9 Aug 2019 04:32:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHaAg54uHM0YyXOG680F5uxbHKPfOgLb8tFMNBwJwD9wl4p3wElAw8LhV7Zwjr6ud0ZOaw X-Received: by 2002:a63:5a0a:: with SMTP id o10mr17314519pgb.282.1565350325364; Fri, 09 Aug 2019 04:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565350325; cv=none; d=google.com; s=arc-20160816; b=SxYSKsv4+2HYYdYb1Anqas5MGm11jxRrOIbGUYb6M+HPt7ESmhuuq3q5fvJ0fIHwh0 7J0Dd42kA6IIHMPjET3BIfxtlfa0Pr1OBC5qI9QJZzIfYPkYQPNFwUXwCF9uQfroSukg 0gI5G7E7wEfPr7MzZSaMhPJxWJ07tejh67I4K09gYhCdpuBsMGiIufJ1c/KhU4dtNT86 mkPo+2R0aD7osA2NlsVPoWJFxdKgSezw+uqL/klxr9HqRGBrvrqbaJ1JDJ2xPzqgrSR0 o6DvJaqTE6zlu8u0874zLPpVQlVPGhNy7sTNP6XAvUYC/VrmPKqOkz9FPhDOk5EMkXzO eQAA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=DWyb8mosayQnd4wDnqDT+SJa7crqP1zFQKuzCXaI7XM=; b=ku3i+8zpvyhrZXcdDZXAga+wV1vdfykL+Uvlf6aRKlh7KIdt8+WXMujL7GjObiYW7n SEzbPK9gLbkpzpxym/UGuIsxN4wxVXTY+lq/oKHxAQq2zP59sU+rd4h3q00vzcl7oS5b CNqnx5vA2UIfDrZjsKNbwRYDlqsPQyXwU6N2J19PAeHNBwNB/mKv2J8KWber64vCNdcr VClUU0iYuv3eyC1axnEUIuJxeOrY6Jqn+duZ/0QFTffNY36a08Qc0kmCoofHvBqUB0Xw 7DOT3Ckj9lVu9yVt0b2Xz0ku2aTdkhlgeYBXrLOap1Zft1pzFghXGj2gj0963e15cnNz 7rhA== 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 q8si54257302pfc.155.2019.08.09.04.31.50; Fri, 09 Aug 2019 04:32:05 -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 S2406219AbfHILbS (ORCPT + 99 others); Fri, 9 Aug 2019 07:31:18 -0400 Received: from foss.arm.com ([217.140.110.172]:46032 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726140AbfHILbS (ORCPT ); Fri, 9 Aug 2019 07:31:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C07901596; Fri, 9 Aug 2019 04:31:17 -0700 (PDT) Received: from [10.1.194.37] (e113632-lin.cambridge.arm.com [10.1.194.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 27C633F575; Fri, 9 Aug 2019 04:31:17 -0700 (PDT) Subject: Re: [PATCH v4 6/8] sched: Replace strncmp with str_has_prefix To: Chuhong Yuan Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org References: <20190809071051.17387-1-hslester96@gmail.com> From: Valentin Schneider Message-ID: Date: Fri, 9 Aug 2019 12:31:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190809071051.17387-1-hslester96@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/08/2019 08:10, Chuhong Yuan wrote: > strncmp(str, const, len) is error-prone because len > is easy to have typo. > The example is the hard-coded len has counting error > or sizeof(const) forgets - 1. > So we prefer using newly introduced str_has_prefix() > to substitute such strncmp to make code better. > > Signed-off-by: Chuhong Yuan I tried to have a look at the series as a whole but it's not properly threaded (or at least doesn't appear as such on lore), which makes it unnecessarily annoying to review. Please make sure to use git-send-email, which should properly thread all patches (IOW make them in-reply-to the cover letter). Other than that, I stared at it and it seems fine. It's not that helpful here since I doubt any of these prefixes will change in the near feature, but hey, why not. Reviewed-by: Valentin Schneider > --- > Changes in v4: > - Eliminate assignments in if conditions. > > kernel/sched/debug.c | 6 ++++-- > kernel/sched/isolation.c | 11 +++++++---- > 2 files changed, 11 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c > index f7e4579e746c..a03900523e5d 100644 > --- a/kernel/sched/debug.c > +++ b/kernel/sched/debug.c > @@ -102,10 +102,12 @@ static int sched_feat_set(char *cmp) > { > int i; > int neg = 0; > + size_t len; > > - if (strncmp(cmp, "NO_", 3) == 0) { > + len = str_has_prefix(cmp, "NO_"); > + if (len) { > neg = 1; > - cmp += 3; > + cmp += len; > } > > i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp); > diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c > index ccb28085b114..ea2ead4b1906 100644 > --- a/kernel/sched/isolation.c > +++ b/kernel/sched/isolation.c > @@ -141,16 +141,19 @@ __setup("nohz_full=", housekeeping_nohz_full_setup); > static int __init housekeeping_isolcpus_setup(char *str) > { > unsigned int flags = 0; > + size_t len; > > while (isalpha(*str)) { > - if (!strncmp(str, "nohz,", 5)) { > - str += 5; > + len = str_has_prefix(str, "nohz,"); > + if (len) { > + str += len; > flags |= HK_FLAG_TICK; > continue; > } > > - if (!strncmp(str, "domain,", 7)) { > - str += 7; > + len = str_has_prefix(str, "domain,"); > + if (len) { > + str += len; > flags |= HK_FLAG_DOMAIN; > continue; > } >