Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2696366ybh; Mon, 5 Aug 2019 05:24:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2dmKwVxIF9pU3yyIOCBO24rom3bvcFbz57QaNTid+EaGqo7n/8IPJmkQLL3aYXvfE1Zb7 X-Received: by 2002:a17:90a:cb15:: with SMTP id z21mr18197577pjt.87.1565007843742; Mon, 05 Aug 2019 05:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565007843; cv=none; d=google.com; s=arc-20160816; b=Qr7PQAXIwTURx+cM+9//U31Ajvuhkh9jsirKbzQqmr6PD+ayn4GzdyK43Hok58wXVd Jj/wAMhOVIG0lpnMc2o6/hvn2U9CsWJWPjUlKxVerx/FRE54RNWYT9y6eqnHN5cUBEVq F79T3UdipDTWyvj8nc452abh9y01VS445DHtNeyIcfo4SfQwmzHoCnhT+/0xaDOlNF6o oZbh0+K231LzYXatNqYWByq8mpeeji9mjJmhWMaMMsPt+W19wyEL8dh5pxRHWndXNvTT Vxw1+C+e3FHvMPR24wyjEt0mJsU/MnJiE1ITk8d8h0i+AWiRNfe8wsK4Q4zf7BX9hCJD s1uQ== 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=ZnZJGZr/WPeKzWcVnuKXKMnqZkxEkSin124EXbUZO4g=; b=ZDtaCpJ44ayIeIjDlxTOfmri0XT79+mwbaB0xkcxBhHPq3tKu+Gq0orKv6OSXCNKf6 pNUcHhSR3zvI0XTwzGfET+eagiOBvfAHfv6KbONnmAymhOnSe4pKXZlvA4So/4NpG9C3 k4a0deQntYuVGqO6tOSI64QmXvYggGd6uyjO5DWqAIDq4NV2qb43VWtmeQjJQictv1iP 1LArBJ9HpLLIh9erB70XWT+ECI8MwXCLRjpnELQL8HaAUNcJQ2kaTHKMt2QnZZXiHFOH 2kkAZ1g6TZw0xEzzsXNWugFYPcDjdgGWggsAP9Szl1yf8fPbWusqXKVc732rPX4M2Ilz 4B5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YMZVytAp; 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.23.47; Mon, 05 Aug 2019 05:24:03 -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=YMZVytAp; 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 S1728717AbfHEMWy (ORCPT + 99 others); Mon, 5 Aug 2019 08:22:54 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37432 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727259AbfHEMWy (ORCPT ); Mon, 5 Aug 2019 08:22:54 -0400 Received: by mail-pg1-f196.google.com with SMTP id d1so6835845pgp.4; Mon, 05 Aug 2019 05:22:53 -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=ZnZJGZr/WPeKzWcVnuKXKMnqZkxEkSin124EXbUZO4g=; b=YMZVytApipzfRf/tfoqp0BMVYFmwPjqRNYChH3JThxyHrjHYuLpfNyQEX2O78uqhUi W/RvyEQhYxVak1D/Bg07x7JohNkuloEbuDOOEwOe9nFoBr/HGCjh8gafpmbS/JHPIsEm woT4LyUfMKl7D3LfuaS+L3xrKS4xwqVbyB4Sqi5vXyt+0FXzZzZip3OPnQZz7G+o9Hjg HGporvXaO5v53m18JncKk9X5jIKLFH9A6/rP9/uE8anO7a1j8XQMKygcubr9JI7JZrPO GLRJzYv5XovCufql9Rt1MZJ4huYKPH1C+p5Tylknt6p+CHRR8VHtjSUP6FNrxChvLgAy qe5w== 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=ZnZJGZr/WPeKzWcVnuKXKMnqZkxEkSin124EXbUZO4g=; b=KRsN0q7jFW0Jahd3zC5zwKq2NbBjBRoVrZYwXqVoIP8U0w/tOpv2/6osYmBbswedox 69LICmLtGjCGTvuiTkQubQC7zfegNjDmt4U7c+VRvuwUgxPNzuHfBjJmk+EoopG2D2I/ iryl5dB0JAY8zHuJbmGht6l+MOI7QvT/WjMFi8sC2IZXMkH1N075WApwVHS9t/q5GiUN 6brHxN1o9IN79BJx4uLhiQ89Xml35bgbhiIKNNfmMJQAvRr+IXr1p/zdPiE8TT4tVDzR CQmhSO+yuylYZhq32XosPSKqwkeesZkLr2k3Jk4rcObZ+GWMkf260cCPT0kNVpMLBI1C UHsQ== X-Gm-Message-State: APjAAAWpMIWJGrbx0qrlnjp1JwDV+4E2kzigo8pT+IoWtSM9zUHJQAUz CPw9EC8fGo6BX/22E8r1sY0= X-Received: by 2002:a63:8ac3:: with SMTP id y186mr135828216pgd.13.1565007773492; Mon, 05 Aug 2019 05:22:53 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id i15sm89514813pfd.160.2019.08.05.05.22.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 05:22:52 -0700 (PDT) From: Chuhong Yuan Cc: "Rafael J . Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v3 3/8] PM/sleep: Replace strncmp with str_has_prefix Date: Mon, 5 Aug 2019 20:22:44 +0800 Message-Id: <20190805122244.12986-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/power/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/power/main.c b/kernel/power/main.c index bdbd605c4215..5e5f64bb3a43 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -495,7 +495,7 @@ static suspend_state_t decode_state(const char *buf, size_t n) len = p ? p - buf : n; /* Check hibernation first. */ - if (len == 4 && !strncmp(buf, "disk", len)) + if (len == 4 && str_has_prefix(buf, "disk")) return PM_SUSPEND_MAX; #ifdef CONFIG_SUSPEND -- 2.20.1