Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2697366ybh; Mon, 5 Aug 2019 05:25:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwg7tS1AnM4tqZHV0iVdetGektLkFVeERdjVWiBw1XYG6jR+lgSb6elEfmOWKdEhqSd2NFE X-Received: by 2002:a17:902:28c9:: with SMTP id f67mr105485411plb.19.1565007916439; Mon, 05 Aug 2019 05:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565007916; cv=none; d=google.com; s=arc-20160816; b=NN0+Plyqo/tfZ8m8P1H2OwTlul7il4qB5Uoq8f1ow6ryr7+v+FdaMpgC+qBO135YVv L39hBt4+oM5a8k+B1j6a7ANqMjY+iKOVSQ1SfxNVnr+iTbVlnamHpGmLqk2WEYbxN5WW bYyRJz9PcejzT0Zk2wyanR4EMIwE2WMeajKBCTDG5GWIyoY/KqitmU3ryRVdkQnqOnMY 0rhBs9ft5/4JxfgXffTYTrRloyiiOT/HQ5nUnr09fj8n6lDUXf997lUZAuUISuVTBdLr QUnvG4USKh/ShUKvHMYbFQxEzBnLKAHWZ9BGGsTOP/Y41f80vk/q74tXt0hs6c3LGEDe VtLg== 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=kvNIIvyr1HZdHxI3+dMG0XwOSbyqFwP/GOGTSjFs/B4=; b=TfsotKKeY75yXdSGaLK+l8eFBKRSuZ3A/mKU7KzaeCvOe/+6+/OyCnLno4u4p4IQeU lSaOv9YJP/U3invLO/IQZBrgj6k0VLzCv5YBPLmYqo0Qz777M9D+r5bhTgxMWg4haXmZ SMoANB5/bmX2se97vgnJdb2fv/43rwy9ksslNTcTWtsMVbjmPE4QgKQvdG1ZUz7V5zcb xN6HvS1SL78FGZcXwnufOdRKVE/XA9zQHnv30eQe7jwJPV9AU8cznXs6N6LWnqI/+6+P 49lL7jFlPOoEChXsY59ehFB3OSHmLfPXRTXuuwiwfi6qzQEMIQCAWAvlaiAJNexTkjIm y35g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=HOpVCdl6; 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 z72si45931660pgd.34.2019.08.05.05.25.00; Mon, 05 Aug 2019 05:25:16 -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=HOpVCdl6; 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 S1728783AbfHEMYF (ORCPT + 99 others); Mon, 5 Aug 2019 08:24:05 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41102 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727259AbfHEMYF (ORCPT ); Mon, 5 Aug 2019 08:24:05 -0400 Received: by mail-pf1-f193.google.com with SMTP id m30so39579862pff.8 for ; Mon, 05 Aug 2019 05:24:04 -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=kvNIIvyr1HZdHxI3+dMG0XwOSbyqFwP/GOGTSjFs/B4=; b=HOpVCdl6QfscvZumVVZBmYBvn6ARHLLUFP7R98TQku3GrqyU3dAAzxvL4ijBStcoYk 5czJxxpew3ycKWH1++HGfmppdrYO8RRb+byVydL4dmofr8CJVT757lfwXgoVto+hfL0l SZe5/k9NQeAfjH8H6FURerps8wvx5EA2tf/k8xWEuLFjE3+JefcVrQO+hbp9+UnK461e fUE44nXWttbw+6JcKJFWobaWwKw/YEzvillOo7J6I8dGs/mWPN/m4ztDWuDQ/vqqzYjw W7ucjpYPNrNDka+ZOGUZFtI07XhNjRBT9R9h09OgcisRSln6FCt13t9ekUrKPf/hBqpM XXkg== 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=kvNIIvyr1HZdHxI3+dMG0XwOSbyqFwP/GOGTSjFs/B4=; b=t9wSFKwqMZWQr9J/5z+weKAFJYa0nQboTOsdaBwYt3LnTqvDtPa6HTPgcrlKzQfz83 QQ93dLFMnVWAju7prQMNLzxUqfDyNrtPcn66cioF3UsPcZE+D/yS5MMqdzulzvCssbLR N1WFC0iYSNtcYoGXiLjubgnk4enxACYUFG2ahoWX9ftVXa69rPaH2/MgELXpdp9JHpEd h5bx/ClFnjFy6APfZ31vWStjcBKwHAgog55LszGeul569QkbmD7MdWREG18OwcQaOou8 SqYedMQkGpB7pphNitGxnArF3GOqaNXrM++vIV7ww2l1hJ1P8I1YOJKIKCBeMThfHvCj D6LQ== X-Gm-Message-State: APjAAAWI4nl/aYDxxDmCTaiK0aHzpKjxhVCX0E/3g16Lz2cc14aIvgyU 811ZGBsVlJoGaR06IV1fl12j4W/ImEy/WA== X-Received: by 2002:a17:90a:b104:: with SMTP id z4mr18045000pjq.102.1565007844428; Mon, 05 Aug 2019 05:24:04 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id s20sm95447299pfe.169.2019.08.05.05.24.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 05:24:03 -0700 (PDT) From: Chuhong Yuan Cc: linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v3 8/8] watchdog: Replace strncmp with str_has_prefix Date: Mon, 5 Aug 2019 20:23:57 +0800 Message-Id: <20190805122357.13262-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/watchdog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/watchdog.c b/kernel/watchdog.c index 7f9e7b9306fe..ac7a4b5f856e 100644 --- a/kernel/watchdog.c +++ b/kernel/watchdog.c @@ -70,13 +70,13 @@ void __init hardlockup_detector_disable(void) static int __init hardlockup_panic_setup(char *str) { - if (!strncmp(str, "panic", 5)) + if (str_has_prefix(str, "panic")) hardlockup_panic = 1; - else if (!strncmp(str, "nopanic", 7)) + else if (str_has_prefix(str, "nopanic")) hardlockup_panic = 0; - else if (!strncmp(str, "0", 1)) + else if (str_has_prefix(str, "0")) nmi_watchdog_user_enabled = 0; - else if (!strncmp(str, "1", 1)) + else if (str_has_prefix(str, "1")) nmi_watchdog_user_enabled = 1; return 1; } -- 2.20.1