Skip to content

Commit 3e89ad8

Browse files
jforissiertorvalds
authored andcommitted
checkpatch: add --kconfig-prefix
Kconfig allows to customize the CONFIG_ prefix via the $CONFIG_ environment variable. Out-of-tree projects may therefore use Kconfig with a different prefix, or they may use a custom configuration tool which does not use the CONFIG_ prefix at all. Such projects may still want to adhere to the Linux kernel coding style and run checkpatch.pl. One example is OP-TEE [1] which does not use Kconfig but does have configuration options prefixed with CFG_. It also mostly follows the kernel coding style and therefore being able to use checkpatch is quite valuable. To make this possible, add the --kconfig-prefix command line option. [1] https://github.com/OP-TEE/optee_os Signed-off-by: Jerome Forissier <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Acked-by: Joe Perches <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 004fba1 commit 3e89ad8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/checkpatch.pl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
# git output parsing needs US English output, so first set backtick child process LANGUAGE
6666
my $git_command ='export LANGUAGE=en_US.UTF-8; git';
6767
my $tabsize = 8;
68+
my ${CONFIG_} = "CONFIG_";
6869

6970
sub help {
7071
my ($exitcode) = @_;
@@ -127,6 +128,8 @@ sub help {
127128
--typedefsfile Read additional types from this file
128129
--color[=WHEN] Use colors 'always', 'never', or only when output
129130
is a terminal ('auto'). Default is 'auto'.
131+
--kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default
132+
${CONFIG_})
130133
-h, --help, --version display this help and exit
131134
132135
When FILE is - read standard input.
@@ -235,6 +238,7 @@ sub list_types {
235238
'color=s' => \$color,
236239
'no-color' => \$color, #keep old behaviors of -nocolor
237240
'nocolor' => \$color, #keep old behaviors of -nocolor
241+
'kconfig-prefix=s' => \${CONFIG_},
238242
'h|help' => \$help,
239243
'version' => \$help
240244
) or help(1);
@@ -6524,16 +6528,16 @@ sub process {
65246528
}
65256529

65266530
# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
6527-
if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^CONFIG_/) {
6531+
if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) {
65286532
WARN("IS_ENABLED_CONFIG",
6529-
"IS_ENABLED($1) is normally used as IS_ENABLED(CONFIG_$1)\n" . $herecurr);
6533+
"IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
65306534
}
65316535

65326536
# check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
6533-
if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
6537+
if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
65346538
my $config = $1;
65356539
if (WARN("PREFER_IS_ENABLED",
6536-
"Prefer IS_ENABLED(<FOO>) to CONFIG_<FOO> || CONFIG_<FOO>_MODULE\n" . $herecurr) &&
6540+
"Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) &&
65376541
$fix) {
65386542
$fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
65396543
}

0 commit comments

Comments
 (0)