Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1452568rdh; Fri, 27 Oct 2023 15:06:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5gS5bDyBvcVb2FjhHvFzR3LE0oQMeUpbE+UmTggfHTufBT5YYjcJMRh/YVpbI5o8a2W25 X-Received: by 2002:a81:ad1a:0:b0:5a7:be29:19ac with SMTP id l26-20020a81ad1a000000b005a7be2919acmr4572841ywh.12.1698444384072; Fri, 27 Oct 2023 15:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698444384; cv=none; d=google.com; s=arc-20160816; b=H5TtQMNUPemyyh2EKL+TAFmreDVwwj18aVB9U21Om8aSQZjTWBs2VoJV2vnm60qm9Z k2Q5yWG291Dpqm165ulPqrm9g4GABzW7Kp6m24yXGJ8XTgFCcr+aQPmn0LCzaedI1/D3 geGBjYrDdOm4S9vFXZnUZwUVYGBfC8JrHsImc8fI8OGD3mVUC6cJb0znqr9wjJEy6Qk8 X77rEJlKDQZqWMXbR4k6rRC28aJBj+Xxe9ohyZCuvpnsLPdguzEbgEBuBbqBAaYeByJO R5ntXzFsNTvCkAPJHMDMVbX+02p/3hETZoUexSP3rexcYSFCAZaChnqCYcgaKZN4GJwU WmeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=DdSXo05ZDTrQ0bolpnGX21EQgcBZaNy4lNpYoejJ8s8=; fh=KbtZdS+g7EcIXF6IkhyVCA7RdLprHttm0sN0x6fLY0g=; b=0LIKZ25xRYKvr6M5H0BodQvKJGRnRxNcvzspG0nFARfhujA4XyqSiPqxmlHohAzuwe FHBfjOz6UsnywxdaitP4PpoILb+yMr6bOH1x+nPzZ6zB0t90QjURL2HfUVqXhRg21TPJ dd6H0Gl3VJbrQb8eEjYIYseyQH+00/8rwVC0rvBKT2FYTN7kE34uuhBgEOFfjbtQNx4I j3BcNoU+ZTnZUEZT89sjFyqqXb4bceTDt2AN13bQiCtDRQ3Uvp+xkRXVQxSWP70A/dAi qEOhCvejj3XjE/wsGxbKuo3awm4P+oFQiGL3jAXY/B+WA3Ww2rsi7UDLsDCNQcef3I75 GW+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E2pKeo2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id o198-20020a0dcccf000000b005a7f9634341si3733804ywd.151.2023.10.27.15.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 15:06:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=E2pKeo2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id E1EB98384F6A; Fri, 27 Oct 2023 15:06:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346637AbjJ0WFs (ORCPT + 99 others); Fri, 27 Oct 2023 18:05:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346583AbjJ0WFm (ORCPT ); Fri, 27 Oct 2023 18:05:42 -0400 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 87F29D42 for ; Fri, 27 Oct 2023 15:05:39 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7af69a4baso22500537b3.0 for ; Fri, 27 Oct 2023 15:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698444339; x=1699049139; 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=DdSXo05ZDTrQ0bolpnGX21EQgcBZaNy4lNpYoejJ8s8=; b=E2pKeo2kJ+akmSA0cTcgJnKx2HqrpUfZMJBQkdGOkG4lo4t1/d1iDTMNiye3crt/kS 4KhXKu6jnn2TZyWIi4PP9GzSwkGYjxlL1byrichhJqDdCjs58WmH0fkDOmiREC1NUuYp JrU4OF1egBvbBx2KALePsiGZg4nMeIWvtF6xGjcVyZNlaiWLPkjEkkfTxzH2N0wyzrnf 5DXJO0/C5d455+ANJtcfF+DPDnCteV4tJWMinMfw7JQQaBAdUt7S2dkwZxO8tSzZr0mp MoB0Rg29bAt9wMndQwtqQyScTqqzSJtD70YA/V/gGOouZ4cJ+pzzW3CpP2Vi2VwMtcQq Sg+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698444339; x=1699049139; 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=DdSXo05ZDTrQ0bolpnGX21EQgcBZaNy4lNpYoejJ8s8=; b=JSudh2+/P3hfJ+nn5J96wioe2cAdF2md+mtnYbV6soFH2OCg0hWMUTMDDbgfJLaMmq tG3meGnaDGa9OK1m4D5LKH4ZErnndTms+wsCgtFhnQMwjzGm8JxZXA4tsYHs7+bDxISY HcFG0HQYGD1BXsOOHWRKyVcuL6qrND1Ff503keTZ/TOFxUkBIrEHiGeOv1VraGT6OeSp g4ZdoolzKXTwoNr9pyKBGdVGtD5pqYRqaeEMGc01ZJngH5CJYpJW2gEwjhLeLkychdZm HmaOdJtfG6CWTX7SpltvcQO4R6Fj7rq22FFAJqCXBcxfIqfbx074t4Tb0qQbLJX1rdD9 GE1g== X-Gm-Message-State: AOJu0YyVEA+h7ZeexkrUfE1KAGzWxNJ3JA7BrdXuBrBAdFuyAnN28vkB hiHu11bBIQjggQ2pA9qVN4yQKFLQBbFccCU+Jw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:1746:b0:d9a:59cb:8bed with SMTP id bz6-20020a056902174600b00d9a59cb8bedmr69382ybb.5.1698444338644; Fri, 27 Oct 2023 15:05:38 -0700 (PDT) Date: Fri, 27 Oct 2023 22:05:34 +0000 In-Reply-To: <20231027-ethtool_puts_impl-v3-0-3466ac679304@google.com> Mime-Version: 1.0 References: <20231027-ethtool_puts_impl-v3-0-3466ac679304@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698444334; l=1990; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=Peahw3CmOtnUj2I89Tjap4JSwacXUbTFJpotNKfpIAo=; b=/dV8JH6sg2K0SMzdRYoIByKAm/hZGtV2i2RyZ0hRiSo1vOQmFG+LMPEoIUTIwPdSxZVjgBWW9 AOzrjCPUG+eCexFWJvZZE9e0rOdmAbkRvivrtrYWEohlds40p4HoDCE X-Mailer: b4 0.12.3 Message-ID: <20231027-ethtool_puts_impl-v3-2-3466ac679304@google.com> Subject: [PATCH net-next v3 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" X-Spam-Status: No, score=-8.4 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,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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 15:06:21 -0700 (PDT) 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 7d16f863edf1..9369ce1d15c5 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7020,6 +7020,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 && -- 2.42.0.820.g83a721a137-goog