From fa95625867fa1f373e8c5d8ec160a65e50a3d5c2 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Fri, 30 Sep 2016 15:51:32 -0600 Subject: 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 Reviewed-on: https://review.coreboot.org/16839 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- util/lint/kconfig_lint | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'util/lint/kconfig_lint') 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" ); } -- cgit v1.2.3