Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp749826rdh; Thu, 26 Oct 2023 14:57:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGBLaqrJWJ7uEkK+5gjs/e8FftE3yJkEsb7DHuXufUj1jSihnVxpd0SlJvD84dc9jQVbSZ X-Received: by 2002:a17:907:c1f:b0:9b2:89eb:79b5 with SMTP id ga31-20020a1709070c1f00b009b289eb79b5mr816000ejc.35.1698357452940; Thu, 26 Oct 2023 14:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698357452; cv=none; d=google.com; s=arc-20160816; b=RicCs3cnFMtmqQcvRc4rpZdaUh0aYfrUM4oNzkdQeCVMNO+3jrztDFiBK9/qTFwU9y GKEMdkyqyN7IX0MfHf3QiXdE2fpUk+9av8wnWPWEiKInjA0+2f7t5JSs9qviGTio/Td+ Ku2mhURAncGpk34UgJHuNR2c7jYdfwEg0w1TCAoN1MPtencRX24lRHrLjrLSv+baQ2HS lLQ3L6K8EIH+CZFB2j+Q+ylTSoiEFuuK7JOIX1u67Q9NiWhBcDp8bLdciBRrC3u5zPQA jga/a1sScfNbEH9srE1UGPCs6X79ceksgj9uGtUo3eypr+73c8Vl48VD50wndh9M7RKj 1TZg== 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=dYFCbbBAM6Yzga/rYjukRYsp/POsV5oivqv/XEKMawY=; fh=KbtZdS+g7EcIXF6IkhyVCA7RdLprHttm0sN0x6fLY0g=; b=l62Oxc7T6hp104AqHw3QhJT23ba2t+cnzDUq0JycB7GNn8NZafaPT2dTHKz1F1EqO5 /OKzc8oBroaWWGaXFIMsv6j46k8i+gpavQVzAK1TwofIT/c/HVbKRbV3Ssfza/MilRoP 1jQ6chWWX8gHPZaTVTLXrut4IbbkSiX/fU75e0fAvaCU5nv89EIcyZAomFOCPIissAbr tFFon3a7CkatGXUexhZ8Hn5Z15gOxNnIl0HSakyWMQ2FvYkHMLdfUa6f3yLlwSIZ/TYh DXfoYgnakd+Cu+puXqNP340J9L5CMTP3K8trxzf1yFACy4Dd/Lp+HXd86xzC5Gpu2Q30 +I8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=s3uedDKO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id qw26-20020a1709066a1a00b009c5706905cdsi144292ejc.463.2023.10.26.14.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 14:57:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=s3uedDKO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id A30A7825F17B; Thu, 26 Oct 2023 14:56:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344896AbjJZV41 (ORCPT + 99 others); Thu, 26 Oct 2023 17:56:27 -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-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" 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 26 Oct 2023 14:56:57 -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 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 =~ /\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] =~ s/ethtool_sprintf\s*\(/ethtool_puts\(/; + } + } + + # 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("ETHTOOL_SPRINTF", + "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ 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