public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] checkpatch: Allow to pass config directory
@ 2026-02-24 18:16 Petr Vorel
  2026-03-26 15:47 ` Petr Vorel
  2026-03-26 17:48 ` Simon Glass
  0 siblings, 2 replies; 6+ messages in thread
From: Petr Vorel @ 2026-02-24 18:16 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

checkpatch.pl searches for .checkpatch.conf in $HOME and .scripts
(in current working directory). Allow to pass 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).

While at it, document all directories in help.

Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
NOTE: if you don't like the way how directories are printed in help
(user's home directory path instead of $HOME) I can change it.

$ ./scripts/checkpatch.pl -h
...
When FILE is - read standard input.

CONFIGURATION FILE

Script searches for a configuration file .checkpatch.conf in path:
$CHECKPATCH_CONFIG_DIR:.:/home/foo:.scripts

Link to v1:
https://lore.kernel.org/lkml/20260202144221.76765-1-pvorel@suse.cz/
https://lore.kernel.org/lkml/20260202144221.76765-2-pvorel@suse.cz/

Changes v1->v2:
* Use environment variable instead of --conf-dir option (Joe Perches)
NOTE: I'd slightly prefer using --conf-dir (more convenient for user).
* squash documentation into this commit

Kind regards,
Petr

 scripts/checkpatch.pl | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index bec7930cdd66..e47fec115ee7 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,10 @@ Options:
   -h, --help, --version      display this help and exit
 
 When FILE is - read standard input.
+
+CONFIGURATION FILE
+Script searches for a configuration file $configuration_file in path:
+\$$env_config_dir:$def_configuration_dirs
 EOM
 
 	exit($exitcode);
@@ -1531,8 +1537,10 @@ sub which {
 
 sub which_conf {
 	my ($conf) = @_;
+	my $paths = $ENV{$env_config_dir} . ':' if exists($ENV{$env_config_dir});
+	$paths .= $def_configuration_dirs;
 
-	foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
+	foreach my $path (split(/:/, $paths)) {
 		if (-e "$path/$conf") {
 			return "$path/$conf";
 		}
-- 
2.51.0


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

* Re: [PATCH v2] checkpatch: Allow to pass config directory
  2026-02-24 18:16 [PATCH v2] checkpatch: Allow to pass config directory Petr Vorel
@ 2026-03-26 15:47 ` Petr Vorel
  2026-03-26 17:48 ` Simon Glass
  1 sibling, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-03-26 15: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 all,

> checkpatch.pl searches for .checkpatch.conf in $HOME and .scripts
> (in current working directory). Allow to pass 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).

Gentle ping for a feedback.

Kind regards,
Petr

> While at it, document all directories in help.

> Suggested-by: Joe Perches <joe@perches.com>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> NOTE: if you don't like the way how directories are printed in help
> (user's home directory path instead of $HOME) I can change it.

> $ ./scripts/checkpatch.pl -h
> ...
> When FILE is - read standard input.

> CONFIGURATION FILE

> Script searches for a configuration file .checkpatch.conf in path:
> $CHECKPATCH_CONFIG_DIR:.:/home/foo:.scripts

> Link to v1:
> https://lore.kernel.org/lkml/20260202144221.76765-1-pvorel@suse.cz/
> https://lore.kernel.org/lkml/20260202144221.76765-2-pvorel@suse.cz/

> Changes v1->v2:
> * Use environment variable instead of --conf-dir option (Joe Perches)
> NOTE: I'd slightly prefer using --conf-dir (more convenient for user).
> * squash documentation into this commit

> Kind regards,
> Petr

>  scripts/checkpatch.pl | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index bec7930cdd66..e47fec115ee7 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,10 @@ Options:
>    -h, --help, --version      display this help and exit

>  When FILE is - read standard input.
> +
> +CONFIGURATION FILE
> +Script searches for a configuration file $configuration_file in path:
> +\$$env_config_dir:$def_configuration_dirs
>  EOM

>  	exit($exitcode);
> @@ -1531,8 +1537,10 @@ sub which {

>  sub which_conf {
>  	my ($conf) = @_;
> +	my $paths = $ENV{$env_config_dir} . ':' if exists($ENV{$env_config_dir});
> +	$paths .= $def_configuration_dirs;

> -	foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
> +	foreach my $path (split(/:/, $paths)) {
>  		if (-e "$path/$conf") {
>  			return "$path/$conf";
>  		}

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

* Re: [PATCH v2] checkpatch: Allow to pass config directory
  2026-02-24 18:16 [PATCH v2] checkpatch: Allow to pass config directory Petr Vorel
  2026-03-26 15:47 ` Petr Vorel
@ 2026-03-26 17:48 ` Simon Glass
  2026-03-26 20:50   ` Petr Vorel
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Glass @ 2026-03-26 17:48 UTC (permalink / raw)
  To: Petr Vorel
  Cc: linux-kernel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
	Lukas Bulwahn, Kory Maincent, Tom Rini, Simon Glass,
	Kuan-Wei Chiu

Hi Petr,

On Tue, 24 Feb 2026 at 11:20, Petr Vorel <pvorel@suse.cz> wrote:
>
> checkpatch.pl searches for .checkpatch.conf in $HOME and .scripts
> (in current working directory). Allow to pass directory via

How about: Allow passing a directory

> 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).
>
> While at it, document all directories in help.
>
> Suggested-by: Joe Perches <joe@perches.com>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> NOTE: if you don't like the way how directories are printed in help
> (user's home directory path instead of $HOME) I can change it.
>
> $ ./scripts/checkpatch.pl -h
> ...
> When FILE is - read standard input.
>
> CONFIGURATION FILE
>
> Script searches for a configuration file .checkpatch.conf in path:
> $CHECKPATCH_CONFIG_DIR:.:/home/foo:.scripts

It looks like this can be a colon-separated list of dirs - perhaps
document that, if intended?

>
> Link to v1:
> https://lore.kernel.org/lkml/20260202144221.76765-1-pvorel@suse.cz/
> https://lore.kernel.org/lkml/20260202144221.76765-2-pvorel@suse.cz/
>
> Changes v1->v2:
> * Use environment variable instead of --conf-dir option (Joe Perches)
> NOTE: I'd slightly prefer using --conf-dir (more convenient for user).

Agreed.

> * squash documentation into this commit
>
> Kind regards,
> Petr
>
>  scripts/checkpatch.pl | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index bec7930cdd66..e47fec115ee7 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,10 @@ Options:
>    -h, --help, --version      display this help and exit
>
>  When FILE is - read standard input.
> +
> +CONFIGURATION FILE
> +Script searches for a configuration file $configuration_file in path:
> +\$$env_config_dir:$def_configuration_dirs
>  EOM
>
>         exit($exitcode);
> @@ -1531,8 +1537,10 @@ sub which {
>
>  sub which_conf {
>         my ($conf) = @_;
> +       my $paths = $ENV{$env_config_dir} . ':' if exists($ENV{$env_config_dir});

How about splitting it so that the variable cannot be undef ?

my $paths = $def_configuration_dirs;
$paths = "$ENV{$env_config_dir}:$paths" if exists($ENV{$env_config_dir});

> +       $paths .= $def_configuration_dirs;
>
> -       foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
> +       foreach my $path (split(/:/, $paths)) {
>                 if (-e "$path/$conf") {
>                         return "$path/$conf";
>                 }
> --
> 2.51.0
>
>

Regards,
Simon

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

* Re: [PATCH v2] checkpatch: Allow to pass config directory
  2026-03-26 17:48 ` Simon Glass
@ 2026-03-26 20:50   ` Petr Vorel
  2026-03-27  0:06     ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Vorel @ 2026-03-26 20:50 UTC (permalink / raw)
  To: Simon Glass
  Cc: linux-kernel, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
	Lukas Bulwahn, Kory Maincent, Tom Rini, Simon Glass,
	Kuan-Wei Chiu

Hi Simon,

first, thanks for your review!

> Hi Petr,

> On Tue, 24 Feb 2026 at 11:20, Petr Vorel <pvorel@suse.cz> wrote:

> > checkpatch.pl searches for .checkpatch.conf in $HOME and .scripts
> > (in current working directory). Allow to pass directory via

> How about: Allow passing a directory

+1

> > 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).

> > While at it, document all directories in help.

> > Suggested-by: Joe Perches <joe@perches.com>
> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > NOTE: if you don't like the way how directories are printed in help
> > (user's home directory path instead of $HOME) I can change it.

> > $ ./scripts/checkpatch.pl -h
> > ...
> > When FILE is - read standard input.

> > CONFIGURATION FILE

> > Script searches for a configuration file .checkpatch.conf in path:
> > $CHECKPATCH_CONFIG_DIR:.:/home/foo:.scripts

> It looks like this can be a colon-separated list of dirs - perhaps
> document that, if intended?

It was not intended. I'd slightly prefer variable should point into single
directory (that's why I did it in v1), I'll send v3.

But sure, it can be list of directories if you really prefer it.

> > Link to v1:
> > https://lore.kernel.org/lkml/20260202144221.76765-1-pvorel@suse.cz/
> > https://lore.kernel.org/lkml/20260202144221.76765-2-pvorel@suse.cz/

> > Changes v1->v2:
> > * Use environment variable instead of --conf-dir option (Joe Perches)
> > NOTE: I'd slightly prefer using --conf-dir (more convenient for user).

> Agreed.

I don't want to fight against Joe's NACK of v1 (unless he changes his mind).

> > * squash documentation into this commit

> > Kind regards,
> > Petr

> >  scripts/checkpatch.pl | 10 +++++++++-
> >  1 file changed, 9 insertions(+), 1 deletion(-)

> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index bec7930cdd66..e47fec115ee7 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,10 @@ Options:
> >    -h, --help, --version      display this help and exit

> >  When FILE is - read standard input.
> > +
> > +CONFIGURATION FILE
> > +Script searches for a configuration file $configuration_file in path:
> > +\$$env_config_dir:$def_configuration_dirs
> >  EOM

> >         exit($exitcode);
> > @@ -1531,8 +1537,10 @@ sub which {

> >  sub which_conf {
> >         my ($conf) = @_;
> > +       my $paths = $ENV{$env_config_dir} . ':' if exists($ENV{$env_config_dir});

> How about splitting it so that the variable cannot be undef ?

> my $paths = $def_configuration_dirs;
> $paths = "$ENV{$env_config_dir}:$paths" if exists($ENV{$env_config_dir});

+1, sure, thanks!

Kind regards,
Petr

> > +       $paths .= $def_configuration_dirs;

> > -       foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
> > +       foreach my $path (split(/:/, $paths)) {
> >                 if (-e "$path/$conf") {
> >                         return "$path/$conf";
> >                 }
> > --
> > 2.51.0

> Regards,
> Simon

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

* Re: [PATCH v2] checkpatch: Allow to pass config directory
  2026-03-26 20:50   ` Petr Vorel
@ 2026-03-27  0:06     ` Joe Perches
  2026-03-27  9:50       ` Petr Vorel
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2026-03-27  0:06 UTC (permalink / raw)
  To: Petr Vorel, Simon Glass
  Cc: linux-kernel, Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn,
	Kory Maincent, Tom Rini, Simon Glass, Kuan-Wei Chiu

On Thu, 2026-03-26 at 21:50 +0100, Petr Vorel wrote:

> > my $paths = $def_configuration_dirs;
> > $paths = "$ENV{$env_config_dir}:$paths" if exists($ENV{$env_config_dir});
> 
> +1, sure, thanks!

Why have two uses of $ENV{$env_config_dir}?
Seems typo error prone and somewhat difficult to read.

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

* Re: [PATCH v2] checkpatch: Allow to pass config directory
  2026-03-27  0:06     ` Joe Perches
@ 2026-03-27  9:50       ` Petr Vorel
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2026-03-27  9:50 UTC (permalink / raw)
  To: Joe Perches
  Cc: Simon Glass, linux-kernel, Andy Whitcroft, Dwaipayan Ray,
	Lukas Bulwahn, Kory Maincent, Tom Rini, Simon Glass,
	Kuan-Wei Chiu

> On Thu, 2026-03-26 at 21:50 +0100, Petr Vorel wrote:

> > > my $paths = $def_configuration_dirs;
> > > $paths = "$ENV{$env_config_dir}:$paths" if exists($ENV{$env_config_dir});

> > +1, sure, thanks!

> Why have two uses of $ENV{$env_config_dir}?

Your suggestion in v1 :).

> Seems typo error prone and somewhat difficult to read.

In v3 I'll just prepend it without checking, because we do the check later on
if (-e "$path/$conf").

And add a note that one can add more dirs (like in PATH or LD_LIBRARY_PATH).
But again, it looks to me more better to point just a single file.
Check would be done only on the directory to which variable points, that's what
would user probably want (not silently fallbacking into the default
directories). But that would require slightly more code changes.

Kind regards,
Petr

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

end of thread, other threads:[~2026-03-27  9:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24 18:16 [PATCH v2] checkpatch: Allow to pass config directory Petr Vorel
2026-03-26 15:47 ` Petr Vorel
2026-03-26 17:48 ` Simon Glass
2026-03-26 20:50   ` Petr Vorel
2026-03-27  0:06     ` Joe Perches
2026-03-27  9:50       ` Petr Vorel

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