Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp308740ybi; Thu, 1 Aug 2019 19:33:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBCWaYO//wE0/VFkC6bkzBdylVMoRC5qmYwJKi4xHcdnTkOkchWMDjzLojfe5Dao9yBsxD X-Received: by 2002:a17:902:2808:: with SMTP id e8mr123950735plb.317.1564713188099; Thu, 01 Aug 2019 19:33:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564713188; cv=none; d=google.com; s=arc-20160816; b=Nu4uj/rChIJU5DXEG4mtFeUwzQk3qfxNmwKWH8jZUpph2ZhtGviSebrxMMdf+CLZpE qtrU/3fUCtDBctNEXEtilpQDiUGTOx9zAYYaiZGfE+Q1Yc01d+n5vKuDDV9c0sc7fEmz YaN5noSebWspR5xUfX2v4z6OmKGDkNf5I096j2kyLMUrcUbBVoGsIHyMR6FBD4clS833 Qhh7fVz0wGvxHXlwfBNCgYWnTMlNx2u9HA1DyIyekVJRRMsAtji9HtjQpORddYEUsouc VA3nE1vKl6YFKYlAuPftFa3uDEWvhCMsOArNVRTZsGs/x2KpCYWECWuw18Lyj9k1URTC w/dA== 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=ONZiznhobYR+f5xk60p2BwYZtKTcGSGm/L1sszvHa2c=; b=hjJaBSzIKhtA9riz6Bvy2i3DYx4iwqK4f6l4ihsSfAUejB9sEG1LKjZQffUzp8VBZI 839RjFmqegkvj/cDtKDpIki83l/GR9eT2z1jesjCqlg4yQ1IoEiMLuts6IDMQRRX0wzV vfMw8sSWyTtpxTbtmLZ/QU+ZgJ2QrpijSL4zyhOHoKobpm9XwSqYfobMZoRI3HJQWouD G3o9EeqMBgLkMO42kwdhgmCwT7mwt5G4EhIK+gVrvl++5oekYDz02UE8BMR4YPEWq6KA 7Oy4KHXs96m0M0ae3WpvbM5Ch8NTrNuqOpIVIGoaBZtlU7McwrxU/IiOYdK86hcip5Wv A89w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TRwPM+KQ; 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 l6si12108926pgp.391.2019.08.01.19.32.53; Thu, 01 Aug 2019 19:33:08 -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=TRwPM+KQ; 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 S2388838AbfHBBrS (ORCPT + 99 others); Thu, 1 Aug 2019 21:47:18 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:35333 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728937AbfHBBrR (ORCPT ); Thu, 1 Aug 2019 21:47:17 -0400 Received: by mail-pl1-f196.google.com with SMTP id w24so32979849plp.2; Thu, 01 Aug 2019 18:47:17 -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=ONZiznhobYR+f5xk60p2BwYZtKTcGSGm/L1sszvHa2c=; b=TRwPM+KQM9hE3nz0Nhu2Q2geO1Z6+GeIrltAOcRiZRZ16xzPajdJ36LhQc83SUVEjL p3Qm2WOq7cixmqukHdJfVdBXu9+iZpFzOkelpo6ZWhzEdxgcTw/AeIDnUl+bpIWTqsyF Mk3nm1PEAEGLiS2tYKhUNLRIh0PRuxQJWiH+9YFsLLhsPcxlbDfM4393ttL/0MMOs62o xe/CiGHP+hY30hmPCgYYEszh9WfFdudsng0ElgrcU7tC24OHu57HwsxVV/E9klgA+nm1 bDysvl1J+lkbrb8wlwMI2Dpy2++wWc6u7242Y3xjYvzCSJO/gpYKm6qo3g2ED3LvVTzp uq3w== 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=ONZiznhobYR+f5xk60p2BwYZtKTcGSGm/L1sszvHa2c=; b=MT0Qb4Y4AEskMbnxnea/pGXtjEDNtGDXjxMAXqlRw87FU4qgQMJMHtNQlWIr3R9M+E 6PXtXQT1wraMlWnspKLbyOrbdwAXFAy7bHFBIGX4pnQxDqnSKLj4b0abpD1+PISE3qFY Zot5ZQQh/BvBomshS4sZ0TOLi/GtLmCHTXWYYf4B7QeBa/1/frDpm6oIThCJVvFo8G6w HxyfhwOyU3DUqWPcAS5tPOstzDqK6h6AePJ68C6iHqQodF49+OrGn4eavudE/tp+VKeA hTa03L59E1pylE6FqWphkFrEwsVspxhjkJgHeLQyc0cInSLJMksp7GEKav9E2YnEGrmb f4kg== X-Gm-Message-State: APjAAAW7GfSN2G83GgJz4bfZ75rwoSqFOG38E9hhiznVHpXYpW/tlbT2 GF95lpvbI01lH+FCcgF2H6Q++xzHM7xGAg== X-Received: by 2002:a17:902:2ae7:: with SMTP id j94mr128750572plb.270.1564710437181; Thu, 01 Aug 2019 18:47:17 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id b37sm11498552pjc.15.2019.08.01.18.47.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 01 Aug 2019 18:47:16 -0700 (PDT) From: Chuhong Yuan Cc: "Rafael J . Wysocki" , Pavel Machek , Len Brown , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH v2 05/10] PM / sleep: Replace strncmp with str_has_prefix Date: Fri, 2 Aug 2019 09:47:11 +0800 Message-Id: <20190802014711.8898-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. 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