From nobody Thu Nov 14 05:07:50 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 5AA66C25B6B for ; Thu, 26 Oct 2023 21:56:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344901AbjJZV42 (ORCPT ); Thu, 26 Oct 2023 17:56:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbjJZV4U (ORCPT ); Thu, 26 Oct 2023 17:56:20 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 196431B6 for ; Thu, 26 Oct 2023 14:56:17 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d815354ea7fso1013636276.1 for ; Thu, 26 Oct 2023 14:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698357376; x=1698962176; 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=dYFCbbBAM6Yzga/rYjukRYsp/POsV5oivqv/XEKMawY=; b=s3uedDKO57Gbbjj5ckqs2yI/l/NMPrzoFUTVteFYNqT0wdbrNFOyCbCJuFEByoxTAA JQpgp42ryiIzTlXUHumVLjTW3WjN90jmHeBHezePUDDhRMm2fK4MZDnLHu25esuq/idr eyFwZhEC6sl7ZaIOcK0Rv0eAzryGQPveVBbB3/uO5m9fGNNItWJebKyErRLQYUTXIFyr 9iQwGzpsdUfkwLm2UdN/pYlmE3LgUVCmWK+vVUIESVZHzub3JTFXIy65UBQ4xeonC2Cw bThaKeZSTSA+F9yZrBQSDUMoeACAken3LAGWVDOThmuvzJ+IvnrO9zGzLB/GSf5jyDoX mcAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698357376; x=1698962176; 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=dYFCbbBAM6Yzga/rYjukRYsp/POsV5oivqv/XEKMawY=; b=Zvh752tYaKgPTuGnbGq9OvWX1XT1dFFiBFAQatCceO7YzPR+BE4cgiRxO8JR3GAbeS Eu0NchyWf/NncFjszEhUoPBCPxlgeEjMxEfFn/84hgvIDTV0BDe0Kz6sfvGS2w9vJ9Js p8501bYc4bMoa2s79TKZWqOU9UFjCQdZTXTKTPKFwBuhI5fQuuI0HrsGhiqC4NJ+FzAx hN5aGPKi/2qZWLuV8zO8Yxt8FyP/l2niXdm1P2vbM/+HmMKjmPBfycpGy2aC/56p00xc YbLdCmZ119UB2PksPUuTHb/Sffu9BK5LjqNV6MaQ9z45X227nFIQ+EtL+3PJq97nWNma QR3A== X-Gm-Message-State: AOJu0YwsKUx5IntTYtySIhoufeIUCVQ9VPQZcOvZo2NrrX8MUy9gtlcd 21lwrE6NwlfZBPf1HFFr2BNNVbk4iCV73GuI1A== X-Google-Smtp-Source: AGHT+IEfb7oOzPF36nMjYrY6yuwt7u5aPWQywSkNLJU2looIRNzyUO73wvXREAmdoYaSsyaeoRl83oRT8BPm+HpxYA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a5b:9d2:0:b0:d9a:bce6:acf3 with SMTP id y18-20020a5b09d2000000b00d9abce6acf3mr18000ybq.0.1698357376212; Thu, 26 Oct 2023 14:56:16 -0700 (PDT) Date: Thu, 26 Oct 2023 21:56:08 +0000 In-Reply-To: <20231026-ethtool_puts_impl-v2-0-0d67cbdd0538@google.com> Mime-Version: 1.0 References: <20231026-ethtool_puts_impl-v2-0-0d67cbdd0538@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698357372; l=1942; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=Tttx+U2qjudejsJUauC/KpxZsIK2OKqCPCc+Ch/fVls=; b=elpAQEsU3HOMMos/TnCJkrVo+AFG/1lerU81cOH+T2BgSHRjrFvGR7BmTA25L2uIiNK2WLsQZ m5JhXI8wJOxDHnWxVC+YAmf+U1BnkfHv0NAyeBvW/Fv+InbmfMY7Pw4 X-Mailer: b4 0.12.3 Message-ID: <20231026-ethtool_puts_impl-v2-2-0d67cbdd0538@google.com> Subject: [PATCH next v2 2/3] checkpatch: add ethtool_sprintf rules From: Justin Stitt 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 --- 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: 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("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 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("ETHTOOL_SPRINTF", + "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" spe= cifier\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 && --=20 2.42.0.820.g83a721a137-goog