From patchwork Wed Dec 6 23:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13482357 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wrXBQef4" Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDC9210C0 for ; Wed, 6 Dec 2023 15:16:17 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5caf86963ecso490897b3.3 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=IyJykEPZSKDRXl9vSlys9vaS65Wm1fDRn6Ya2IAIOBgoZv7vvguaOcAOFTi6yyjOCp x7LKcFYx5TJZsqlJOUQZPJU1wao7D2OHHRnZzHncEf3FIWZ6xp5sLEia3N/qfSNyaqGo YVRflZeb5ShaER3pNhJDhTP1xpnjI9ZR+GTFuaD21Gr1axk9DQ1VvlrW+jYPpYg0ydXd XUB2+VG7Lk1kdERDZfisSEVv+9T3P3WvqVoqBdIj5mE+C+MHslimVAc5Whp26Qi5ueEe lqDArxf2MkG9N1bv6IdZWgu4C9AN+Bb9t9Qcjtc1aKq8D1I/WWJYK8SQWbSrgHUGJdpe nTmw== X-Gm-Message-State: AOJu0YyYzxXHdx7OLqJWLmhfs3vcSgRv5ivu1jveVrWGqpQ1m2xZF6go xY6mEaA3DaklBd0FIBIqyBsuf9PrBcdowmm08A== 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> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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?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 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 X-Patchwork-Delegate: kuba@kernel.org 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: https://github.com/KSPP/linux/issues/90\n" . $herecurr); } +# ethtool_sprintf uses that should likely be ethtool_puts + if ($line =~ /\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] =~ 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 =~ /\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\" specifier\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ 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 &&