Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp678692ybh; Sat, 3 Aug 2019 07:33:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0cJe3ughTg7da1Xts9SquJqt/tUXT4x7fGSmUELFXAUao2HZqo/xD4zd80NjIILrB3jLN X-Received: by 2002:a17:902:124:: with SMTP id 33mr139355067plb.145.1564842805126; Sat, 03 Aug 2019 07:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564842805; cv=none; d=google.com; s=arc-20160816; b=S4xqxchggoOCiLDUll6lelIkwuWRSo5rFNj29M8p5wEI6HhRRfl9JXToKooBZDmFWf vKxIiid/KK7NaSkv8/pidINrYjbaQUWbeV8/1H8VAUxwsXgHdCaFWkXFA/OEM6VuK3i7 d32asMQuIlyHd15BES//vZBQPRhkCItlnHz5YK4cURsiY5+Y3ZQr9Dp/U8O2ikup6FPB 3HIHg2TUQV9rRMrz7wjChxbRJDrWV9kCfJjS4Ej3v/LHjgwIe9bK4kHyr32kisxZK2O2 bm+l9JUwr70/xIxuk6d/8Doj62pvvBdJPgMBjCOiY9CBP4lZNimns2Z/zoI5+bQZGayi 3JHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=u/6xSIRYHiOP85ntjseSZQgtsjWb+fEA7f5+m0DuZOs=; b=Ds0uOY121UUP4yGWMCbaqYnDPOGFseyjwrYgrUo6ViBhBrxTddZiNG53kbFfbr5H4p OnFIkf/rN3y2BGaspsQCVEJGNCK+UHB3roGXEP+OKjnXj9QpDnLcNq2tqWMvBC6Xb+q/ TbOT7t2iGlz2+ez0rCK/YqlSkfmJb3ZEJgs0py+aJN9OPfWipWjRzNQ+y9zhkk0WZ6ru iWGy37HUc4WKI4U35M4iowK3Vfa3TPA0slRm7aquS0G1tuCUXKW8pEeaRaV6r9+S8TJH w5OIzPGIi5Da5XO1ZLIlSVa0xlm00iYA8vqgkuOj2k3a1FdpAxIbAOA3+QnR2EE5RlbT Th0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Eu8Q9a98; 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=pass (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 a25si41633580pfk.201.2019.08.03.07.33.10; Sat, 03 Aug 2019 07:33:25 -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=pass header.i=@gmail.com header.s=20161025 header.b=Eu8Q9a98; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731256AbfHBPV1 (ORCPT + 99 others); Fri, 2 Aug 2019 11:21:27 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:38179 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727198AbfHBPV1 (ORCPT ); Fri, 2 Aug 2019 11:21:27 -0400 Received: by mail-ed1-f65.google.com with SMTP id r12so37918821edo.5; Fri, 02 Aug 2019 08:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=u/6xSIRYHiOP85ntjseSZQgtsjWb+fEA7f5+m0DuZOs=; b=Eu8Q9a98dbycsbHrjw5S2fpv5HWJJvMYh368ryAYZgHoUjo2Z2fD1TXsG/RmsM9KzN pxACT1HmAvWqBnrsjrCHaV29OWB8+z8mOF7LDEwG84CfrctxqmN2DDxoNmnvXRKzfr0f gdZd99XWAUVenMrtkx8XFjFZlTwgdwgVA88+XiQ/dnwYQM1gnyUtO3qWrxyu6UZMGAqr 5FdLvKYXo+ZKLpqZ6NBEvzdo/f4CYuHHaGITr71dYkzvlfXJ7cqAWQp4D9+d8g44nW4R NWhYRm15UuTNqpvnjSwCCFPh8iUCsMHe2hGJmgD/AvseERpi+KBAyXQSfqPSM5fRxH7i mYZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=u/6xSIRYHiOP85ntjseSZQgtsjWb+fEA7f5+m0DuZOs=; b=f0VWoMl1eLsBr3IlINFB35jTSQhWj8vSk/RgGCIcDxkc7217W+CJFDbp5twhsCB3OK 9PlIOmEQQpMGq1GdrmdgIZKcCTBTMORFf7zslHymrHyZveaOKwU4Lgnhlh86p4mWO5d2 O9EuHWoljKfC5ETO/HiinYd67GmtNLjQQAG2WxxaOMSATv4u1d+eHxaU2iO1urUhF7rT vbjvhfH2g1DZ3m0aD9CSmYI5lhDlr4t1BwhNU13HZcXKZEnEbihxL+ynUicdgfwRORo7 xZVw1/3XAcAGsCcz7C09t56hCvS6b97+fSDcOnX1AsMM2EMmcMH4igYhumeDorHYi9Pl e8SA== X-Gm-Message-State: APjAAAU9laJ+G6UpZj9fELyZSgZhJIJ6CnwsOXT5XEb+DuZao1thCWuG C9WsQEW6OQkOFDcM2v2j4udogYILEBNZk3ZhlU42IdzsGCo= X-Received: by 2002:a17:906:7cd6:: with SMTP id h22mr12851541ejp.254.1564759285374; Fri, 02 Aug 2019 08:21:25 -0700 (PDT) MIME-Version: 1.0 References: <20190802062537.11510-1-hslester96@gmail.com> <20190802073858.19a86f82@lwn.net> In-Reply-To: <20190802073858.19a86f82@lwn.net> From: Chuhong Yuan Date: Fri, 2 Aug 2019 23:21:14 +0800 Message-ID: Subject: Re: [PATCH] Documentation/checkpatch: Prefer str_has_prefix over strncmp To: Jonathan Corbet Cc: Andy Whitcroft , Joe Perches , linux-doc@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jonathan Corbet =E4=BA=8E2019=E5=B9=B48=E6=9C=882=E6=97=A5= =E5=91=A8=E4=BA=94 =E4=B8=8B=E5=8D=889:38=E5=86=99=E9=81=93=EF=BC=9A > > On Fri, 2 Aug 2019 14:25:37 +0800 > Chuhong Yuan wrote: > > > Add strncmp() to Documentation/process/deprecated.rst since > > using strncmp() to check whether a string starts with a > > prefix is error-prone. > > The safe replacement is str_has_prefix(). > > Is that the *only* use of strncmp()? This is not the only use of strncmp(). Maybe add a case description like strncpy() is more precise? For example, "strncmp() on string prefix". > > > Also add check to the newly introduced deprecated_string_apis > > in checkpatch.pl. > > > > This patch depends on patch: > > "Documentation/checkpatch: Prefer stracpy/strscpy over > > strcpy/strlcpy/strncpy." > > > > Signed-off-by: Chuhong Yuan > > --- > > Documentation/process/deprecated.rst | 8 ++++++++ > > scripts/checkpatch.pl | 1 + > > 2 files changed, 9 insertions(+) > > > > diff --git a/Documentation/process/deprecated.rst b/Documentation/proce= ss/deprecated.rst > > index 56280e108d5a..22d3f0dbcf61 100644 > > --- a/Documentation/process/deprecated.rst > > +++ b/Documentation/process/deprecated.rst > > @@ -109,6 +109,14 @@ the given limit of bytes to copy. This is ineffici= ent and can lead to > > linear read overflows if a source string is not NUL-terminated. The > > safe replacement is stracpy() or strscpy(). > > > > +strncmp() > > +--------- > > +:c:func:`strncmp` is often used to test if a string starts with a pref= ix > > Please don't use :c:func: anymore; just say strncmp() and the right thing= s > will happen. > I will revise this in the next version. Regards, Chuhong > Thanks, > > jon