From 5b88301073cd8ff1da7f3f6514d6a091b23cd080 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Sun, 25 Jun 2017 20:27:36 -0600 Subject: 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 Reviewed-on: https://review.coreboot.org/20360 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Patrick Georgi Reviewed-by: Werner Zeh --- util/lint/kconfig_lint | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'util/lint') 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'" ); + } + } } } } -- cgit v1.2.3