From patchwork Fri Aug 9 07:10:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuhong Yuan X-Patchwork-Id: 11085513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72E1A746 for ; Fri, 9 Aug 2019 07:10:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EBD428C37 for ; Fri, 9 Aug 2019 07:10:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 531B728C3A; Fri, 9 Aug 2019 07:10:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D49B28C37 for ; Fri, 9 Aug 2019 07:10:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405742AbfHIHK3 (ORCPT ); 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-Google-Smtp-Source: APXvYqwoxMyVhTYXNckZ8XJ4rP4tbgD7QG8BKGKz2vfkXe00sq5sM/L1h8plQl5Sn0hdxRO24258Uw== 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 To: unlisted-recipients:; (no To-header on input) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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