From patchwork Wed Oct 25 23:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13436974 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A004381B4 for ; Wed, 25 Oct 2023 23:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yuNRk8Mj" 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 D7E46182 for ; Wed, 25 Oct 2023 16:40:38 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9b9aeb4962so214972276.3 for ; Wed, 25 Oct 2023 16:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698277238; x=1698882038; 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=z2yHYpXdKX/Z1PdTHNHNNkO8SEsjgfSsadT9YDZgRP0=; b=yuNRk8MjDZbUgkyEXvhp8IFsMSFPdDawqVt/qjaG/V4774b1i51mkRGMoUqRRrreD0 Wn+wVCtzu84N5sZW9tr8mfcGdk3049NBuU8VHVJLGXDBKqOUg3iS42iP3Kq7Vm/oSmct mfvD+aeKe04dW8ZPm8PJgNdlP2ki5nO3p4rIyN5FSHckl5ZIkmx2xzemwtpttcXw2m3w Tg9ejQ5LhGlwOwO96Rcv4Yx4O9DWf/C+wlCuKoLGeTDcmAYZy8oTj8zU7LSfIFxw4PDI U/WNvPGVS9HH0wzO8BbeIxix0Tv8aeRRM056khxKjJOZlcO1zq3Lg7r/OWpVF5MEkUQW 38lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698277238; x=1698882038; 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=z2yHYpXdKX/Z1PdTHNHNNkO8SEsjgfSsadT9YDZgRP0=; b=tBEFO5ZuIWT9rCPhq1y2sM98vt3eUdxxncvbe7+XGn2uClqTbDogq8p621GcYNsuF1 W+h2us0URKgea0SyFRj5rtG4W+TA63TQyr3q6MmYdEwfploUJJxo/ojPd0/sWx4GZHO/ 7QpKLbJ3WqVhybVArKz7REK5PX9XuNCVmlv0UKSZ3ubxBX8V+2TQQ6ktpd7TI/rlLGDG ZHMgdPFJUJXbPRrNeSmY39uf6lnRfyKThv9l6oFl9cJ7FNP525Bbml45jpe8tJrxj/WJ P9cR1UJPzkg8pyO3tGaau6AtYghKVDD7cRfW+oW6mnF08rtBUgVN6/QoMgoUZ06/vVAd 9XOQ== X-Gm-Message-State: AOJu0YzXX55FCJenbJRKCrj6qHd8b3ADAJXEK+Fb362r5kO4dUTQxsdW 5THixuo5kl7Xnn1VslbBx36JqyZeRIhqqvcLbw== X-Google-Smtp-Source: AGHT+IEPHaIkN8H3iGQWkKfJ5NpCYcT3yYMmFh0PPi0IcMzsA3hF9JA14tymNgt30lyJsEwk/WiGn6lEwEr2E4Dzgg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:bccc:0:b0:d9a:c218:8177 with SMTP id l12-20020a25bccc000000b00d9ac2188177mr365329ybm.8.1698277238101; Wed, 25 Oct 2023 16:40:38 -0700 (PDT) Date: Wed, 25 Oct 2023 23:40:34 +0000 In-Reply-To: <20231025-ethtool_puts_impl-v1-0-6a53a93d3b72@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231025-ethtool_puts_impl-v1-0-6a53a93d3b72@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698277232; l=1707; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=n1veWIcKxGb7fuzlMSTmPKoEQaWG96C9Cgb9YzocQ5U=; b=W+dlkHRgIJMungJ97d0DNn75PwsHcGQp6OJdyQzjetsUzkUF+C5MUA4sHBdGuuzJqLmwBu8XE 4b6P70t8H6LCSr0S2uDYGUmJBTSTiZLZFgaH2y2gkECIo+QpVCuuHfV X-Mailer: b4 0.12.3 Message-ID: <20231025-ethtool_puts_impl-v1-3-6a53a93d3b72@google.com> Subject: [PATCH 3/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 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, Justin Stitt 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7d16f863edf1..1ba9ce778746 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7020,6 +7020,19 @@ 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*\)/ ) { + WARN("ETHTOOL_SPRINTF", + "Prefer ethtool_puts over ethtool_sprintf with only two arguments" . $herecurr); + } + + # 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*\)/ ) { + WARN("ETHTOOL_SPRINTF2", + "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier" . $herecurr); + } + + # typecasts on min/max could be min_t/max_t if ($perl_version_ok && defined $stat &&