Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2696761ybh; Mon, 5 Aug 2019 05:24:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqRuh9YzLBJFynvjikPlshF7v5Y+tN4AZUO6ydDJa7+/1t3Ij8rtdEnceZ9TaR9BUN8Azl X-Received: by 2002:a62:187:: with SMTP id 129mr73404511pfb.128.1565007875284; Mon, 05 Aug 2019 05:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565007875; cv=none; d=google.com; s=arc-20160816; b=uah0mCqQIPmVrHbLlT5n7FeAv6uP4bQp3dInsyVoVlGXYqlQWRJbHI/iZkonsTcjKu l0A7XeuqR4tZusYR1a2BCRhvoN1PusIU0DNmF1GnVij6tkLS1E3HgXhsL7fwCZ6PGNaI J5PjZY86S3cSfQMCDtPFyhX2dF5j+WuPg7wjdpxcsKgwlThUWCCN7JUkBczp81J8QEvA oHbyp0gTwqUoyQVBXi61f7V+7bL9kwvN6FkhWrzFSA0Ed7jNN7mfmh/mTECqc1x11XJQ q4AaWfOicYh4m682EAHluxxRFRp9JjbgLrQ+avnoM1qBtQCm7YOWdNQ3qsckUAp+VKfi wv1Q== 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=dQHK9bxJCsNN8z/u4+8HH2PVzX7tOliDTN1dWwstt/w=; b=gLwDPOquOE5OldUbIkAmChxLSkZktIFFE8X88G2QJAOzsIymHuUwfXaQ5T5cNSk9ZJ 0hGXML/tr5JDm/slm0jADcweXjPc6aUiVljsuNzfEoEZLcavjvHPiQt1+Da+zgSweGDj wvoZJ3/smsU4YFzrDiIG4ypp/ebTZxJk1wohaeiCT4zHPyf6k8APsmsFaFomOeKPWXp1 bGPTeCB25JxiW8zQr7eyoaA8vVSA9DIm4FF+Ol8gQqc+ytVfR7y2zE2564MB1Tq5gpay /b8Y4cUKfzM2gEzJH0XnP4zC0X0rnPStiA0HSpTMbuRbD8TyBSN5vERznkLHgW7zg1d1 xzww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UvqYbWIz; 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 a190si44570594pgc.25.2019.08.05.05.24.18; Mon, 05 Aug 2019 05:24: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=UvqYbWIz; 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 S1728752AbfHEMXP (ORCPT + 99 others); Mon, 5 Aug 2019 08:23:15 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33431 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727259AbfHEMXP (ORCPT ); Mon, 5 Aug 2019 08:23:15 -0400 Received: by mail-pg1-f194.google.com with SMTP id n190so4526526pgn.0 for ; Mon, 05 Aug 2019 05:23:15 -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=dQHK9bxJCsNN8z/u4+8HH2PVzX7tOliDTN1dWwstt/w=; b=UvqYbWIzIdxTGctcAH9OWcDrGZ3nGG+JAaY1OXc+Hh6qVuSaLefdsDwufR1VFeL546 V7Glpvqqlw3OT3NTf9ySVk7X69hOHFX5xv6ckqXmZJ+0oJsx6uTlH0TnEK79hXTWZazg M28723sWxA3JcJUnfY+if/XbMUcZ3/ADrZ47PpvXhDBxdrS76FPz5Oz3Qv9WxRRBrmoT PZslDBhiwIWm44afQJ6j2ETkQVE3S9xYfOEeL7Jb1lAxuktCWVG+K3tKxbEKaklfwWB+ +MUecmSfpyYCY09HzF0ctW0zDjUSRPFgWEIq3icL1mdTdJ4xUnVDgDr2vXb2rJpLOdrd hkDQ== 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=dQHK9bxJCsNN8z/u4+8HH2PVzX7tOliDTN1dWwstt/w=; b=Rhq8L+0/8+zJVOin/6U5CAeJq/bUTVSgKEUxDC3MLNDn/3RXiWKfFjt+nJofd1ZlnV W0b2qiKuRDqTt8Lhoz2/DaQy6GS4ts+qW2igKycqc+FGrSqLimfO9Iu1+VDoGwwBujTu QfWNuLG0vlJgKIKvzCpM5lv8VNZoMHdPUTMsG96rxgADgVKAyhtyM5DVVz2YvCtjRqw4 ylIJX7hMidK4CmmAb5ObxfZ4lKCkrjFtqNCLe+uv/O2ZTt3BgweWg9OTxdEC5WHAxSA4 nUnFFoj9h37lDjKc8ozEX5BqxjV3/bl/qYuUoI0v4KQ5+wJ3ugeOVneZFt8IMjAPAg2U Vczg== X-Gm-Message-State: APjAAAVFztKfe3XXcLs4vtXKoy2TR0jjA8ZJT169Ks3cDPNSarM/YTNN W5aH943+3s/al8pJ50U2DT37V97fetw+FA== X-Received: by 2002:a63:e948:: with SMTP id q8mr131962527pgj.93.1565007794686; Mon, 05 Aug 2019 05:23:14 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id x24sm81599515pgl.84.2019.08.05.05.23.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 05:23:14 -0700 (PDT) From: Chuhong Yuan Cc: linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v3 5/8] reboot: Replace strncmp with str_has_prefix Date: Mon, 5 Aug 2019 20:23:07 +0800 Message-Id: <20190805122307.13095-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/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