* [PATCH 1/2] checkpatch: Document config file in help
@ 2026-02-02 14:42 Petr Vorel
2026-02-02 14:42 ` [PATCH 2/2] checkpatch: Add --conf-dir option Petr Vorel
0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2026-02-02 14:42 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Vorel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
Lukas Bulwahn, Kory Maincent, Tom Rini, Simon Glass,
Kuan-Wei Chiu
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
This can be squashed to the following commit.
I added it separately just in case if following patch will be rejected.
Kind regards,
Petr
scripts/checkpatch.pl | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e56374662ff79..8fffdf9e7f85f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -57,6 +57,7 @@ my %ignore_type = ();
my @ignore = ();
my $help = 0;
my $configuration_file = ".checkpatch.conf";
+my $def_configuration_dirs = ".:$ENV{HOME}:.scripts";
my $max_line_length = 100;
my $ignore_perl_version = 0;
my $minimum_perl_version = 5.10.0;
@@ -146,6 +147,9 @@ Options:
-h, --help, --version display this help and exit
When FILE is - read standard input.
+
+Script searches for a configuration file $configuration_file in path:
+$def_configuration_dirs
EOM
exit($exitcode);
@@ -237,7 +241,7 @@ sub list_types {
exit($exitcode);
}
-my $conf = which_conf($configuration_file);
+my $conf = which_conf($configuration_file, $def_configuration_dirs);
if (-f $conf) {
my @conf_args;
open(my $conffile, '<', "$conf")
@@ -1530,9 +1534,9 @@ sub which {
}
sub which_conf {
- my ($conf) = @_;
+ my ($conf, $dirs) = @_;
- foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
+ foreach my $path (split(/:/, $dirs)) {
if (-e "$path/$conf") {
return "$path/$conf";
}
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] checkpatch: Add --conf-dir option
2026-02-02 14:42 [PATCH 1/2] checkpatch: Document config file in help Petr Vorel
@ 2026-02-02 14:42 ` Petr Vorel
2026-02-20 11:47 ` Petr Vorel
2026-02-20 17:13 ` Joe Perches
0 siblings, 2 replies; 7+ messages in thread
From: Petr Vorel @ 2026-02-02 14:42 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Vorel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
Lukas Bulwahn, Kory Maincent, Tom Rini, Simon Glass,
Kuan-Wei Chiu
This allows to directly use project configuration file for projects
which vendored checkpatch.pl (e.g. LTP or u-boot).
Options from the configuration file has been read before processing
command line options with Getopt::Long since the start (000d1cc1829f9)
because options read from config file needs to be unshifted from command
line arguments (@ARGV) before processing with Getopt::Long. Therefore
parse --conf-dir with direct reading @ARGV.
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
@ARGV can be probably processed cleaner.
Kind regards,
Petr
scripts/checkpatch.pl | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8fffdf9e7f85f..7e19287d452d8 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -58,6 +58,7 @@ my @ignore = ();
my $help = 0;
my $configuration_file = ".checkpatch.conf";
my $def_configuration_dirs = ".:$ENV{HOME}:.scripts";
+my $configuration_dir = "";
my $max_line_length = 100;
my $ignore_perl_version = 0;
my $minimum_perl_version = 5.10.0;
@@ -144,12 +145,14 @@ Options:
is a terminal ('auto'). Default is 'auto'.
--kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default
${CONFIG_})
+ --conf-dir=DIR directory with $configuration_file configuration file
+ (default:$def_configuration_dirs)
-h, --help, --version display this help and exit
When FILE is - read standard input.
Script searches for a configuration file $configuration_file in path:
-$def_configuration_dirs
+$def_configuration_dirs (can be overwritten by --conf-dir)
EOM
exit($exitcode);
@@ -241,7 +244,31 @@ sub list_types {
exit($exitcode);
}
-my $conf = which_conf($configuration_file, $def_configuration_dirs);
+# parse --conf-dir before the other options
+my @argv;
+while (@ARGV) {
+ my $arg = shift @ARGV;
+ if ($arg eq '--conf-dir') {
+ $configuration_dir = shift @ARGV;
+ die "--conf-dir requires value" unless ($configuration_dir);
+ } elsif ($arg =~ /^--conf-dir=(.+)$/) {
+ $configuration_dir = $1;
+ die "--conf-dir requires value" unless ($configuration_dir);
+ } else {
+ push @argv, $arg;
+ }
+}
+@ARGV = @argv;
+
+my $conf;
+if ($configuration_dir) {
+ die "Dir. $configuration_dir does not exist" unless (-d $configuration_dir);
+ $conf = "$configuration_dir/$configuration_file";
+ die "File $conf does not exist" unless (-f $conf);
+} else {
+ $conf = which_conf($configuration_file, $def_configuration_dirs);
+}
+
if (-f $conf) {
my @conf_args;
open(my $conffile, '<', "$conf")
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] checkpatch: Add --conf-dir option
2026-02-02 14:42 ` [PATCH 2/2] checkpatch: Add --conf-dir option Petr Vorel
@ 2026-02-20 11:47 ` Petr Vorel
2026-02-20 17:13 ` Joe Perches
1 sibling, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2026-02-20 11:47 UTC (permalink / raw)
To: linux-kernel
Cc: Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn,
Kory Maincent, Tom Rini, Simon Glass, Kuan-Wei Chiu
Hi,
gently ping about the patchset. We can keep the functionality out of tree,
but I suppose more project which use checkpatch.pl would benefit from it.
Kind regards,
Petr
> This allows to directly use project configuration file for projects
> which vendored checkpatch.pl (e.g. LTP or u-boot).
> Options from the configuration file has been read before processing
> command line options with Getopt::Long since the start (000d1cc1829f9)
> because options read from config file needs to be unshifted from command
> line arguments (@ARGV) before processing with Getopt::Long. Therefore
> parse --conf-dir with direct reading @ARGV.
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> @ARGV can be probably processed cleaner.
> Kind regards,
> Petr
> scripts/checkpatch.pl | 31 +++++++++++++++++++++++++++++--
> 1 file changed, 29 insertions(+), 2 deletions(-)
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 8fffdf9e7f85f..7e19287d452d8 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -58,6 +58,7 @@ my @ignore = ();
> my $help = 0;
> my $configuration_file = ".checkpatch.conf";
> my $def_configuration_dirs = ".:$ENV{HOME}:.scripts";
> +my $configuration_dir = "";
> my $max_line_length = 100;
> my $ignore_perl_version = 0;
> my $minimum_perl_version = 5.10.0;
> @@ -144,12 +145,14 @@ Options:
> is a terminal ('auto'). Default is 'auto'.
> --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default
> ${CONFIG_})
> + --conf-dir=DIR directory with $configuration_file configuration file
> + (default:$def_configuration_dirs)
> -h, --help, --version display this help and exit
> When FILE is - read standard input.
> Script searches for a configuration file $configuration_file in path:
> -$def_configuration_dirs
> +$def_configuration_dirs (can be overwritten by --conf-dir)
> EOM
> exit($exitcode);
> @@ -241,7 +244,31 @@ sub list_types {
> exit($exitcode);
> }
> -my $conf = which_conf($configuration_file, $def_configuration_dirs);
> +# parse --conf-dir before the other options
> +my @argv;
> +while (@ARGV) {
> + my $arg = shift @ARGV;
> + if ($arg eq '--conf-dir') {
> + $configuration_dir = shift @ARGV;
> + die "--conf-dir requires value" unless ($configuration_dir);
> + } elsif ($arg =~ /^--conf-dir=(.+)$/) {
> + $configuration_dir = $1;
> + die "--conf-dir requires value" unless ($configuration_dir);
> + } else {
> + push @argv, $arg;
> + }
> +}
> +@ARGV = @argv;
> +
> +my $conf;
> +if ($configuration_dir) {
> + die "Dir. $configuration_dir does not exist" unless (-d $configuration_dir);
> + $conf = "$configuration_dir/$configuration_file";
> + die "File $conf does not exist" unless (-f $conf);
> +} else {
> + $conf = which_conf($configuration_file, $def_configuration_dirs);
> +}
> +
> if (-f $conf) {
> my @conf_args;
> open(my $conffile, '<', "$conf")
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] checkpatch: Add --conf-dir option
2026-02-02 14:42 ` [PATCH 2/2] checkpatch: Add --conf-dir option Petr Vorel
2026-02-20 11:47 ` Petr Vorel
@ 2026-02-20 17:13 ` Joe Perches
2026-02-23 15:53 ` Petr Vorel
1 sibling, 1 reply; 7+ messages in thread
From: Joe Perches @ 2026-02-20 17:13 UTC (permalink / raw)
To: Petr Vorel, linux-kernel
Cc: Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn, Kory Maincent,
Tom Rini, Simon Glass, Kuan-Wei Chiu
On Mon, 2026-02-02 at 15:42 +0100, Petr Vorel wrote:
> ```
> This allows to directly use project configuration file for projects
> which vendored checkpatch.pl (e.g. LTP or u-boot).
>
> Options from the configuration file has been read before processing
> command line options with Getopt::Long since the start (000d1cc1829f9)
> because options read from config file needs to be unshifted from command
> line arguments (@ARGV) before processing with Getopt::Long. Therefore
> parse --conf-dir with direct reading @ARGV.
nack.
Extend 'sub which_conf {' and the perhaps the code that uses it
if you really need this capability.
Though I think it's not all that useful.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] checkpatch: Add --conf-dir option
2026-02-20 17:13 ` Joe Perches
@ 2026-02-23 15:53 ` Petr Vorel
2026-02-23 17:08 ` Joe Perches
0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2026-02-23 15:53 UTC (permalink / raw)
To: Joe Perches
Cc: linux-kernel, Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn,
Kory Maincent, Tom Rini, Simon Glass, Kuan-Wei Chiu
> On Mon, 2026-02-02 at 15:42 +0100, Petr Vorel wrote:
> > ```
> > This allows to directly use project configuration file for projects
> > which vendored checkpatch.pl (e.g. LTP or u-boot).
> > Options from the configuration file has been read before processing
> > command line options with Getopt::Long since the start (000d1cc1829f9)
> > because options read from config file needs to be unshifted from command
> > line arguments (@ARGV) before processing with Getopt::Long. Therefore
> > parse --conf-dir with direct reading @ARGV.
> nack.
> Extend 'sub which_conf {' and the perhaps the code that uses it
> if you really need this capability.
Thanks for a hint. If there is a chance it will be accepted I'll have look on
it. We would certainly appreciated not having to carry yet another checkpatch.pl
patch in LTP.
> Though I think it's not all that useful.
We use LTP in makefile targets run from various subdirectories. For that we
define our checkpatch.pl options (--ignore list and others) in certain Makefile.
Then we have b4 configuration, where we also use checkpatch.pl options.
Mixing cd to rootdir and passing path to the sources is of course doable
(to reach config file in .scripts in project root directory) but quite ugly.
Also, allowing to pass a configuration file (quite common feature for any
software) would allow to run checkpatch.pl with different configs for different
projects.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] checkpatch: Add --conf-dir option
2026-02-23 15:53 ` Petr Vorel
@ 2026-02-23 17:08 ` Joe Perches
2026-02-23 21:38 ` Petr Vorel
0 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2026-02-23 17:08 UTC (permalink / raw)
To: Petr Vorel
Cc: linux-kernel, Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn,
Kory Maincent, Tom Rini, Simon Glass, Kuan-Wei Chiu
On Mon, 2026-02-23 at 16:53 +0100, Petr Vorel wrote:
> On Mon, 2026-02-02 at 15:42 +0100, Petr Vorel wrote:
> > > This allows to directly use project configuration file for projects
> > > which vendored checkpatch.pl (e.g. LTP or u-boot).
[]
> > Extend 'sub which_conf {' and the perhaps the code that uses it
> > if you really need this capability.
>
> Thanks for a hint. If there is a chance it will be accepted I'll have look on
> it. We would certainly appreciated not having to carry yet another checkpatch.pl
> patch in LTP.
[]
> > Though I think it's not all that useful.
[]
> We use LTP in makefile targets run from various subdirectories. For that we
> define our checkpatch.pl options (--ignore list and others) in certain Makefile.
> Then we have b4 configuration, where we also use checkpatch.pl options.
>
> Mixing cd to rootdir and passing path to the sources is of course doable
> (to reach config file in .scripts in project root directory) but quite ugly.
>
> Also, allowing to pass a configuration file (quite common feature for any
> software) would allow to run checkpatch.pl with different configs for different
> projects.
Right now the HOME environment variable is used in which_conf.
Perhaps prepend a CHECKPATCH_CONFIG environment where the right
<somedir>.checkpatch.conf would be found?
Maybe something like the below and executed with something like
$ CHECKPATCH_CONFIG=<dir> <path_to>checkpatch.pl etc...
---
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e56374662ff7..355542d7d5a9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1532,7 +1532,11 @@ sub which {
sub which_conf {
my ($conf) = @_;
- foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
+ my $env_config_path = 'CHECKPATCH_CONFIG';
+ my $paths = $ENV{$env_config_path} . ':' if exists($ENV{$env_config_path});
+ $paths .= ".:$ENV{'HOME'}:.scripts";
+
+ foreach my $path (split(/:/, $paths)) {
if (-e "$path/$conf") {
return "$path/$conf";
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] checkpatch: Add --conf-dir option
2026-02-23 17:08 ` Joe Perches
@ 2026-02-23 21:38 ` Petr Vorel
0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2026-02-23 21:38 UTC (permalink / raw)
To: Joe Perches
Cc: linux-kernel, Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn,
Kory Maincent, Tom Rini, Simon Glass, Kuan-Wei Chiu
> On Mon, 2026-02-23 at 16:53 +0100, Petr Vorel wrote:
> > On Mon, 2026-02-02 at 15:42 +0100, Petr Vorel wrote:
> > > > This allows to directly use project configuration file for projects
> > > > which vendored checkpatch.pl (e.g. LTP or u-boot).
> []
> > > Extend 'sub which_conf {' and the perhaps the code that uses it
> > > if you really need this capability.
> > Thanks for a hint. If there is a chance it will be accepted I'll have look on
> > it. We would certainly appreciated not having to carry yet another checkpatch.pl
> > patch in LTP.
> []
> > > Though I think it's not all that useful.
> []
> > We use LTP in makefile targets run from various subdirectories. For that we
> > define our checkpatch.pl options (--ignore list and others) in certain Makefile.
> > Then we have b4 configuration, where we also use checkpatch.pl options.
> > Mixing cd to rootdir and passing path to the sources is of course doable
> > (to reach config file in .scripts in project root directory) but quite ugly.
> > Also, allowing to pass a configuration file (quite common feature for any
> > software) would allow to run checkpatch.pl with different configs for different
> > projects.
> Right now the HOME environment variable is used in which_conf.
Yes (and that's not enough for the case I described).
> Perhaps prepend a CHECKPATCH_CONFIG environment where the right
> <somedir>.checkpatch.conf would be found?
Sure, if you prefer not processing @ARGV twice (and modifying it), using
environment variable works as well. The reason I touched @ARGV was to be
slightly more convenient for user with a bit more complicated code. But when
variable is properly documented, there is practically no difference (if I ignore
the fact that in the future somebody writes bash-completion support, which will
ignore environment variables).
Anyway, thanks for being open to the idea. I'll send a patch based on the code
you proposed.
Kind regards,
Petr
> Maybe something like the below and executed with something like
> $ CHECKPATCH_CONFIG=<dir> <path_to>checkpatch.pl etc...
> ---
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index e56374662ff7..355542d7d5a9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1532,7 +1532,11 @@ sub which {
> sub which_conf {
> my ($conf) = @_;
> - foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
> + my $env_config_path = 'CHECKPATCH_CONFIG';
> + my $paths = $ENV{$env_config_path} . ':' if exists($ENV{$env_config_path});
> + $paths .= ".:$ENV{'HOME'}:.scripts";
> +
> + foreach my $path (split(/:/, $paths)) {
> if (-e "$path/$conf") {
> return "$path/$conf";
> }
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-02-23 21:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 14:42 [PATCH 1/2] checkpatch: Document config file in help Petr Vorel
2026-02-02 14:42 ` [PATCH 2/2] checkpatch: Add --conf-dir option Petr Vorel
2026-02-20 11:47 ` Petr Vorel
2026-02-20 17:13 ` Joe Perches
2026-02-23 15:53 ` Petr Vorel
2026-02-23 17:08 ` Joe Perches
2026-02-23 21:38 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox