[coreboot-gerrit] New patch to review for coreboot: util/lint/kconfig_lint: Check default types

Martin Roth (martinroth@google.com) gerrit at coreboot.org
Fri Sep 30 23:59:03 CEST 2016


Martin Roth (martinroth at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16839

-gerrit

commit c771a1f56b57882ffd8fa5922ccab6eb2ef222fe
Author: Martin Roth <martinroth at google.com>
Date:   Fri Sep 30 15:51:32 2016 -0600

    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 at google.com>
---
 util/lint/kconfig_lint | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/util/lint/kconfig_lint b/util/lint/kconfig_lint
index c955343..064f3db 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" );
                 }



More information about the coreboot-gerrit mailing list