public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 1/2] checkpatch: Allow passing config directory
@ 2026-04-17 17:03 Petr Vorel
  2026-04-17 17:03 ` [PATCH v5 2/2] checkpatch: Add option to not force /* */ for SPDX Petr Vorel
  2026-04-19 23:50 ` [PATCH v5 1/2] checkpatch: Allow passing config directory Simon Glass
  0 siblings, 2 replies; 6+ messages in thread
From: Petr Vorel @ 2026-04-17 17:03 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 add --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 help.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes in v5 (all by sashiko agent):
https://sashiko.dev/#/patchset/20260415143636.272605-1-pvorel%40suse.cz
* Move warning to don't wrongly warn  when $CHECKPATCH_CONFIG_DIR is not set
(sigh).

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/

 scripts/checkpatch.pl | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0492d6afc9a1f..8f7a42da12869 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', fallback to default locations: $!\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] 6+ messages in thread

* [PATCH v5 2/2] checkpatch: Add option to not force /* */ for SPDX
  2026-04-17 17:03 [PATCH v5 1/2] checkpatch: Allow passing config directory Petr Vorel
@ 2026-04-17 17:03 ` Petr Vorel
  2026-04-19 23:50   ` Simon Glass
  2026-04-19 23:50 ` [PATCH v5 1/2] checkpatch: Allow passing config directory Simon Glass
  1 sibling, 1 reply; 6+ messages in thread
From: Petr Vorel @ 2026-04-17 17:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: Petr Vorel, Joe Perches, Simon Glass, Dwaipayan Ray,
	Lukas Bulwahn

Add option --spdx-cxx-comments to not force C comments (/* */) for SPDX,
but allow also C++ comments (//).

As documented in aa19a176df95d6, this is required for some old
toolchains still have older assembler tools which cannot handle C++
style comments. This allows avoid forcing this for for projects which
vendored checkpatch.pl (e.g. LTP or u-boot).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes in v5 (all by sashiko agent):
https://sashiko.dev/#/patchset/20260415143636.272605-1-pvorel%40suse.cz
* Actually don't force // on --spdx-cxx-comments, still allow /* */ (sigh).
* Document --spdx-cxx-comments in Documentation/dev-tools/checkpatch.rst.

Link to v4:
https://lore.kernel.org/lkml/20260415143636.272605-2-pvorel@suse.cz/

Link to v3:
https://lore.kernel.org/lkml/20260408120603.54351-2-pvorel@suse.cz/

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

diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index dccede68698ca..ca48334b728a5 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -184,6 +184,13 @@ Available options:
    Override checking of perl version.  Runtime errors may be encountered after
    enabling this flag if the perl version does not meet the minimum specified.
 
+ - --spdx-cxx-comments
+
+   Don't force C comments ``\* \*/`` for SPDX license (required by old
+   toolchains), allow also C++ comments ``//``.
+
+   NOTE: it should *not* be used for Linux mainline.
+
  - --codespell
 
    Use the codespell dictionary for checking spelling errors.
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8f7a42da12869..8095b9b1c168a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -61,6 +61,7 @@ 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 $spdx_cxx_comments = 0;
 my $minimum_perl_version = 5.10.0;
 my $min_conf_desc_length = 4;
 my $spelling_file = "$D/spelling.txt";
@@ -137,6 +138,10 @@ Options:
                              file.  It's your fault if there's no backup or git
   --ignore-perl-version      override checking of perl version.  expect
                              runtime errors.
+  --spdx-cxx-comments        don't force C comments (/* */) for SPDX license
+                             (required by old toolchains), allow also C++
+                             comments (//).
+                             NOTE: it should *not* be used for Linux mainline.
   --codespell                Use the codespell dictionary for spelling/typos
                              (default:$codespellfile)
   --codespellfile            Use this codespell dictionary
@@ -346,6 +351,7 @@ GetOptions(
 	'fix!'		=> \$fix,
 	'fix-inplace!'	=> \$fix_inplace,
 	'ignore-perl-version!' => \$ignore_perl_version,
+	'spdx-cxx-comments!' => \$spdx_cxx_comments,
 	'debug=s'	=> \%debug,
 	'test-only=s'	=> \$tst_only,
 	'codespell!'	=> \$codespell,
@@ -3814,26 +3820,33 @@ sub process {
 				$checklicenseline = 2;
 			} elsif ($rawline =~ /^\+/) {
 				my $comment = "";
-				if ($realfile =~ /\.(h|s|S)$/) {
-					$comment = '/*';
-				} elsif ($realfile =~ /\.(c|rs|dts|dtsi)$/) {
+				if ($realfile =~ /\.(c|rs|dts|dtsi)$/) {
 					$comment = '//';
 				} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) {
 					$comment = '#';
 				} elsif ($realfile =~ /\.rst$/) {
 					$comment = '..';
 				}
+				my $pattern = qr{$comment};
+				if ($realfile =~ /\.(h|s|S)$/) {
+					$comment = '/*';
+					$pattern = qr{/\*};
+					if ($spdx_cxx_comments) {
+						$comment = '// or /*';
+						$pattern = qr{//|/\*};
+					}
+				}
 
 # check SPDX comment style for .[chsS] files
 				if ($realfile =~ /\.[chsS]$/ &&
 				    $rawline =~ /SPDX-License-Identifier:/ &&
-				    $rawline !~ m@^\+\s*\Q$comment\E\s*@) {
+				    $rawline !~ m@^\+\s*$pattern\s*@) {
 					WARN("SPDX_LICENSE_TAG",
 					     "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
 				}
 
 				if ($comment !~ /^$/ &&
-				    $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
+				    $rawline !~ m@^\+$pattern SPDX-License-Identifier: @) {
 					WARN("SPDX_LICENSE_TAG",
 					     "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
 				} elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
-- 
2.53.0


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

* Re: [PATCH v5 1/2] checkpatch: Allow passing config directory
  2026-04-17 17:03 [PATCH v5 1/2] checkpatch: Allow passing config directory Petr Vorel
  2026-04-17 17:03 ` [PATCH v5 2/2] checkpatch: Add option to not force /* */ for SPDX Petr Vorel
@ 2026-04-19 23:50 ` Simon Glass
  2026-04-20 13:04   ` Petr Vorel
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Glass @ 2026-04-19 23:50 UTC (permalink / raw)
  To: Petr Vorel; +Cc: linux-kernel, Joe Perches, Dwaipayan Ray, Lukas Bulwahn

Hi Petr,

On Sat, 18 Apr 2026 at 05:04, Petr Vorel <pvorel@suse.cz> wrote:
>
> 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 add --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 help.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Changes in v5 (all by sashiko agent):
> https://sashiko.dev/#/patchset/20260415143636.272605-1-pvorel%40suse.cz
> * Move warning to don't wrongly warn  when $CHECKPATCH_CONFIG_DIR is not set
> (sigh).
>
> 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/
>
>  scripts/checkpatch.pl | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 0492d6afc9a1f..8f7a42da12869 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', fallback to default locations: $!\n";

Just some optional nits

I think you should drop the $! as the errno might be stale here.

'falling back to' would read better

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

Reviewed-by: Simon Glass <sjg@chromium.org>

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

* Re: [PATCH v5 2/2] checkpatch: Add option to not force /* */ for SPDX
  2026-04-17 17:03 ` [PATCH v5 2/2] checkpatch: Add option to not force /* */ for SPDX Petr Vorel
@ 2026-04-19 23:50   ` Simon Glass
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2026-04-19 23:50 UTC (permalink / raw)
  To: Petr Vorel; +Cc: linux-kernel, Joe Perches, Dwaipayan Ray, Lukas Bulwahn

Hi Petr,

On Sat, 18 Apr 2026 at 05:04, Petr Vorel <pvorel@suse.cz> wrote:
>
> Add option --spdx-cxx-comments to not force C comments (/* */) for SPDX,
> but allow also C++ comments (//).
>
> As documented in aa19a176df95d6, this is required for some old
> toolchains still have older assembler tools which cannot handle C++
> style comments. This allows avoid forcing this for for projects which

one 'for'
This avoids forcing...

> vendored checkpatch.pl (e.g. LTP or u-boot).
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> Changes in v5 (all by sashiko agent):
> https://sashiko.dev/#/patchset/20260415143636.272605-1-pvorel%40suse.cz
> * Actually don't force // on --spdx-cxx-comments, still allow /* */ (sigh).
> * Document --spdx-cxx-comments in Documentation/dev-tools/checkpatch.rst.
>
> Link to v4:
> https://lore.kernel.org/lkml/20260415143636.272605-2-pvorel@suse.cz/
>
> Link to v3:
> https://lore.kernel.org/lkml/20260408120603.54351-2-pvorel@suse.cz/
>
>  Documentation/dev-tools/checkpatch.rst |  7 +++++++
>  scripts/checkpatch.pl                  | 23 ++++++++++++++++++-----
>  2 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
> index dccede68698ca..ca48334b728a5 100644
> --- a/Documentation/dev-tools/checkpatch.rst
> +++ b/Documentation/dev-tools/checkpatch.rst
> @@ -184,6 +184,13 @@ Available options:
>     Override checking of perl version.  Runtime errors may be encountered after
>     enabling this flag if the perl version does not meet the minimum specified.
>
> + - --spdx-cxx-comments
> +
> +   Don't force C comments ``\* \*/`` for SPDX license (required by old
> +   toolchains), allow also C++ comments ``//``.
> +
> +   NOTE: it should *not* be used for Linux mainline.
> +
>   - --codespell
>
>     Use the codespell dictionary for checking spelling errors.
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 8f7a42da12869..8095b9b1c168a 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -61,6 +61,7 @@ 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 $spdx_cxx_comments = 0;
>  my $minimum_perl_version = 5.10.0;
>  my $min_conf_desc_length = 4;
>  my $spelling_file = "$D/spelling.txt";
> @@ -137,6 +138,10 @@ Options:
>                               file.  It's your fault if there's no backup or git
>    --ignore-perl-version      override checking of perl version.  expect
>                               runtime errors.
> +  --spdx-cxx-comments        don't force C comments (/* */) for SPDX license
> +                             (required by old toolchains), allow also C++
> +                             comments (//).
> +                             NOTE: it should *not* be used for Linux mainline.
>    --codespell                Use the codespell dictionary for spelling/typos
>                               (default:$codespellfile)
>    --codespellfile            Use this codespell dictionary
> @@ -346,6 +351,7 @@ GetOptions(
>         'fix!'          => \$fix,
>         'fix-inplace!'  => \$fix_inplace,
>         'ignore-perl-version!' => \$ignore_perl_version,
> +       'spdx-cxx-comments!' => \$spdx_cxx_comments,
>         'debug=s'       => \%debug,
>         'test-only=s'   => \$tst_only,
>         'codespell!'    => \$codespell,
> @@ -3814,26 +3820,33 @@ sub process {
>                                 $checklicenseline = 2;
>                         } elsif ($rawline =~ /^\+/) {
>                                 my $comment = "";
> -                               if ($realfile =~ /\.(h|s|S)$/) {
> -                                       $comment = '/*';
> -                               } elsif ($realfile =~ /\.(c|rs|dts|dtsi)$/) {
> +                               if ($realfile =~ /\.(c|rs|dts|dtsi)$/) {
>                                         $comment = '//';
>                                 } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) {
>                                         $comment = '#';
>                                 } elsif ($realfile =~ /\.rst$/) {
>                                         $comment = '..';
>                                 }
> +                               my $pattern = qr{$comment};

nit: if $comment is '..' then this pattern matches any two characters
so for example this line would pass:

+ XY SPDX-License-Identifier: ...

You could do something like: my $pattern = qr{\Q$comment\E};

> +                               if ($realfile =~ /\.(h|s|S)$/) {
> +                                       $comment = '/*';
> +                                       $pattern = qr{/\*};
> +                                       if ($spdx_cxx_comments) {
> +                                               $comment = '// or /*';
> +                                               $pattern = qr{//|/\*};
> +                                       }
> +                               }
>
>  # check SPDX comment style for .[chsS] files
>                                 if ($realfile =~ /\.[chsS]$/ &&
>                                     $rawline =~ /SPDX-License-Identifier:/ &&
> -                                   $rawline !~ m@^\+\s*\Q$comment\E\s*@) {
> +                                   $rawline !~ m@^\+\s*$pattern\s*@) {
>                                         WARN("SPDX_LICENSE_TAG",
>                                              "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
>                                 }
>
>                                 if ($comment !~ /^$/ &&
> -                                   $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
> +                                   $rawline !~ m@^\+$pattern SPDX-License-Identifier: @) {
>                                         WARN("SPDX_LICENSE_TAG",
>                                              "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
>                                 } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
> --
> 2.53.0
>

Reviewed-by: Simon Glass <sjg@chromium.org>

Regards,
Simon

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

* Re: [PATCH v5 1/2] checkpatch: Allow passing config directory
  2026-04-19 23:50 ` [PATCH v5 1/2] checkpatch: Allow passing config directory Simon Glass
@ 2026-04-20 13:04   ` Petr Vorel
  2026-04-20 19:32     ` Simon Glass
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Vorel @ 2026-04-20 13:04 UTC (permalink / raw)
  To: Simon Glass; +Cc: linux-kernel, Joe Perches, Dwaipayan Ray, Lukas Bulwahn

> Hi Petr,

> On Sat, 18 Apr 2026 at 05:04, Petr Vorel <pvorel@suse.cz> wrote:

> > 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 add --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 help.

> > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > Changes in v5 (all by sashiko agent):
> > https://sashiko.dev/#/patchset/20260415143636.272605-1-pvorel%40suse.cz
> > * Move warning to don't wrongly warn  when $CHECKPATCH_CONFIG_DIR is not set
> > (sigh).

> > 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/

> >  scripts/checkpatch.pl | 19 ++++++++++++++++---
> >  1 file changed, 16 insertions(+), 3 deletions(-)

> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 0492d6afc9a1f..8f7a42da12869 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', fallback to default locations: $!\n";

> Just some optional nits

> I think you should drop the $! as the errno might be stale here.

> 'falling back to' would read better

+1

> > +       }

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


> Reviewed-by: Simon Glass <sjg@chromium.org>

At this point I dare to add your RBT in next version.

Kind regards,
Petr

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

* Re: [PATCH v5 1/2] checkpatch: Allow passing config directory
  2026-04-20 13:04   ` Petr Vorel
@ 2026-04-20 19:32     ` Simon Glass
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Glass @ 2026-04-20 19:32 UTC (permalink / raw)
  To: Petr Vorel; +Cc: linux-kernel, Joe Perches, Dwaipayan Ray, Lukas Bulwahn

Hi Petr,

On Tue, 21 Apr 2026 at 01:04, Petr Vorel <pvorel@suse.cz> wrote:
>
> > Hi Petr,
>
> > On Sat, 18 Apr 2026 at 05:04, Petr Vorel <pvorel@suse.cz> wrote:
>
> > > 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 add --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 help.
>
> > > Signed-off-by: Petr Vorel <pvorel@suse.cz>
> > > ---
> > > Changes in v5 (all by sashiko agent):
> > > https://sashiko.dev/#/patchset/20260415143636.272605-1-pvorel%40suse.cz
> > > * Move warning to don't wrongly warn  when $CHECKPATCH_CONFIG_DIR is not set
> > > (sigh).
>
> > > 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/
>
> > >  scripts/checkpatch.pl | 19 ++++++++++++++++---
> > >  1 file changed, 16 insertions(+), 3 deletions(-)
>
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > > index 0492d6afc9a1f..8f7a42da12869 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', fallback to default locations: $!\n";
>
> > Just some optional nits
>
> > I think you should drop the $! as the errno might be stale here.
>
> > 'falling back to' would read better
>
> +1
>
> > > +       }
>
> > > -       foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
> > > +       foreach my $path (split(/:/, $paths)) {
> > >                 if (-e "$path/$conf") {
> > >                         return "$path/$conf";
> > >                 }
> > > --
> > > 2.53.0
>
>
> > Reviewed-by: Simon Glass <sjg@chromium.org>
>
> At this point I dare to add your RBT in next version.

Thanks :-) These are really just nits.

Regards,
Simon

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

end of thread, other threads:[~2026-04-20 19:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-17 17:03 [PATCH v5 1/2] checkpatch: Allow passing config directory Petr Vorel
2026-04-17 17:03 ` [PATCH v5 2/2] checkpatch: Add option to not force /* */ for SPDX Petr Vorel
2026-04-19 23:50   ` Simon Glass
2026-04-19 23:50 ` [PATCH v5 1/2] checkpatch: Allow passing config directory Simon Glass
2026-04-20 13:04   ` Petr Vorel
2026-04-20 19:32     ` Simon Glass

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