Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp764229rdh; Thu, 26 Oct 2023 15:25:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGv8vncykZIX5orrYZlF4ebbLm+YbJeNH+GapEB1s0fjUegs0BDaDO/Zqjonr8lw9z5TwsK X-Received: by 2002:a81:4316:0:b0:5a7:bcac:7d3 with SMTP id q22-20020a814316000000b005a7bcac07d3mr868736ywa.9.1698359126073; Thu, 26 Oct 2023 15:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698359126; cv=none; d=google.com; s=arc-20160816; b=JZlzeLgetQmGJRW29cyns6cLmCtbP/bldBXM+QzptsLCDCdcASEoWV4lqM8bmZFPy6 LgBZDugYy6Vu+5LdnlgYu8rrLwxRkPb4d8AUSOxpw1T4Df99WuRCGk6oZe6E4Yzd2wJP UTRTWJbyau0hAErXZ0romDm/I0jRSsO4UjAscy7gaKN7J1WNlyxJaHqpnnkINLd7wNng ewDut3ehZs/PDmDi16EdwCf3Ueb/lVqSteiHcr2YbUgH37arO5072Bv5EXz8aKxmjX90 S0SdGK3opJjxe/Lf3kwwOiePzylxND4ArYc9KzB97c5KIu/tGfU+QxLUb/2WhzCANI1w N+oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=YeD8ayoKI+cNQ+dfy3v3WycX2QANJHfshgC8v+Kwnbw=; fh=E+O6lB+WksfCgT0P8JRY9LGebRJ8IEjJgrBLhq6dx78=; b=b4gfME6eVu7D7g2I0BMijGuhnr/GrmcLg5PBChf0l3lc6qzBZix82pN27ybCUWoSeW Zfe3spFMtTUC8sV0yU+C+FuxcEGkGFdQiAWVGNvyb4nP2QhnHdY0yUpsC19kUyZwaEzQ CWSDzs4tGM+ZbXM4xyrgv4cKSqghx7k7Z+eUR80SZDXwNlKpK/RDDJo62FfHhtROV6Dp VYY7nARCeRvfcY30QAJm94qsYb5iYQon5SHKKmFjPv682vNU4x1SSs2d3GSBfzZga/mF R0bkHSaM/4nuWzXzYS13Jlqeo5TaeVw8WouEwyb64RSvMFd4JGFn2bpRPQL3dReVVEyD CNeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GU1LpBpD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id u204-20020a8160d5000000b005a7da0fd8eesi447090ywb.174.2023.10.26.15.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 15:25:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GU1LpBpD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E186181F3382; Thu, 26 Oct 2023 15:25:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231947AbjJZWZM (ORCPT + 99 others); Thu, 26 Oct 2023 18:25:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229694AbjJZWZL (ORCPT ); Thu, 26 Oct 2023 18:25:11 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B783CC for ; Thu, 26 Oct 2023 15:25:08 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-53e07db272cso2158572a12.3 for ; Thu, 26 Oct 2023 15:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698359107; x=1698963907; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YeD8ayoKI+cNQ+dfy3v3WycX2QANJHfshgC8v+Kwnbw=; b=GU1LpBpDCnYxb8bp+dnWZ9au4wpEq0GwhQRGapIBqwVja+Jg9m1Idz0jldUI6+SuiU SRNktZ8FHw1OMU8X5C0LGrblY3IBErxVCmeRSv3NRv35SUC5w7wUwlUMXfNocwuyjWiv +MKJghA4AwDwk1WwywWsx1HIzWvNh8O59q/xTzE/0zCHeh3iXq9dr1JUCrkzsLX/RpBM fjPeTAcyg47Qmg1rpb4+NpYnsVdARIbLM+5tjGHB58pWpeKTJGxwbFTmlTJ+tsfBYkgh //OiUW5hjE+9St6bN3D2sgEUyPJ/LuVBnIWAt4MKOP559OQ1nTenXBVJ8J7S4wwwXXRU nL2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698359107; x=1698963907; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YeD8ayoKI+cNQ+dfy3v3WycX2QANJHfshgC8v+Kwnbw=; b=CvCh7T4DeYX4q0YufTr4hCMOkH08EkmpwnoJIBlUfDeEq6IT2lwpeYvIBOsNlnIQgC tq/Vf/Bse+AXLzQriMy7eQoMuirUiI9tKuofFgl/mjwczbiQo1s8YvSx0BkJXKhbtBaU TdqmTUv6+evA5mdZu2YsnNMcgsnyfHDzy+Ebndt6Pdfwq80bRmUsVl4k7EoN1+gynWRE Hw0q7fxwSsfhYzuHGZCOvOqBYLKt3hE+YU8pPJccaDOeC+AobnafAl9dAePVZeS5jmAD 7bjAZSpnd2pjb8nY5W3StWHsl61QGDec3s4gsKhB2AgO3stM3qpWKsxT9GVudAumUBrI FHHg== X-Gm-Message-State: AOJu0YwyI28DqawV3FpbD6B7/HiX/zoHcucytYU5YwZMtR5ack/60Of1 BjyczMZUYLYccYtkRM8xLY4rJm6rT5wyLtuFNy7l9g== X-Received: by 2002:a17:907:928b:b0:9ae:46c7:90fe with SMTP id bw11-20020a170907928b00b009ae46c790femr740516ejc.72.1698359106926; Thu, 26 Oct 2023 15:25:06 -0700 (PDT) MIME-Version: 1.0 References: <20231026-ethtool_puts_impl-v2-0-0d67cbdd0538@google.com> <20231026-ethtool_puts_impl-v2-2-0d67cbdd0538@google.com> <20231026221206.52oge3a5w4uxkkd5@skbuf> In-Reply-To: <20231026221206.52oge3a5w4uxkkd5@skbuf> From: Justin Stitt Date: Thu, 26 Oct 2023 15:24:54 -0700 Message-ID: Subject: Re: [PATCH next v2 2/3] checkpatch: add ethtool_sprintf rules To: Vladimir Oltean Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shay Agroskin , Arthur Kiyanovski , David Arinzon , Noam Dagan , Saeed Bishara , Rasesh Mody , Sudarsana Kalluru , GR-Linux-NIC-Dev@marvell.com, Dimitris Michailidis , Yisen Zhuang , Salil Mehta , Jesse Brandeburg , Tony Nguyen , Louis Peens , Shannon Nelson , Brett Creeley , drivers@pensando.io, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Ronak Doshi , VMware PV-Drivers Reviewers , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Hauke Mehrtens , Andrew Lunn , Florian Fainelli , =?UTF-8?B?QXLEsW7DpyDDnE5BTA==?= , Daniel Golle , Landen Chao , DENG Qingfang , Sean Wang , Matthias Brugger , AngeloGioacchino Del Regno , Linus Walleij , =?UTF-8?Q?Alvin_=C5=A0ipraga?= , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Lars Povlsen , Steen Hegelund , Daniel Machon , UNGLinuxDriver@microchip.com, Jiawen Wu , Mengyuan Lou , Heiner Kallweit , Russell King , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Nick Desaulniers , Nathan Chancellor , Kees Cook , intel-wired-lan@lists.osuosl.org, oss-drivers@corigine.com, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.3 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 26 Oct 2023 15:25:23 -0700 (PDT) On Thu, Oct 26, 2023 at 3:12=E2=80=AFPM Vladimir Oltean = wrote: > > On Thu, Oct 26, 2023 at 09:56:08PM +0000, Justin Stitt wrote: > > Add some warnings for using ethtool_sprintf() where a simple > > ethtool_puts() would suffice. > > > > The two cases are: > > > > 1) Use ethtool_sprintf() with just two arguments: > > | ethtool_sprintf(&data, driver[i].name); > > or > > 2) Use ethtool_sprintf() with a standalone "%s" fmt string: > > | ethtool_sprintf(&data, "%s", driver[i].name); > > > > The former may cause -Wformat-security warnings while the latter is jus= t > > not preferred. Both are safely in the category of warnings, not errors. > > > > Signed-off-by: Justin Stitt > > --- > > scripts/checkpatch.pl | 19 +++++++++++++++++++ > > 1 file changed, 19 insertions(+) > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > index 25fdb7fda112..22f007131337 100755 > > --- a/scripts/checkpatch.pl > > +++ b/scripts/checkpatch.pl > > @@ -7011,6 +7011,25 @@ sub process { > > "Prefer strscpy, strscpy_pad, or __nonstring= over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr= ); > > } > > > > +# ethtool_sprintf uses that should likely be ethtool_puts > > + if ($line =3D~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$= FuncArg\s*\)/) { > > + if(WARN("ETHTOOL_SPRINTF", > > + "Prefer ethtool_puts over ethtool_sprintf with= only two arguments\n" . $herecurr) && > > + $fix) { > > + $fixed[$fixlinenr] =3D~ s/ethtool_sprintf\s*\(/ethtool_puts\(= /; > > + } > > + } > > + > > + # use $rawline because $line loses %s via sanitization an= d thus we can't match against it. > > + if ($rawline =3D~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\= s*\"\%s\"\s*,\s*$FuncArg\s*\)/) { > > + if(WARN("ETHTOOL_SPRINTF", > > + "Prefer ethtool_puts over ethtool_sprintf with= standalone \"%s\" specifier\n" . $herecurr) && > > + $fix) { > > + $fixed[$fixlinenr] =3D~ s/ethtool_sprintf\s*\(\s*(.*?),.*?,(.= *?)\)/ethtool_puts\($1,$2)/; > > + } > > + } > > + > > + > > # typecasts on min/max could be min_t/max_t > > if ($perl_version_ok && > > defined $stat && > > > > -- > > 2.42.0.820.g83a721a137-goog > > > > I don't really know Perl, but does the indentation and coding style here > conform to any rules, or is it just free-form? The rest of the script > looks almost as you'd expect from C. This is unreadable to me. There was some discussion here [1] but AFAICT I need to use EMACS or configure my vim in a very particular way to get the same formatting But yeah, look around line 7000 -- lots of this pattern matching code is pretty hard to read. Not sure there's much to be done as far as readability is concerned. [1]: https://lore.kernel.org/all/137a309b313cc8a295f3affc704f0da049f233aa.c= amel@perches.com/ Thanks Justin