Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1312648rdb; Wed, 6 Dec 2023 15:16:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFo0f8XTyRIS122Er6WvnFhNoQ1fNbapi1qvmsjagl3ZSsaKUy6XJN+egH3ZCq+ygtSv3vi X-Received: by 2002:a92:db12:0:b0:35d:6123:1793 with SMTP id b18-20020a92db12000000b0035d61231793mr1800674iln.41.1701904598751; Wed, 06 Dec 2023 15:16:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701904598; cv=none; d=google.com; s=arc-20160816; b=i1Xi4phqEruBsc5Iope3PLZHyW81seVmTEoP20Sur+5nyQWEylrMdPmfHk24A1obCc iP1jOTJef6fiS7XMCQagLLcvAjzK3yRhSBwOh4x5RFJAMuvXSBvEnWOS9rCSsEbRG8ct IVmwmeA5MUl9m9/0TzgQ58m+b7KjWOqTLCA1ih9YHn8x0VvtEfw0j9AlPY31fjUAZ542 sGAwv2kJcUejtfsJ2PSRKBPajoOay200oUC0LMs9zL2UtLMrUEYVy+4iOZX3XUIp3VmL v8x2+JIHOuhuoFLfnKUufDicHJGnqA4s6l3RBkBC4KJU99I+1QD2ROnTrPHGOlOu52dZ MAHw== 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=l2kWA06Tv172IMegEBtFHRUM7NNFaAXM0DXA+ADIdjk=; fh=KbtZdS+g7EcIXF6IkhyVCA7RdLprHttm0sN0x6fLY0g=; b=l52h4HMgLxs/mRI2SzDwGt+T3c/7/qsQL2X5om1ewma91SFYCzTOEFnfM6TZrA1df5 meeOob/f8MGLoQcv6jRtVqrB4WhVfXRtISGj7cX6byeRZEYAetaYbTzc0tIXJbWe62dA fljD9AaH0mMNeGirusjL8aUM64Y5JWqTgz0E8K0faGgiLj6M0OynWO3OIsBSUzMHabxG 6zm71qRjM3Awnr7aqpfZtVnYRCZjtg/+/TGx7fqxgd8rP/hYLSOFf6mWjHPxRwHlOVM9 3zGNT8VsNoZvbonjG3tTOLayG9FoZF9TJhS5n+tZdHzghDe8jWTGGhAzfMY4gCVCEI+B hjKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wrXBQef4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s22-20020a656456000000b005bdfb77e552si41371pgv.439.2023.12.06.15.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 15:16:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wrXBQef4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 456D48024014; Wed, 6 Dec 2023 15:16:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377759AbjLFXQT (ORCPT + 99 others); Wed, 6 Dec 2023 18:16:19 -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-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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 06 Dec 2023 15:16:37 -0800 (PST) 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..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 && -- 2.43.0.rc2.451.g8631bc7472-goog