Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp587032rdb; Thu, 2 Nov 2023 11:56:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiA0jvyybsjy+XVhSO9mHZsQz2Dg/gU8j/Xbn60aoI47BTAkgl9QMWV9M0cjiuIAl2L2sO X-Received: by 2002:a05:6a00:93aa:b0:6be:bf7:fda5 with SMTP id ka42-20020a056a0093aa00b006be0bf7fda5mr18887303pfb.12.1698951382387; Thu, 02 Nov 2023 11:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698951382; cv=none; d=google.com; s=arc-20160816; b=m6lCC+6l2YX3AwfvzNeyHJIg1NtrdaHVa26UOVQtMBgpA/wXGmP32JebEAtNh68hRR LJem2N4AGv1DG1UAD5JZPkcsQ3ZlfI2cyMNKmjvfMPkZg4XTu9Cdor7Ij1JcLprCrFAm y+RL7vgekCNPpgZAkNG2ebaD41evIrWwlOYyv8N+8RpfYkctbg/qajtJVF9zyIcc3c46 sm3ku6uqoaKeSB1L4cxWG2IgWI1lAhEjZsFqHr7BukU2qfmUzeyHrXQ7yjOfmx4cH2O1 UQpugl36KRB0o2YWp4v56goZsvL+l6E1xcUCdDWMH15pn9cFNr0rRySAgDZ3zpK7sRw1 kYQw== 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=32K79yUePS03VyWxcYP10LK3dnc9q0LtbXtqJtsNvV4=; fh=KbtZdS+g7EcIXF6IkhyVCA7RdLprHttm0sN0x6fLY0g=; b=qOsf2BxALzrWn8Fa4QDnRC0CyMUW77SrgUlqUAor4C/WIAAMeuJEh2Y5r8NGQGq6Xn idkEyAGJkO7rTDQGsTSsAMfrS/gwLcmCE9EKHx92L3rqLpHxdhWXeR4s0JnEYro+13PR nW+Y5sse+Prquqa5AoE8DaDvA7tmx9bL2oGUmbpv/SymOikPIBC14GzuMZpVE19PwqHE xDi5S+pYsNDeiLZ2BnsAUulQKwn3hsAZrxBJpKkeKKnBpyqI0IZb4OJLGpqC2MI61E1k UZSi8BOFLMLCZ+RbEF3RS+wHgQm4yCuCT+yrrkl+U7yZxMwGtb/k/AFGFnIQ+SXG1aSv 3GJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4IrWuyf4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id bw5-20020a056a02048500b005bd3a0e2ec5si121798pgb.472.2023.11.02.11.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:56:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=4IrWuyf4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 5568A82CB513; Thu, 2 Nov 2023 11:56:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377357AbjKBS4L (ORCPT + 99 others); Thu, 2 Nov 2023 14:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234273AbjKBSz7 (ORCPT ); Thu, 2 Nov 2023 14:55:59 -0400 Received: from mail-oo1-xc49.google.com (mail-oo1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50301188 for ; Thu, 2 Nov 2023 11:55:52 -0700 (PDT) Received: by mail-oo1-xc49.google.com with SMTP id 006d021491bc7-581ff5ab8d3so2639226eaf.1 for ; Thu, 02 Nov 2023 11:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698951351; x=1699556151; 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=32K79yUePS03VyWxcYP10LK3dnc9q0LtbXtqJtsNvV4=; b=4IrWuyf4FDXi3knwTBIYTJsnN040pB6PiJlHx3iw0OI4rBF42lGH6AiCBDsY/ci1uK /hI28wnRz9xZky+J0JVzp9az/5gjGppGB2Xca/Jx7IWGJoSa2RirZoXOp+DnXSo4fRa5 RDkICyMS1AHDb14cCvMfnEGBj+ixOrfmrmkQzqlFFGX0C8wyzbpyjXvfSvkAG1jTRr2A +5JxzpbKBSolv016xq3bTGWsdL5DgeXsM999xbYVexSQcrnH+7d9Ze8SVO5EnG8m5Zlf RgifFokKLUsmfHnmTGfweAnFP86XvdnHNb9QaOYC8JTCCeqRAirKqUmPfYgNP3Lp+jsa o52w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698951351; x=1699556151; 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=32K79yUePS03VyWxcYP10LK3dnc9q0LtbXtqJtsNvV4=; b=UDri4kaMJPD82Sg0sj4gt1S7jhvd0tyrPPvPOjXHqLw4Tymj7S9pooM6sb4b25nElt 7bsi2Gt0jKFaUjSMBeyJLrYDTmW1VS5uIv6TS5QJ9rx+Tpw6WQxMqbjIUSeIUK8rBKzT 3Gz6RGgw0pSye1dqjK0vnZud/IkRjERFCAzX4QqwYaAJCRSB7/7oQaO6KK8EF5lwj5RX YPV4txfaslTB973HfpzZ5ucBrIrxVrWepjO3jNEDbMvRVRkRN1YBlU6XYqBDgKqE4N5L 5WXDEdIZ8sTcpQ+pBcISMEt6dr6PW0gOaiP+QbQtwkdkiILGU9nuSHKp+92do2QWAmpM C6MQ== X-Gm-Message-State: AOJu0YzWUNbigYKo+jsyD57arM8rqKfgMlbKWeDpKHF/dkHM3lOMtyCE uvtqCp45bt843v+BgkcwCRv4y+9IENLrP0sbXA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:b629:b0:1e9:a86f:ec44 with SMTP id cm41-20020a056870b62900b001e9a86fec44mr375267oab.2.1698951351424; Thu, 02 Nov 2023 11:55:51 -0700 (PDT) Date: Thu, 02 Nov 2023 18:55:43 +0000 In-Reply-To: <20231102-ethtool_puts_impl-v4-0-14e1e9278496@google.com> Mime-Version: 1.0 References: <20231102-ethtool_puts_impl-v4-0-14e1e9278496@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698951347; l=1990; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=5WZCSRmn5I240grrVCw4x/4n7/d4Ou3ZeMgHOu6QRHU=; b=1nZEvR6w+gOAIckxQFx/hzREhfGTALc08T+ct+mnZ2DmKk8uycd6z6khwq8TbMAwCu9Ezqp/H Dfu4ZT5igmOB2KC0bZOz7azBMQm7Hj6sTI87CdS0CAZqv2537ilCpzL X-Mailer: b4 0.12.3 Message-ID: <20231102-ethtool_puts_impl-v4-2-14e1e9278496@google.com> Subject: [PATCH net-next v4 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=-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, URIBL_BLOCKED,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]); Thu, 02 Nov 2023 11:56: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.869.gea05f2083d-goog