Skip to content

Commit c252147

Browse files
sravnborgmichal42
authored andcommitted
kconfig: refactor code in symbol.c
Move logic to determine default for a choice to a separate function. No functional changes. Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent 0748cb3 commit c252147

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

‎scripts/kconfig/lkc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void sym_init(void);
126126
void sym_clear_all_valid(void);
127127
void sym_set_all_changed(void);
128128
void sym_set_changed(struct symbol *sym);
129+
struct symbol *sym_choice_default(struct symbol *sym);
129130
struct symbol *sym_check_deps(struct symbol *sym);
130131
struct property *prop_alloc(enum prop_type type, struct symbol *sym);
131132
struct symbol *prop_get_symbol(struct property *prop);

‎scripts/kconfig/symbol.c‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,18 @@ static void sym_calc_visibility(struct symbol *sym)
226226
}
227227
}
228228

229-
static struct symbol *sym_calc_choice(struct symbol *sym)
229+
/*
230+
* Find the default symbol for a choice.
231+
* First try the default values for the choice symbol
232+
* Next locate the first visible choice value
233+
* Return NULL if none was found
234+
*/
235+
struct symbol *sym_choice_default(struct symbol *sym)
230236
{
231237
struct symbol *def_sym;
232238
struct property *prop;
233239
struct expr *e;
234240

235-
/* first calculate all choice values' visibilities */
236-
prop = sym_get_choice_prop(sym);
237-
expr_list_for_each_sym(prop->expr, e, def_sym)
238-
sym_calc_visibility(def_sym);
239-
240-
/* is the user choice visible? */
241-
def_sym = sym->def[S_DEF_USER].val;
242-
if (def_sym && def_sym->visible != no)
243-
return def_sym;
244-
245241
/* any of the defaults visible? */
246242
for_all_defaults(sym, prop) {
247243
prop->visible.tri = expr_calc_value(prop->visible.expr);
@@ -258,11 +254,35 @@ static struct symbol *sym_calc_choice(struct symbol *sym)
258254
if (def_sym->visible != no)
259255
return def_sym;
260256

261-
/* no choice? reset tristate value */
262-
sym->curr.tri = no;
257+
/* failed to locate any defaults */
263258
return NULL;
264259
}
265260

261+
static struct symbol *sym_calc_choice(struct symbol *sym)
262+
{
263+
struct symbol *def_sym;
264+
struct property *prop;
265+
struct expr *e;
266+
267+
/* first calculate all choice values' visibilities */
268+
prop = sym_get_choice_prop(sym);
269+
expr_list_for_each_sym(prop->expr, e, def_sym)
270+
sym_calc_visibility(def_sym);
271+
272+
/* is the user choice visible? */
273+
def_sym = sym->def[S_DEF_USER].val;
274+
if (def_sym && def_sym->visible != no)
275+
return def_sym;
276+
277+
def_sym = sym_choice_default(sym);
278+
279+
if (def_sym == NULL)
280+
/* no choice? reset tristate value */
281+
sym->curr.tri = no;
282+
283+
return def_sym;
284+
}
285+
266286
void sym_calc_value(struct symbol *sym)
267287
{
268288
struct symbol_value newval, oldval;

0 commit comments

Comments
 (0)