* [PATCH] kconfig: Warn if choice default is not in choice
@ 2017-10-03 23:25 Ulf Magnusson
2017-10-04 0:10 ` Ulf Magnusson
2017-12-07 14:50 ` Masahiro Yamada
0 siblings, 2 replies; 4+ messages in thread
From: Ulf Magnusson @ 2017-10-03 23:25 UTC (permalink / raw)
To: yann.morin.1998, linux-kbuild; +Cc: linux-kernel, arnd, Ulf Magnusson
This will catch mistakes like in the following real-world example, where
a "CONFIG_" prefix snuck in, making an undefined symbol the default:
choice
prompt "Compiler optimization level"
default CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
config CC_OPTIMIZE_FOR_PERFORMANCE
...
config CC_OPTIMIZE_FOR_SIZE
...
endchoice
This now prints the following warning:
init/Kconfig:1036:warning: choice default symbol 'CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE' is not contained in the choice
Cases where the default symbol belongs to the wrong choice are also
detected.
(The mistake is harmless here: Since the default symbol is not visible,
the choice falls back on using the first visible symbol as the default,
which is CC_OPTIMIZE_FOR_PERFORMANCE, as intended.)
Discovered while playing around with Kconfiglib
(https://github.com/ulfalizer/Kconfiglib).
Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
---
| 10 ++++++++++
1 file changed, 10 insertions(+)
--git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index e935793..ce88de8 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -252,6 +252,16 @@ static void sym_check_prop(struct symbol *sym)
"'%s': number is invalid",
sym->name);
}
+ if (sym_is_choice(sym)) {
+ struct property *choice_prop =
+ sym_get_choice_prop(sym2);
+
+ if (!choice_prop ||
+ prop_get_symbol(choice_prop) != sym)
+ prop_warn(prop,
+ "choice default symbol '%s' is not contained in the choice",
+ sym2->name);
+ }
break;
case P_SELECT:
case P_IMPLY:
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kconfig: Warn if choice default is not in choice
2017-10-03 23:25 [PATCH] kconfig: Warn if choice default is not in choice Ulf Magnusson
@ 2017-10-04 0:10 ` Ulf Magnusson
2017-10-05 3:12 ` Ulf Magnusson
2017-12-07 14:50 ` Masahiro Yamada
1 sibling, 1 reply; 4+ messages in thread
From: Ulf Magnusson @ 2017-10-04 0:10 UTC (permalink / raw)
To: yann.morin.1998, linux-kbuild; +Cc: linux-kernel, Arnd Bergmann, Ulf Magnusson
On Wed, Oct 4, 2017 at 1:25 AM, Ulf Magnusson <ulfalizer@gmail.com> wrote:
> This will catch mistakes like in the following real-world example, where
> a "CONFIG_" prefix snuck in, making an undefined symbol the default:
>
> choice
> prompt "Compiler optimization level"
> default CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
>
> config CC_OPTIMIZE_FOR_PERFORMANCE
> ...
>
> config CC_OPTIMIZE_FOR_SIZE
> ...
>
> endchoice
>
> This now prints the following warning:
>
> init/Kconfig:1036:warning: choice default symbol 'CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE' is not contained in the choice
>
> Cases where the default symbol belongs to the wrong choice are also
> detected.
>
> (The mistake is harmless here: Since the default symbol is not visible,
> the choice falls back on using the first visible symbol as the default,
> which is CC_OPTIMIZE_FOR_PERFORMANCE, as intended.)
>
> Discovered while playing around with Kconfiglib
> (https://github.com/ulfalizer/Kconfiglib).
>
> Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
> ---
> scripts/kconfig/menu.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
> index e935793..ce88de8 100644
> --- a/scripts/kconfig/menu.c
> +++ b/scripts/kconfig/menu.c
> @@ -252,6 +252,16 @@ static void sym_check_prop(struct symbol *sym)
> "'%s': number is invalid",
> sym->name);
> }
> + if (sym_is_choice(sym)) {
> + struct property *choice_prop =
> + sym_get_choice_prop(sym2);
> +
> + if (!choice_prop ||
> + prop_get_symbol(choice_prop) != sym)
> + prop_warn(prop,
> + "choice default symbol '%s' is not contained in the choice",
> + sym2->name);
> + }
> break;
> case P_SELECT:
> case P_IMPLY:
> --
> 2.7.4
>
A patch to fix the compiler optimization level choice has been
submitted as well:
https://lkml.org/lkml/2017/10/3/991
Cheers,
Ulf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kconfig: Warn if choice default is not in choice
2017-10-04 0:10 ` Ulf Magnusson
@ 2017-10-05 3:12 ` Ulf Magnusson
0 siblings, 0 replies; 4+ messages in thread
From: Ulf Magnusson @ 2017-10-05 3:12 UTC (permalink / raw)
To: yann.morin.1998, linux-kbuild
Cc: linux-kernel, Arnd Bergmann, Ulf Magnusson, Masahiro Yamada,
Arnaud Lacombe
On Wed, Oct 4, 2017 at 2:10 AM, Ulf Magnusson <ulfalizer@gmail.com> wrote:
> On Wed, Oct 4, 2017 at 1:25 AM, Ulf Magnusson <ulfalizer@gmail.com> wrote:
>> This will catch mistakes like in the following real-world example, where
>> a "CONFIG_" prefix snuck in, making an undefined symbol the default:
>>
>> choice
>> prompt "Compiler optimization level"
>> default CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
>>
>> config CC_OPTIMIZE_FOR_PERFORMANCE
>> ...
>>
>> config CC_OPTIMIZE_FOR_SIZE
>> ...
>>
>> endchoice
>>
>> This now prints the following warning:
>>
>> init/Kconfig:1036:warning: choice default symbol 'CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE' is not contained in the choice
>>
>> Cases where the default symbol belongs to the wrong choice are also
>> detected.
>>
>> (The mistake is harmless here: Since the default symbol is not visible,
>> the choice falls back on using the first visible symbol as the default,
>> which is CC_OPTIMIZE_FOR_PERFORMANCE, as intended.)
>>
>> Discovered while playing around with Kconfiglib
>> (https://github.com/ulfalizer/Kconfiglib).
>>
>> Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
>> ---
>> scripts/kconfig/menu.c | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
>> index e935793..ce88de8 100644
>> --- a/scripts/kconfig/menu.c
>> +++ b/scripts/kconfig/menu.c
>> @@ -252,6 +252,16 @@ static void sym_check_prop(struct symbol *sym)
>> "'%s': number is invalid",
>> sym->name);
>> }
>> + if (sym_is_choice(sym)) {
>> + struct property *choice_prop =
>> + sym_get_choice_prop(sym2);
>> +
>> + if (!choice_prop ||
>> + prop_get_symbol(choice_prop) != sym)
>> + prop_warn(prop,
>> + "choice default symbol '%s' is not contained in the choice",
>> + sym2->name);
>> + }
>> break;
>> case P_SELECT:
>> case P_IMPLY:
>> --
>> 2.7.4
>>
>
> A patch to fix the compiler optimization level choice has been
> submitted as well:
> https://lkml.org/lkml/2017/10/3/991
>
> Cheers,
> Ulf
Adding some CCs just because I forgot. No panic.
Cheers,
Ulf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kconfig: Warn if choice default is not in choice
2017-10-03 23:25 [PATCH] kconfig: Warn if choice default is not in choice Ulf Magnusson
2017-10-04 0:10 ` Ulf Magnusson
@ 2017-12-07 14:50 ` Masahiro Yamada
1 sibling, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2017-12-07 14:50 UTC (permalink / raw)
To: Ulf Magnusson
Cc: Yann E. MORIN, Linux Kbuild mailing list,
Linux Kernel Mailing List, Arnd Bergmann
2017-10-04 8:25 GMT+09:00 Ulf Magnusson <ulfalizer@gmail.com>:
> This will catch mistakes like in the following real-world example, where
> a "CONFIG_" prefix snuck in, making an undefined symbol the default:
>
> choice
> prompt "Compiler optimization level"
> default CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
>
> config CC_OPTIMIZE_FOR_PERFORMANCE
> ...
>
> config CC_OPTIMIZE_FOR_SIZE
> ...
>
> endchoice
>
> This now prints the following warning:
>
> init/Kconfig:1036:warning: choice default symbol 'CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE' is not contained in the choice
>
> Cases where the default symbol belongs to the wrong choice are also
> detected.
>
> (The mistake is harmless here: Since the default symbol is not visible,
> the choice falls back on using the first visible symbol as the default,
> which is CC_OPTIMIZE_FOR_PERFORMANCE, as intended.)
>
> Discovered while playing around with Kconfiglib
> (https://github.com/ulfalizer/Kconfiglib).
>
> Signed-off-by: Ulf Magnusson <ulfalizer@gmail.com>
> ---
Applied to linux-kbuild/kconfig.
Thanks!
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-12-07 14:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-03 23:25 [PATCH] kconfig: Warn if choice default is not in choice Ulf Magnusson
2017-10-04 0:10 ` Ulf Magnusson
2017-10-05 3:12 ` Ulf Magnusson
2017-12-07 14:50 ` Masahiro Yamada
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).