Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2696940ybh; Mon, 5 Aug 2019 05:24:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWdFr+GE2ztho1QXA3ocyuxRcuRYnsRoryifdx/OCjl08R2TtcVuuwBVF3iAUqcEzWQL7B X-Received: by 2002:a63:550d:: with SMTP id j13mr73896906pgb.173.1565007887069; Mon, 05 Aug 2019 05:24:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565007887; cv=none; d=google.com; s=arc-20160816; b=fcq3DtipG9C8ui7r/vC3IfiI06Ppgr8dpIv9IBjk5U7ArJiUMuwIcmfUFLnwJcSfSH DLBR/VTS/DjnZ8lccDVRbIgYf0JPtuHXtjfnxkFEHZWtVZeQI3Ps9IUM3WMUrTcygHYT Vy8luTe6omS/73+9Mykm0VBHh3nedMpl05oOJ+ttZovwq++hmdm4POhpsH5W4Xod9VwE 6APk9VT5sd49ukBQL1SqcPnHWFftnp/HxnnKPzVwX8DuhvNrb5398xKO5HjbOcr8HpVs D7t0VEJtqPn4Xj7/NoM/v+1fK0yaz7ju6hi/Vc9z3YOYpRjULcsZFnUm1EYiKaY+KhwO UtUg== 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=KaGTdYqsvTF4u3tp0xDk/NEAitZQsW1ch/nrQc3hayg=; b=mb6k4C9+aRsayqVhy/6INZ6BsuBP7TUG3j9DRHAJGmCyb80n/DJUtR6jnEz+3NgFee 58FJ8ojiQZx/CjAFVDOSClJfRFd47tjF535wXfSAU/zKi/lTUKDGYV7o7kWGF0Dmb+Bg uciWzO2yDuJjjUBHebGVHja1ulL649Hhal+uh2O5P/JqgIkfbQTymGkTEoGx6YJxB35X bqImMOCWlf6gOdTWxcsvEU+VCZI1Rhxp/FOM4/sC468S1r1Aeav+yY3NbBzd74xNpU8y 2WaFXnpxlcmJG6vmGocg6M5pQHnztJohAEU9j7f5Fw9YLcUjsWKqnR7qLvlx6POzboNv OvMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="Yf3Uh6I/"; 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 h5si42077692pls.280.2019.08.05.05.24.32; Mon, 05 Aug 2019 05:24:47 -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="Yf3Uh6I/"; 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 S1728770AbfHEMX0 (ORCPT + 99 others); Mon, 5 Aug 2019 08:23:26 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:39059 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727259AbfHEMXZ (ORCPT ); Mon, 5 Aug 2019 08:23:25 -0400 Received: by mail-pg1-f195.google.com with SMTP id u17so39655959pgi.6 for ; Mon, 05 Aug 2019 05:23:25 -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=KaGTdYqsvTF4u3tp0xDk/NEAitZQsW1ch/nrQc3hayg=; b=Yf3Uh6I/HpVtHSBJtybk4rp5TAZTszkCZv4QGefr2HcKlVQ0ggboBU5dY7i2i+thAC FdI73/lMsUaH5Jb5aryq2vpoQy8kFJ1ZYtA3BC+kqNs1cjwHzyOMBp4Bra4SsLqX5Vos C5K+6FJw4UIy0CUE+v6X4wYckOHiWskz4s9CoVUKGVypo/b75VLuiJMUT1s5lt8P34dX xQiK4m8tUIQLyLvxuPY0PN2fAoS/ScyjbHb+0Q+mXRjDcWjvHRNLR8aBAX7lLasrz1yJ JsO/bFUpKiQxUoNG5Jn6wBrMK4Esr8Y1Bzau5KvOnUOEBdaV7xho3H1VzIovCWpjm4/H HkVg== 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=KaGTdYqsvTF4u3tp0xDk/NEAitZQsW1ch/nrQc3hayg=; b=Gzjp8jnCFP/tdXt5wQSh76tqTTfd7uDgG7YfeghN+3TYXy9jULHEKApX+92PGkbKzl Zj3FqMG1uQJL2i712HnzZd2yUAfAg+k5Up/hwH4L3I6Z+++B82JKpqAH8UKAc4H8ALUS FlEasU6/QSHsok+2806zG/1o0p19XRaJrHFtqD6/i0kobBKLUSI9G//xGNi4Pfj6NZVR WTAeGCUv1UiT0yzpdt5VVwakqxQi46oVWVwX6pFI46zULewgkTAyk1sDBHcDG61jAIGH wP0jrjM/5S6sJthcYaBNu5r3jWzihHZXlDcFqaLfZT238TvNepXazFYGL/ydlkuy3qcK o7Nw== X-Gm-Message-State: APjAAAXRaNsQijxiYNrPYhx+Qnd6+q05Nr5cQQhKf8hptUIdd7cwclMZ RdCPw7H4u2lkeQ5dTYcugectUQG+NlSXYA== X-Received: by 2002:a62:2ccc:: with SMTP id s195mr72322673pfs.256.1565007805148; Mon, 05 Aug 2019 05:23:25 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id s6sm125102224pfs.122.2019.08.05.05.23.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 05:23:24 -0700 (PDT) From: Chuhong Yuan Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v3 6/8] sched: Replace strncmp with str_has_prefix Date: Mon, 5 Aug 2019 20:23:18 +0800 Message-Id: <20190805122318.13149-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 to make code better. Signed-off-by: Chuhong Yuan --- Changes in v3: - Revise the description. 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