Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp308318ybi; Thu, 1 Aug 2019 19:32:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeL5EcN02bkAaPckUGs49WRgD/0vAHmcjZ8Ou6oi1/h3H+h9AdmTueXVkQUYT3gPjVEek7 X-Received: by 2002:a65:5348:: with SMTP id w8mr121033416pgr.176.1564713155413; Thu, 01 Aug 2019 19:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564713155; cv=none; d=google.com; s=arc-20160816; b=RlRlWcAb331cP3Z+XkjapuBMbUrPPF55ulz16OJJZUQOpa1YRFQ628Ca1eAPk0rsaG uL/+8gvYMObaSell8pAxOa2UCkt/yLRjE47zBfuazKk4+qb7EqtxdVuhbAspuw+DfhdH uYdjI3GbtcGqRQo45U7FD2nO4OY+ATBirpASf2xgYnuWmVWuuzwdh0lsP6LeOYILaz1v IqteWKRBNrUc9y1c5Nf+5PhS5/9JxLBTj45QOF25UTzl+pebzjffjcHAlcCvHAMUmN6F HpNv+U2a5rTqIp5/ENs28ZO3jVDmaWdhpXtKGeN919AWWqylhdJU5+0ER7cU5RP4Vnhz oBZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=QNqYVJSJQaKqgrs//XJVX+Bi7rBtMitLuSGPIbLMf+A=; b=hGkBEhD2V6M2opwCG8Fz6meKW7VY40YfJ7qLWGwuAhE3qibIMSk1FcEs+7SwBhVNYI hF9oz+MqQ28vaIimkuD45lIELpN+d1+/+RC+na/l7QE35HYZLeUWDQfrrUGnHrbS9uoo 3M/i+h+xeR6dBvnGu3kDbWkaDybvEzu4r3Zr1p/Fy4tWmemDeYJetJNSID00A2o/ieah mD50m9ViWYpr6+rV89hMMgfi647Qqq+CwVunE7kB0Vmm3ismhZNGzu+a57LHipGoft2t EHEAF6BRVlpsfYKM/YNsVYDQPoJCznoi3Olwt3a537lOHcUljqFOWYIIAeUTovH3dgYP K0JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=uehjDwMt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si35929317pgf.457.2019.08.01.19.32.20; Thu, 01 Aug 2019 19:32:35 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=uehjDwMt; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388924AbfHBBri (ORCPT + 99 others); Thu, 1 Aug 2019 21:47:38 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41902 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727630AbfHBBrh (ORCPT ); Thu, 1 Aug 2019 21:47:37 -0400 Received: by mail-pf1-f194.google.com with SMTP id m30so35119385pff.8 for ; Thu, 01 Aug 2019 18:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QNqYVJSJQaKqgrs//XJVX+Bi7rBtMitLuSGPIbLMf+A=; b=uehjDwMtucPY7a0/Xzh17QwaBhRz2LVB4y1KguITSTUcYtz+b4RSsg3BJAEj+q5To9 dudTlC4IyW7IeR9jEZjRTPUGRvK63k254Bee6d6lkpKCyPGrxzrH3cr40HuQUtaL6ldy XEA3KQsNqyEqrlh36sIHz/csRuGPediAfABOAeUnHpldTyU2gNI1/9PCry+ec+jy9lDF R24UOTOuLjSj6BA7Bd/v6rcfS7nnd9HrnbCOgrEwQyazbYjLEoJ02GnjWAvlr4XQ7ZoX UQgTnbQLdaJd8rYV+egqEfwSutUgBmK7TwexVBrBBJUv+ZFqCOy2nGUTx+mKz4hXuahJ JZzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QNqYVJSJQaKqgrs//XJVX+Bi7rBtMitLuSGPIbLMf+A=; b=kOtxYewCmFlcnud+/AeUBQk5K7nVnN7x7CmEg+otgJhyNrWTA9jkfbUXeJSVKUQXJw lD00kE3NK6t7E3XcFhC7LlPJlIhZ5MmvdMUH2YPOkyDHqGdHyBV4MfaU/W2wPki+oKIm lcHp6DVHGZk9sweKNhtVVVI8YUtiCZFA/Gv9N6PjIpFQmPwXZYWXKA+rbhjcKi1RjDGt C2Fg3sv+DFyrZF1nIktuADalXpDlingDWJyCPCfsx6gvapQ9ujERxSoAIhrTyk0/59KN uT9VTQHRHHWW9Evm/neTtWS0Z1R3et7uLOgrn2sQT8nAD4u+Jcb3MDKgGOwOK10Ke++E CGQg== X-Gm-Message-State: APjAAAXXQZUKl94Gu2XCa9fyCPkwF2pdOKeVpKb8KaXzt1f8Bq7xVNe2 5xxVbYvt5N3g7EeleyQrkjI= X-Received: by 2002:a63:36cc:: with SMTP id d195mr80467080pga.157.1564710457178; Thu, 01 Aug 2019 18:47:37 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id b30sm102489036pfr.117.2019.08.01.18.47.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 18:47:36 -0700 (PDT) From: Chuhong Yuan Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v2 08/10] sched: Replace strncmp with str_has_prefix Date: Fri, 2 Aug 2019 09:47:32 +0800 Message-Id: <20190802014732.9060-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Chuhong Yuan --- Changes in v2: - Revise the description. - Utilize str_has_prefix's return value to eliminate some hard codes. kernel/sched/debug.c | 5 +++-- kernel/sched/isolation.c | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index f7e4579e746c..43983ff325b7 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -102,10 +102,11 @@ static int sched_feat_set(char *cmp) { int i; int neg = 0; + size_t len; - if (strncmp(cmp, "NO_", 3) == 0) { + if ((len = str_has_prefix(cmp, "NO_"))) { 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..f528bb5996f4 100644 --- a/kernel/sched/isolation.c +++ b/kernel/sched/isolation.c @@ -141,16 +141,17 @@ __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; + if ((len = str_has_prefix(str, "nohz,"))) { + str += len; flags |= HK_FLAG_TICK; continue; } - if (!strncmp(str, "domain,", 7)) { - str += 7; + if ((len = str_has_prefix(str, "domain,"))) { + str += len; flags |= HK_FLAG_DOMAIN; continue; } -- 2.20.1