public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 1/2] checkpatch: Allow passing config directory
@ 2026-04-20 13:30 Petr Vorel
  2026-04-20 13:30 ` [PATCH v6 2/2] checkpatch: Add option to not force /* */ for SPDX Petr Vorel
  2026-04-21 10:30 ` [PATCH v6 1/2] checkpatch: Allow passing config directory Petr Vorel
  0 siblings, 2 replies; 3+ messages in thread
From: Petr Vorel @ 2026-04-20 13:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Petr Vorel, Joe Perches, Simon Glass, Dwaipayan Ray,
	Lukas Bulwahn

checkpatch.pl searches for .checkpatch.conf in $CWD, $HOME and
$CWD/.scripts. Allow passing a single directory via
CHECKPATCH_CONFIG_DIR environment variable. This allows to directly use
project configuration file for projects which vendored checkpatch.pl
(e.g. LTP or u-boot).

Although it'd be more convenient for user to have --conf-dir option
(instead of using environment variable), code would get ugly because
options from the configuration file needs to be read before processing
command line options with Getopt::Long.

While at it, document directories and environment variable in -h help
and HTML doc.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes in v6:
* Improve wording "fallback" => falling back" (Simon), "locations" =>
  "search paths" (to be consistent).
* Document config file also in Documentation/dev-tools/checkpatch.rst
* Remove $! in error message (Simon, sashiko)

Link to v5:
https://lore.kernel.org/lkml/20260417170346.448758-1-pvorel@suse.cz/
Link to v4:
https://lore.kernel.org/lkml/20260415143636.272605-1-pvorel@suse.cz/
Link to v3:
https://lore.kernel.org/lkml/20260408120603.54351-1-pvorel@suse.cz/
Link to v2:
https://lore.kernel.org/lkml/20260224181623.89904-1-pvorel@suse.cz/
Link to v1:
https://lore.kernel.org/lkml/20260202144221.76765-2-pvorel@suse.cz/

 Documentation/dev-tools/checkpatch.rst |  7 +++++++
 scripts/checkpatch.pl                  | 19 ++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index dccede68698ca..010dfcd615afc 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -210,6 +210,13 @@ Available options:
 
    Display the help text.
 
+Configuration file
+==================
+
+Default configuration options can be stored in ``.checkpatch.conf``, search
+path: ``.:$HOME:.scripts`` or in a directory specified by ``$CHECKPATCH_CONFIG_DIR``
+environment variable (falling back to the default search path).
+
 Message Levels
 ==============
 
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0492d6afc9a1f..d86f5ccb06fe4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -57,6 +57,8 @@ my %ignore_type = ();
 my @ignore = ();
 my $help = 0;
 my $configuration_file = ".checkpatch.conf";
+my $def_configuration_dirs = ".:$ENV{HOME}:.scripts";
+my $env_config_dir = 'CHECKPATCH_CONFIG_DIR';
 my $max_line_length = 100;
 my $ignore_perl_version = 0;
 my $minimum_perl_version = 5.10.0;
@@ -146,6 +148,11 @@ Options:
   -h, --help, --version      display this help and exit
 
 When FILE is - read standard input.
+
+CONFIGURATION FILE
+Default configuration options can be stored in $configuration_file,
+search path: '$def_configuration_dirs' or in a directory specified by
+\$$env_config_dir environment variable (fallback to the default search path).
 EOM
 
 	exit($exitcode);
@@ -237,7 +244,7 @@ sub list_types {
 	exit($exitcode);
 }
 
-my $conf = which_conf($configuration_file);
+my $conf = which_conf($configuration_file, $env_config_dir, $def_configuration_dirs);
 if (-f $conf) {
 	my @conf_args;
 	open(my $conffile, '<', "$conf")
@@ -1531,9 +1538,15 @@ sub which {
 }
 
 sub which_conf {
-	my ($conf) = @_;
+	my ($conf, $env_key, $paths) = @_;
+	my $env_dir = $ENV{$env_key};
+
+	if (defined($env_dir)) {
+		return "$env_dir/$conf" if (-e "$env_dir/$conf");
+		warn "$P: Can't find a readable $conf in '$env_dir', falling back to default search paths\n";
+	}
 
-	foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
+	foreach my $path (split(/:/, $paths)) {
 		if (-e "$path/$conf") {
 			return "$path/$conf";
 		}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-21 10:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 13:30 [PATCH v6 1/2] checkpatch: Allow passing config directory Petr Vorel
2026-04-20 13:30 ` [PATCH v6 2/2] checkpatch: Add option to not force /* */ for SPDX Petr Vorel
2026-04-21 10:30 ` [PATCH v6 1/2] checkpatch: Allow passing config directory Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox