lint/kconfig_lint: Make sure all symbols have a type defined

Show an error if a symbol does not have a defined type.

This caused a problem of an undefined symbol in check_defaults, so
we just skip those symbols there as we can't verify the default pattern
without knowing the type.

Change-Id: I28711a77962e16f6fc89789400363edd0fdd0931
Signed-off-by: Martin Roth <martinroth@google.com>
Reviewed-on: https://review.coreboot.org/17345
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@googlemail.com>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Martin Roth 2016-11-09 14:27:00 -07:00
parent 1c9c4b8db8
commit 08705f1e90
2 changed files with 30 additions and 0 deletions

View File

@ -85,6 +85,7 @@ sub Main {
load_config($config_file) if ($config_file); load_config($config_file) if ($config_file);
check_type();
check_defaults(); check_defaults();
check_referenced_symbols(); check_referenced_symbols();
@ -272,6 +273,31 @@ sub check_for_def {
} }
} }
#-------------------------------------------------------------------------------
# check_type - Make sure that all symbols have a type defined.
#
# Conflicting types are found when parsing the Kconfig tree.
#-------------------------------------------------------------------------------
sub check_type {
# loop through each defined symbol
foreach my $sym ( sort ( keys %symbols ) ) {
# Make sure there's a type set for the symbol
if (!defined $symbols{$sym}{type}) {
#loop through each instance of that symbol
for ( my $sym_num = 0 ; $sym_num <= $symbols{$sym}{count} ; $sym_num++ ) {
my $filename = $symbols{$sym}{$sym_num}{file};
my $line_no = $symbols{$sym}{$sym_num}{line_no};
show_error("No type defined for symbol $sym defined at $filename:$line_no.");
}
}
}
}
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# check_is_enabled - The IS_ENABLED() macro is only valid for symbols of type # check_is_enabled - The IS_ENABLED() macro is only valid for symbols of type
# bool. It would probably work on type hex or int if the value was 0 or 1, but # bool. It would probably work on type hex or int if the value was 0 or 1, but
@ -333,6 +359,9 @@ sub check_defaults {
my $filename = $symbols{$sym}{$sym_num}{file}; my $filename = $symbols{$sym}{$sym_num}{file};
my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no}; my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no};
# Make sure there's a type set for the symbol
next if (!defined $symbols{$sym}{type});
# skip good defaults # skip good defaults
if (! ((($symbols{$sym}{type} eq "hex") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^0x/)) || if (! ((($symbols{$sym}{type} eq "hex") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^0x/)) ||
(($symbols{$sym}{type} eq "int") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[-0-9]+$/)) || (($symbols{$sym}{type} eq "int") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[-0-9]+$/)) ||

View File

@ -89,6 +89,7 @@ Errors in Kconfig that are also caught by Kconfig itself:
int in another location. int in another location.
- Type keywords (bool, int, hex, string) used outside of a config block. - Type keywords (bool, int, hex, string) used outside of a config block.
- Using a 'prompt' keyword not inside a config or choice block. - Using a 'prompt' keyword not inside a config or choice block.
- Symbols with no defined type.
Errors in coreboot source files: Errors in coreboot source files:
- The IS_ENABLED macro is only valid for bool symbols. - The IS_ENABLED macro is only valid for bool symbols.