Skip to content

Commit 6a12158

Browse files
committed
kconfig: remove 'optional' property support
The 'choice' statement is primarily used to exclusively select one option, but the 'optional' property allows all entries to be disabled. In the following example, both A and B can be disabled simultaneously: choice prompt "choose A, B, or nothing" optional config A bool "A" config B bool "B" endchoice You can achieve the equivalent outcome by other means. A common solution is to add another option to guard the choice block. In the following example, you can set ENABLE_A_B_CHOICE=n to disable the entire choice block: choice prompt "choose A or B" depends on ENABLE_A_B_CHOICE config A bool "A" config B bool "B" endchoice Another approach is to insert one more entry: choice prompt "choose A, B, or disable both" config A bool "A" config B bool "B" config DISABLE_A_AND_B bool "choose this to disable both A and B" endchoice Some real examples are DEBUG_INFO_NONE, INITRAMFS_COMPRESSION_NONE, LTO_NONE, etc. The 'optional' property is even more unnecessary for a tristate choice. Without the 'optional' property, you can disable A and B; you can set 'm' in the choice prompt, and disable A and B individually: choice prompt "choose one built-in or make them modular" config A tristate "A" config B tristate "B" endchoice In conclusion, the 'optional' property was unneeded. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <n.schier@avm.de>
1 parent d9a1dab commit 6a12158

15 files changed

Lines changed: 5 additions & 78 deletions

Documentation/kbuild/kconfig-language.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,6 @@ to be set to 'm'. This can be used if multiple drivers for a single
410410
hardware exists and only a single driver can be compiled/loaded into
411411
the kernel, but all drivers can be compiled as modules.
412412

413-
A choice accepts another option "optional", which allows to set the
414-
choice to 'n' and no entry needs to be selected.
415-
416413
comment::
417414

418415
"comment" <prompt>

scripts/kconfig/confdata.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,17 +810,14 @@ int conf_write_defconfig(const char *filename)
810810
/*
811811
* If symbol is a choice value and equals to the
812812
* default for a choice - skip.
813-
* But only if value is bool and equal to "y" and
814-
* choice is not "optional".
815-
* (If choice is "optional" then all values can be "n")
816813
*/
817814
if (sym_is_choice_value(sym)) {
818815
struct symbol *cs;
819816
struct symbol *ds;
820817

821818
cs = prop_get_symbol(sym_get_choice_prop(sym));
822819
ds = sym_choice_default(cs);
823-
if (!sym_is_optional(cs) && sym == ds) {
820+
if (sym == ds) {
824821
if ((sym->type == S_BOOLEAN) &&
825822
sym_get_tristate_value(sym) == yes)
826823
continue;

scripts/kconfig/expr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ struct symbol {
132132
#define SYMBOL_CHECK 0x0008 /* used during dependency checking */
133133
#define SYMBOL_CHOICEVAL 0x0020 /* used as a value in a choice block */
134134
#define SYMBOL_VALID 0x0080 /* set when symbol.curr is calculated */
135-
#define SYMBOL_OPTIONAL 0x0100 /* choice is optional - values can be 'n' */
136135
#define SYMBOL_WRITE 0x0200 /* write symbol to file (KCONFIG_CONFIG) */
137136
#define SYMBOL_CHANGED 0x0400 /* ? */
138137
#define SYMBOL_WRITTEN 0x0800 /* track info to avoid double-write to .config */

scripts/kconfig/gconf.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ static const char *dbg_sym_flags(int val)
8787
strcat(buf, "choiceval/");
8888
if (val & SYMBOL_VALID)
8989
strcat(buf, "valid/");
90-
if (val & SYMBOL_OPTIONAL)
91-
strcat(buf, "optional/");
9290
if (val & SYMBOL_WRITE)
9391
strcat(buf, "write/");
9492
if (val & SYMBOL_CHANGED)

scripts/kconfig/lexer.l

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ n [A-Za-z0-9_-]
120120
"menuconfig" return T_MENUCONFIG;
121121
"modules" return T_MODULES;
122122
"on" return T_ON;
123-
"optional" return T_OPTIONAL;
124123
"prompt" return T_PROMPT;
125124
"range" return T_RANGE;
126125
"select" return T_SELECT;

scripts/kconfig/lkc.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ static inline bool sym_is_choice_value(struct symbol *sym)
138138
return sym->flags & SYMBOL_CHOICEVAL ? true : false;
139139
}
140140

141-
static inline bool sym_is_optional(struct symbol *sym)
142-
{
143-
return sym->flags & SYMBOL_OPTIONAL ? true : false;
144-
}
145-
146141
static inline bool sym_has_value(struct symbol *sym)
147142
{
148143
return sym->flags & SYMBOL_DEF_USER ? true : false;

scripts/kconfig/menu.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,11 @@ static void _menu_finalize(struct menu *parent, bool inside_choice)
593593
}
594594

595595
/*
596-
* For non-optional choices, add a reverse dependency (corresponding to
597-
* a select) of '<visibility> && m'. This prevents the user from
598-
* setting the choice mode to 'n' when the choice is visible.
599-
*
600-
* This would also work for non-choice symbols, but only non-optional
601-
* choices clear SYMBOL_OPTIONAL as of writing. Choices are implemented
602-
* as a type of symbol.
596+
* For choices, add a reverse dependency (corresponding to a select) of
597+
* '<visibility> && m'. This prevents the user from setting the choice
598+
* mode to 'n' when the choice is visible.
603599
*/
604-
if (sym && !sym_is_optional(sym) && parent->prompt) {
600+
if (sym && sym_is_choice(sym) && parent->prompt) {
605601
sym->rev_dep.expr = expr_alloc_or(sym->rev_dep.expr,
606602
expr_alloc_and(parent->prompt->visible.expr,
607603
expr_alloc_symbol(&symbol_mod)));

scripts/kconfig/parser.y

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ struct menu *current_menu, *current_entry;
6969
%token T_MODULES
7070
%token T_ON
7171
%token T_OPEN_PAREN
72-
%token T_OPTIONAL
7372
%token T_PLUS_EQUAL
7473
%token T_PROMPT
7574
%token T_RANGE
@@ -140,7 +139,6 @@ stmt_list_in_choice:
140139

141140
config_entry_start: T_CONFIG nonconst_symbol T_EOL
142141
{
143-
$2->flags |= SYMBOL_OPTIONAL;
144142
menu_add_entry($2);
145143
printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name);
146144
};
@@ -152,7 +150,6 @@ config_stmt: config_entry_start config_option_list
152150

153151
menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
154152
{
155-
$2->flags |= SYMBOL_OPTIONAL;
156153
menu_add_entry($2);
157154
printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name);
158155
};
@@ -272,12 +269,6 @@ choice_option: logic_type prompt_stmt_opt T_EOL
272269
printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1);
273270
};
274271

275-
choice_option: T_OPTIONAL T_EOL
276-
{
277-
current_entry->sym->flags |= SYMBOL_OPTIONAL;
278-
printd(DEBUG_PARSE, "%s:%d:optional\n", cur_filename, cur_lineno);
279-
};
280-
281272
choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
282273
{
283274
menu_add_symbol(P_DEFAULT, $2, $3);

scripts/kconfig/tests/choice/Kconfig

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ config BOOL_CHOICE1
1717

1818
endchoice
1919

20-
choice
21-
prompt "optional boolean choice"
22-
optional
23-
default OPT_BOOL_CHOICE1
24-
25-
config OPT_BOOL_CHOICE0
26-
bool "choice 0"
27-
28-
config OPT_BOOL_CHOICE1
29-
bool "choice 1"
30-
31-
endchoice
32-
3320
choice
3421
prompt "tristate choice"
3522
default TRI_CHOICE1
@@ -41,16 +28,3 @@ config TRI_CHOICE1
4128
tristate "choice 1"
4229

4330
endchoice
44-
45-
choice
46-
prompt "optional tristate choice"
47-
optional
48-
default OPT_TRI_CHOICE1
49-
50-
config OPT_TRI_CHOICE0
51-
tristate "choice 0"
52-
53-
config OPT_TRI_CHOICE1
54-
tristate "choice 1"
55-
56-
endchoice

scripts/kconfig/tests/choice/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
77
The behavior of 'y' choice is intuitive. If choice values are tristate,
88
the choice can be 'm' where each value can be enabled independently.
9-
Also, if a choice is marked as 'optional', the whole choice can be
10-
invisible.
119
"""
1210

1311

0 commit comments

Comments
 (0)