From 90fcffb416c6b104f7e8c32b8013f34ae7a55cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Niew=C3=B6hner?= Date: Thu, 16 Sep 2021 17:56:14 +0200 Subject: kconfig_lint: restrict definition of defaults for choice elements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Defining defaults for symbols used inside choices is not allowed. Add a check for this, so we can drop the existent, overly restrictive checks in the follow-up change. Change-Id: I45bce2633dbd168fceb81ceae9b68621b28526e8 Signed-off-by: Michael Niewöhner Reviewed-on: https://review.coreboot.org/c/coreboot/+/57715 Tested-by: build bot (Jenkins) Reviewed-by: Felix Singer Reviewed-by: Martin Roth --- util/lint/kconfig_lint | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'util') diff --git a/util/lint/kconfig_lint b/util/lint/kconfig_lint index 04c582a34e..7f26ef298f 100755 --- a/util/lint/kconfig_lint +++ b/util/lint/kconfig_lint @@ -371,6 +371,12 @@ sub check_defaults { # Make sure there's a type set for the symbol next if (!defined $symbols{$sym}{type}); + # Symbols created/used inside a choice must not have a default set. The default is set by the choice itself. + if ($symbols{$sym}{choice}) { + show_error("Defining a default for symbol '$sym' at $filename:$line_no, used inside choice at " + . "$symbols{$sym}{choice_loc}, is not allowed."); + } + # 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]+$/)) || @@ -798,6 +804,9 @@ sub add_symbol { $symbols{$symbol}{count} = 0; if ($inside_choice) { $symbols{$symbol}{choice} = 1; + + # remember the location of the choice + $symbols{$symbol}{choice_loc} = join(':', (split / /, $inside_choice)); } else { $symbols{$symbol}{choice} = 0; -- cgit v1.2.3