diff options
author | Martin Roth <martinroth@google.com> | 2016-09-30 15:51:32 -0600 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2016-10-03 22:05:37 +0200 |
commit | fa95625867fa1f373e8c5d8ec160a65e50a3d5c2 (patch) | |
tree | 6262a95d63f90374ec5bb6a0cd25f1f9f9dc3f54 | |
parent | 3d6db6f0fac9efba4cca8652c4dd1d50f9af0372 (diff) |
util/lint/kconfig_lint: Check default types
The type of the default value wasn't being checked to make sure that it
matched the type of the Kconfig symbol.
This makes sure that the symbol is being set to either a reasonable
looking value or to another Kconfig symbol.
Change-Id: Ia01bd2d8b387f319d29f0a005d55cb8e20cd3853
Signed-off-by: Martin Roth <martinroth@google.com>
Reviewed-on: https://review.coreboot.org/16839
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
-rwxr-xr-x | util/lint/kconfig_lint | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/util/lint/kconfig_lint b/util/lint/kconfig_lint index c9553431f6..064f3db33f 100755 --- a/util/lint/kconfig_lint +++ b/util/lint/kconfig_lint @@ -329,10 +329,42 @@ sub check_defaults { next unless ( exists $symbols{$sym}{$sym_num}{default_max} ); for ( my $def_num = 0 ; $def_num <= $symbols{$sym}{$sym_num}{default_max} ; $def_num++ ) { + my $filename = $symbols{$sym}{$sym_num}{file}; + my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no}; + + # skip good defaults + 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 "string") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^".*"$/)) || + (($symbols{$sym}{type} eq "bool") && ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /^[yn]$/))) + ) { + + my ($checksym) = $symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /(\w+)/; + + if (! exists $symbols{$checksym}) { + + # verify the symbol type against the default value + if ($symbols{$sym}{type} eq "hex") { + show_error("non hex default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for hex symbol $sym at $filename:$line_no."); + } elsif ($symbols{$sym}{type} eq "int") { + show_error("non int default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for int symbol $sym at $filename:$line_no."); + } elsif ($symbols{$sym}{type} eq "string") { + # TODO: Remove special MAINBOARD_DIR check + if ($sym ne "MAINBOARD_DIR") { + show_error("no quotes around default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for string symbol $sym at $filename:$line_no."); + } + } elsif ($symbols{$sym}{type} eq "bool") { + if ($symbols{$sym}{$sym_num}{default}{$def_num}{default} =~ /[01YN]/) { + show_warning("default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) for bool symbol $sym uses value other than y/n at $filename:$line_no."); + } else { + show_error("non bool default value ($symbols{$sym}{$sym_num}{default}{$def_num}{default}) used for bool symbol $sym at $filename:$line_no."); + } + } + } + } + #if a default is already set, display an error if ($default_set) { - my $filename = $symbols{$sym}{$sym_num}{file}; - my $line_no = $symbols{$sym}{$sym_num}{default}{$def_num}{default_line_no}; show_warning( "Default for '$sym' referenced at $filename:$line_no will never be set" . " - overridden by default set at $default_filename:$default_line_no" ); } |