From nobody Wed Nov 13 02:09:37 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA81BC10DC1 for ; Wed, 6 Dec 2023 23:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379612AbjLFXQU (ORCPT ); Wed, 6 Dec 2023 18:16:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbjLFXQL (ORCPT ); Wed, 6 Dec 2023 18:16:11 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8086D72 for ; Wed, 6 Dec 2023 15:16:17 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-db584b8fb9cso494749276.2 for ; Wed, 06 Dec 2023 15:16:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701904577; x=1702509377; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=l2kWA06Tv172IMegEBtFHRUM7NNFaAXM0DXA+ADIdjk=; b=wrXBQef4BivDpMwf9efbJU1kFR1awxtQm3mA9kDCwKhYX9WAiQYilDsZAWtuFKfnFP jGROwyeRzHbfZjp2mVEVtjbxDLp3p0N8GKzVZWUaS4tYvgccf2BFoRXOGc6VFy1aNAgi 6B6UyaFGwmr1jFDk2gMT6mquTqHM90bkCTOzX/VTqsWE3CX3TzUzrVIZiLmOrl/u4woW Q3ASzoAAGuyDzHDNhieLPA2TEQlayz6X90OxCBA8AGXZJoObWdMuai86o4bGs9XwCRVD ltBT1pusLErPoDJL6bn2lkMIDLp9YlYcvqYrQ4mNYqPEzKHt5Cq1NsyMlPRtSTQ32Edm luyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701904577; x=1702509377; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=l2kWA06Tv172IMegEBtFHRUM7NNFaAXM0DXA+ADIdjk=; b=K5HLytqDWQWhUn+BL92xJxEnLycabuDxBcz8LWPpQmIPPTWKxkHDBZs+QGXNsGjI6z yrup7McHX32TEaZtt/uOJPXT9YdatldTdBGEjBCuxx0D7fn5F6EWrHIw2O0I3EBBiQ1m rPtZWfWA7JnuryIl5zadmxpYz5bkXJbewrblKLQ6SY81pdIC961pbAYgiWaV/bOcUsjs e76vkMOZIrDL465tK0HcntVVk1mV82qshWbmvhgm7O7sp3Yebxm6iDYm85JeuYGphIDZ NVIR4HxvfOmT4PeNSFjEf8/p1tr5rxMqs1t3enlG5wNfo/7btBmipDjoXC8mT80bVJPm ZlvA== X-Gm-Message-State: AOJu0YzUlGh5gUlImQfps+nNu0f/XtKtJYu7OMGGoGAAqAYxW6ZcPvAh 0X6MWrpxdWeayrl0movwGwAE7vSDCtEaCHMsxQ== X-Google-Smtp-Source: AGHT+IEMd/xS2syY8YcxUE+jFNtUErStoqR6wMHC+Hu8IQ3Kowhzp4mcbmDmCUP7K5L1nughcxOsG1xLC/GwjEheoQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:d84e:0:b0:db3:5b0a:f274 with SMTP id p75-20020a25d84e000000b00db35b0af274mr25995ybg.0.1701904577009; Wed, 06 Dec 2023 15:16:17 -0800 (PST) Date: Wed, 06 Dec 2023 23:16:11 +0000 In-Reply-To: <20231206-ethtool_puts_impl-v5-0-5a2528e17bf8@google.com> Mime-Version: 1.0 References: <20231206-ethtool_puts_impl-v5-0-5a2528e17bf8@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1701904573; l=1994; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=JqgyVZ/lMWBcIL4WYVyOFjI42i4J6KNM5TZC8fVlDHw=; b=5wv2E+fU7luADvsAMYtCjNbTJcSsyC0RjHSAuunlQsU1ZDIXqaBaMVwfXSYg3av2hcyZ4RP6s XfEcT5fza/xCUvpPtigE+b//xXA7T8IwbrdOIZp8LHuMTe8gG7Y6xG8 X-Mailer: b4 0.12.3 Message-ID: <20231206-ethtool_puts_impl-v5-2-5a2528e17bf8@google.com> Subject: [PATCH net-next v5 2/3] checkpatch: add ethtool_sprintf rules From: justinstitt@google.com To: "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 , Vladimir Oltean , "=?utf-8?q?Ar=C4=B1n=C3=A7_=C3=9CNAL?=" , 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 Cc: 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, Justin Stitt Content-Type: text/plain; charset="utf-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable 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 just not preferred. Both are safely in the category of warnings, not errors. Signed-off-by: Justin Stitt Reviewed-by: Przemek Kitszel --- scripts/checkpatch.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 25fdb7fda112..6924731110d8 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7011,6 +7011,25 @@ sub process { "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: h= ttps://github.com/KSPP/linux/issues/90\n" . $herecurr); } =20 +# ethtool_sprintf uses that should likely be ethtool_puts + if ($line =3D~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) { + if (WARN("PREFER_ETHTOOL_PUTS", + "Prefer ethtool_puts over ethtool_sprintf with only two arguments\n" = . $herecurr) && + $fix) { + $fixed[$fixlinenr] =3D~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*($= FuncArg)/ethtool_puts($1, $7)/; + } + } + + # use $rawline because $line loses %s via sanitization and thus we can't= match against it. + if ($rawline =3D~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s= *$FuncArg\s*\)/) { + if (WARN("PREFER_ETHTOOL_PUTS", + "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" spec= ifier\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =3D~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*"\= %s"\s*,\s*($FuncArg)/ethtool_puts($1, $7)/; + } + } + + # typecasts on min/max could be min_t/max_t if ($perl_version_ok && defined $stat && --=20 2.43.0.rc2.451.g8631bc7472-goog