Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp7822832ybh; Fri, 9 Aug 2019 00:11:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMNNwlvWoASKEJyi/mLTizQFXD9b4m3fLAqNWz3C2pVen4gPODqpQF7o/jr0Wy+VeUT4un X-Received: by 2002:a63:2bd2:: with SMTP id r201mr15914781pgr.193.1565334699771; Fri, 09 Aug 2019 00:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565334699; cv=none; d=google.com; s=arc-20160816; b=qtggYLkglrUIog+49bPB6os1rAqMnJE2Gdriv5pxJ1EMMlWgsg12KNyPPs8mZ9Tg60 AjM/uFEOrjLAD+TOyz5ZaqOfaQ6jjS9VawZlSuRqNZJoBNAGlLQ2IOoDroCKbvnBVwIO 97KhRu4AJJlDqkvc+Am6M+guDDDBATWfpR8uG8vB9OptMaMjjPCKNOmRmBIWSULuWbth hOSI55RiUcy2mCEt+9hnJ1XZIbf8lcDuVpZixp8Q5bGSRUqq+HYzBQkqhRqwD2j/o5R8 uRRvUQctVmqp5h/P6QD8yFpri7LDbTqruxpU9wXYtIhmjiK1sUBf/5m9T08ZBHUAgctu Pr+A== 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=+d5t4lkL11qOJSaV7yGOJ7opndkU1RYl3l6/bnKTaps=; b=Tsw8oMz6HVzT6yhpcATbhUgNFbooHM5K57+WIYoHSI8/0sDej6sIh6vE2sxz0OC3O+ MwQ/5IvL/kdvrjwNEHJqXfeZH4IotLuL/9rnbxZIizGuFEwxdaS7vr5TcpaN0yv6nE+k 4up/CChq3yUbg6r4SNDBy1/llqwAaWp4pseikmw3qBMQnbaiYqdynahRbmE1elKZLHlV 7ojybVNoxtP5SFJvzc97PpCDvyqppizDdMsulf3VTXNIg5LsOzWCmSXGkrgx947QW+3m Q487c5EobgvwqY4YGhiVOJrtHAzyDVHn7R4C4JXYueSKHt7PhxFYnqkvCZcfNhdYUJuj Xf0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=qH5p+7Ef; 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 g2si48383115plp.1.2019.08.09.00.11.24; Fri, 09 Aug 2019 00:11:39 -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=qH5p+7Ef; 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 S2405750AbfHIHK3 (ORCPT + 99 others); Fri, 9 Aug 2019 03:10:29 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44640 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405700AbfHIHK3 (ORCPT ); Fri, 9 Aug 2019 03:10:29 -0400 Received: by mail-pf1-f194.google.com with SMTP id t16so45513437pfe.11; Fri, 09 Aug 2019 00:10:28 -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=+d5t4lkL11qOJSaV7yGOJ7opndkU1RYl3l6/bnKTaps=; b=qH5p+7EfZpTvCWXaJf2rQvToIJyY8fGExGFmXTWpW5LIVKzGfBWCRmwMR2P8Fe5PtD A1ROzvUb5xtCtgIZWZMI47N96t7XZcSxPnzPuHEVHc9/yGElAVR/sJiKQ7YkNIwNokSe mcCFjFEnhiqVQkmFo29/MsJhaZlYT7Yq/FWGaMcyaCG0x4VJuNH9SCq+4WZufLWeCTwG x7NPB7A6zKoNu4FuPEZMLmrzOd3VHnO8mUk243wLLyG9m0333TNM0Xr9h2Ff2dXFnikw jMHp+qpVA8fYv38qUZN/vio71FYepuG48RrF+sxDKTkLBHO9qosk19mbNxj4JPar7Y6b N6VA== 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=+d5t4lkL11qOJSaV7yGOJ7opndkU1RYl3l6/bnKTaps=; b=W6TyL1vBBjHDGBwDtmhhNaj39r2oemrWzuCMGx28H7WxmIR43Uuu3pTgR1p9De065w ppOHPkNt9T57DTIkBa/AtB31ZOExE8WyGzi0+BCkTQLY1Qo74XMbN1zeLN9j3cK0vKl+ eBPSRD3r7/UC4U3u16ssnxJzOb3tdhPFBzAt7x85e/2zKfIdywLVEJLVCrW6TL1Q7LmM YtaoLQ+czjKU0Ru4usKjNgOc8QFjSOw15Wc+guQdHxq+c05sKe4kCfn9XRW2SO3Gl+9w XTMAz/0sdVqc0P7NJr3uvCiGxyUBtFVox77ELhsiVmrITK+GYnQUvJDKfATwLbwlQh/S DIsw== X-Gm-Message-State: APjAAAWTPCQrz+a6ItXaSoFX2pKbmqjC9IcMfQbDUTbrM7imvTlbpi7w T1fYeBimemHLJfDkVUnHFeU= X-Received: by 2002:a65:44cc:: with SMTP id g12mr15990426pgs.409.1565334628486; Fri, 09 Aug 2019 00:10:28 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id x1sm514293pfj.182.2019.08.09.00.10.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 09 Aug 2019 00:10:27 -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 v4 3/8] PM/sleep: Replace strncmp with str_has_prefix Date: Fri, 9 Aug 2019 15:10:23 +0800 Message-Id: <20190809071023.17224-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 --- 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