Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp308712ybi; Thu, 1 Aug 2019 19:33:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSbYjrzjQJBzaG3QemU7aw2SPaOX0X6fQzy5NMgzTuB+DhnJ4x0ZcU8wn/mMN256dReqB6 X-Received: by 2002:a0c:afd5:: with SMTP id t21mr95350123qvc.105.1564713186496; Thu, 01 Aug 2019 19:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564713186; cv=none; d=google.com; s=arc-20160816; b=c8x5JDIEiwky+Vpsk4bOR47Ja1hX7ePeD1K1++TUt1sWQcc+E1ihZTf6twqLTG5r9y l+r7tq/e4jdBap62MDyqCTJM4G9m3O/gEBnKDVyS2wbPdPBqUCZLymGsSUv71s1sFJyM /rwYbK7Lz2nEKF8jNLPXNBAcElSJUTjr7GMBbOOI0bzv6dtQdRHAW/bd4WDQ0URknLoP y3BzmgSg26NioUj1p04uoRsnM45TZtO3C7DW1BPsktZ8BhhrWgRtgboNBCVVbQTYIpB6 w6jZiqzuC75l+RnRfPLEFSSRBbh+VOLUaxueKgqItvkKReat0NOYlnfOeMSoRENSeZkK 7UuQ== 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=lv/YL3fWYcrlgaCURXSs5Rp+POILoWLCMD+0ER71plA=; b=cfGLf/fEiNRl3EGcE6w4VtY/TXTHxlFGK0ekvi2RA/m3W9/pQlKZLK+UFT6HMxuhAk /eynF4y46mxxOVQhwfghqaBlJUMAJqTEQbdMw/c7BvZw+E+I41XciCKW83q/LRJ9Tggp /wOJlOPVPilsFNAi7xY8WHAgTeo5b+dCRs40R/BsMA2WKIrS5JQWzxv9uq7y+LvKMbTi RRD/9nImqSVni9xo4v8UiHWfTZdkywR1VjjKIsOXeKNw4sAvBeasEIV1Xx0e5+G6pNR1 SWscIdNgpFRnJjUIMlRbh8wZs8yp2y2+FEh1QkhlFuhXERYilO/ZGZ0g4fF2XMjqcDKR HyJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=cpNcly7d; 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 m139si2026105qke.257.2019.08.01.19.32.53; Thu, 01 Aug 2019 19:33:06 -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=cpNcly7d; 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 S2388880AbfHBBrb (ORCPT + 99 others); Thu, 1 Aug 2019 21:47:31 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33304 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727630AbfHBBra (ORCPT ); Thu, 1 Aug 2019 21:47:30 -0400 Received: by mail-pl1-f194.google.com with SMTP id c14so32903704plo.0 for ; Thu, 01 Aug 2019 18:47:29 -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=lv/YL3fWYcrlgaCURXSs5Rp+POILoWLCMD+0ER71plA=; b=cpNcly7dwYKojxb0/zRsMqN8tD12gUNrsf4a79e+cJmqtCUxlL+RTTP+at3X8UzzBD tfsxe/GgZeLnUs+DRtoE2B+UWzkE8KL5/Sk1peURCN1D5cd7t752Io3YSx2p4DPH3R2k zIl31oIxigIjwk5kRhodoSmHHKVGGltO0+I4dwaVcJIDAmZ8MB4FxM200YFlJarf7ClJ nvdhYZctEp3drMM0UObGyzHtO1w/UTUuyuS361BDn+Ip7hx430ycy/49IXwp47wV+yxB qWLUOGSY18ugMfLZE5C1TsWf2d9p06TksH+s1qt02X9r0GqlrY7Ry0f41obqQAzSkis2 81PQ== 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=lv/YL3fWYcrlgaCURXSs5Rp+POILoWLCMD+0ER71plA=; b=SDMz8OoiKbYMjLM2CbTkmBDbbtE6knj6E8Md2XSIPYrNm1H6sCvgdrT8LAtstmwqwA 7LPwdS9el2m5KxNfwqhqIVCEPkLodS2UBDROlCwC1biH9a3jQh8Yvsby5Do/GMSKjb4F Nlo8d/cUA/1EKVPmRQssCpA+mmPQ7eWJROn/kzZQVHb1brZI0UOpEOWy7bRM6WCOS7oF qRg3+7bjvyT1AwdP4+bkxBloY7M5ck2M3Xr76bgK89SmebDzVEzKmNX7Xxza1lpm0+h9 3UvectdmNSOPwzKlPO4aTZpRspsCK1zu2etgnaJR7S5yf6vG6h0k81VqMPbVqGFxE1wY xcBQ== X-Gm-Message-State: APjAAAWyVwI5ejLhzUO1CqXbuh3mLaTD3GOoqzaBBA5Tt26nFs8jiLgP AD+KIMQXOcLNw1Qn8XgDgwwPnc7YKffgAw== X-Received: by 2002:a17:902:7d8b:: with SMTP id a11mr75073884plm.306.1564710449352; Thu, 01 Aug 2019 18:47:29 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id i124sm133657768pfe.61.2019.08.01.18.47.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 18:47:28 -0700 (PDT) From: Chuhong Yuan Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v2 07/10] reboot: Replace strncmp with str_has_prefix Date: Fri, 2 Aug 2019 09:47:25 +0800 Message-Id: <20190802014725.9006-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/reboot.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/reboot.c b/kernel/reboot.c index c4d472b7f1b4..addb52391177 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -520,6 +520,8 @@ EXPORT_SYMBOL_GPL(orderly_reboot); static int __init reboot_setup(char *str) { + size_t len; + for (;;) { enum reboot_mode *mode; @@ -530,9 +532,9 @@ static int __init reboot_setup(char *str) */ reboot_default = 0; - if (!strncmp(str, "panic_", 6)) { + if ((len = str_has_prefix(str, "panic_"))) { mode = &panic_reboot_mode; - str += 6; + str += len; } else { mode = &reboot_mode; } -- 2.20.1