summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Roth <martinroth@google.com>2017-06-25 20:27:36 -0600
committerMartin Roth <martinroth@google.com>2017-07-18 19:08:42 +0000
commit5b88301073cd8ff1da7f3f6514d6a091b23cd080 (patch)
tree59e6063c82882d2cfe9f90252f0b0f6397c1b811
parent48f96739edbe8d532e0d74c32e11fe422d44e02c (diff)
downloadcoreboot-5b88301073cd8ff1da7f3f6514d6a091b23cd080.tar.xz
util/lint: update kconfig_lint
* Add check for '#if defined' as well as #ifdef * Add check for IS_ENABLED() around bools in #if statements. * Fix an incomplete comment. Change-Id: I0787eab80ae64f59664fb53f395389bf5ac2a067 Signed-off-by: Martin Roth <martinroth@google.com> Reviewed-on: https://review.coreboot.org/20360 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Patrick Georgi <pgeorgi@google.com> Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
-rwxr-xr-xutil/lint/kconfig_lint35
1 files changed, 33 insertions, 2 deletions
diff --git a/util/lint/kconfig_lint b/util/lint/kconfig_lint
index bf8f70a33e..fb8e60f8a5 100755
--- a/util/lint/kconfig_lint
+++ b/util/lint/kconfig_lint
@@ -193,7 +193,16 @@ sub check_for_ifdef {
#look for #ifdef SYMBOL
while ( my $line = shift @ifdef_symbols ) {
- if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s+CONFIG_(\w+)/ ) {
+ if ( $line =~ /^([^:]+):(\d+):\s*#\s*ifn?def\s*\(?\s*CONFIG_(\w+)/ ) {
+ my $file = $1;
+ my $lineno = $2;
+ my $symbol = $3;
+
+ if ( ( exists $symbols{$symbol} ) && ( $symbols{$symbol}{type} ne "string" ) ) {
+ show_warning( "#ifdef 'CONFIG_$symbol' used at $file:$lineno."
+ . " Symbols of type '$symbols{$symbol}{type}' are always defined." );
+ }
+ } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*if\s+!?\s*defined\s*\(?\s*CONFIG_(\w+)/ ) {
my $file = $1;
my $lineno = $2;
my $symbol = $3;
@@ -320,7 +329,7 @@ sub check_is_enabled {
my $symbol = $2;
$line = $1 . $3;
- #make sure that
+ #make sure that the type is bool
if ( exists $symbols{$symbol} ) {
if ( $symbols{$symbol}{type} ne "bool" ) {
show_error( "IS_ENABLED(CONFIG_$symbol) used at $file:$lineno."
@@ -331,6 +340,28 @@ sub check_is_enabled {
show_error("IS_ENABLED() used on unknown value CONFIG_$symbol at $file:$lineno.");
}
}
+ } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?.*?$/ ) {
+ my $file = $1;
+ my $lineno = $2;
+ my $symbol = $3;
+ # If the type is bool, give a warning that IS_ENABLED should be used
+ if ( exists $symbols{$symbol} ) {
+ if ( $symbols{$symbol}{type} eq "bool" ) {
+ show_error( "#if CONFIG_$symbol used at $file:$lineno."
+ . " IS_ENABLED should be used for type 'bool'" );
+ }
+ }
+ } elsif ( $line =~ /^([^:]+):(\d+):\s*#\s*(?:el)?if.*(?:&&|\|\|)\s+!?\s*\(?\s*CONFIG_(\w+)\)?(\s*==\s*1)?$/ ) {
+ my $file = $1;
+ my $lineno = $2;
+ my $symbol = $3;
+ # If the type is bool, give a warning that IS_ENABLED should be used
+ if ( exists $symbols{$symbol} ) {
+ if ( $symbols{$symbol}{type} eq "bool" ) {
+ show_error( "#if CONFIG_$symbol used at $file:$lineno."
+ . " IS_ENABLED should be used for type 'bool'" );
+ }
+ }
}
}
}