Skip to content

Commit 98f8475

Browse files
committed
kconfig: move conf_set_all_new_symbols() to conf.c
This function is only used in conf.c. Move it there together with the randomize_choice_values() helper. Define 'enum conf_def_mode' locally in conf.c as well. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent 15e68d0 commit 98f8475

File tree

3 files changed

+193
-187
lines changed

3 files changed

+193
-187
lines changed

scripts/kconfig/conf.c

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,199 @@ static void set_randconfig_seed(void)
112112
srand(seed);
113113
}
114114

115+
static bool randomize_choice_values(struct symbol *csym)
116+
{
117+
struct property *prop;
118+
struct symbol *sym;
119+
struct expr *e;
120+
int cnt, def;
121+
122+
/*
123+
* If choice is mod then we may have more items selected
124+
* and if no then no-one.
125+
* In both cases stop.
126+
*/
127+
if (csym->curr.tri != yes)
128+
return false;
129+
130+
prop = sym_get_choice_prop(csym);
131+
132+
/* count entries in choice block */
133+
cnt = 0;
134+
expr_list_for_each_sym(prop->expr, e, sym)
135+
cnt++;
136+
137+
/*
138+
* find a random value and set it to yes,
139+
* set the rest to no so we have only one set
140+
*/
141+
def = rand() % cnt;
142+
143+
cnt = 0;
144+
expr_list_for_each_sym(prop->expr, e, sym) {
145+
if (def == cnt++) {
146+
sym->def[S_DEF_USER].tri = yes;
147+
csym->def[S_DEF_USER].val = sym;
148+
} else {
149+
sym->def[S_DEF_USER].tri = no;
150+
}
151+
sym->flags |= SYMBOL_DEF_USER;
152+
/* clear VALID to get value calculated */
153+
sym->flags &= ~SYMBOL_VALID;
154+
}
155+
csym->flags |= SYMBOL_DEF_USER;
156+
/* clear VALID to get value calculated */
157+
csym->flags &= ~SYMBOL_VALID;
158+
159+
return true;
160+
}
161+
162+
enum conf_def_mode {
163+
def_default,
164+
def_yes,
165+
def_mod,
166+
def_y2m,
167+
def_m2y,
168+
def_no,
169+
def_random
170+
};
171+
172+
static bool conf_set_all_new_symbols(enum conf_def_mode mode)
173+
{
174+
struct symbol *sym, *csym;
175+
int i, cnt;
176+
/*
177+
* can't go as the default in switch-case below, otherwise gcc whines
178+
* about -Wmaybe-uninitialized
179+
*/
180+
int pby = 50; /* probability of bool = y */
181+
int pty = 33; /* probability of tristate = y */
182+
int ptm = 33; /* probability of tristate = m */
183+
bool has_changed = false;
184+
185+
if (mode == def_random) {
186+
int n, p[3];
187+
char *env = getenv("KCONFIG_PROBABILITY");
188+
189+
n = 0;
190+
while (env && *env) {
191+
char *endp;
192+
int tmp = strtol(env, &endp, 10);
193+
194+
if (tmp >= 0 && tmp <= 100) {
195+
p[n++] = tmp;
196+
} else {
197+
errno = ERANGE;
198+
perror("KCONFIG_PROBABILITY");
199+
exit(1);
200+
}
201+
env = (*endp == ':') ? endp + 1 : endp;
202+
if (n >= 3)
203+
break;
204+
}
205+
switch (n) {
206+
case 1:
207+
pby = p[0];
208+
ptm = pby / 2;
209+
pty = pby - ptm;
210+
break;
211+
case 2:
212+
pty = p[0];
213+
ptm = p[1];
214+
pby = pty + ptm;
215+
break;
216+
case 3:
217+
pby = p[0];
218+
pty = p[1];
219+
ptm = p[2];
220+
break;
221+
}
222+
223+
if (pty + ptm > 100) {
224+
errno = ERANGE;
225+
perror("KCONFIG_PROBABILITY");
226+
exit(1);
227+
}
228+
}
229+
230+
for_all_symbols(i, sym) {
231+
if (sym_has_value(sym) || sym->flags & SYMBOL_VALID)
232+
continue;
233+
switch (sym_get_type(sym)) {
234+
case S_BOOLEAN:
235+
case S_TRISTATE:
236+
has_changed = true;
237+
switch (mode) {
238+
case def_yes:
239+
sym->def[S_DEF_USER].tri = yes;
240+
break;
241+
case def_mod:
242+
sym->def[S_DEF_USER].tri = mod;
243+
break;
244+
case def_no:
245+
if (sym->flags & SYMBOL_ALLNOCONFIG_Y)
246+
sym->def[S_DEF_USER].tri = yes;
247+
else
248+
sym->def[S_DEF_USER].tri = no;
249+
break;
250+
case def_random:
251+
sym->def[S_DEF_USER].tri = no;
252+
cnt = rand() % 100;
253+
if (sym->type == S_TRISTATE) {
254+
if (cnt < pty)
255+
sym->def[S_DEF_USER].tri = yes;
256+
else if (cnt < pty + ptm)
257+
sym->def[S_DEF_USER].tri = mod;
258+
} else if (cnt < pby)
259+
sym->def[S_DEF_USER].tri = yes;
260+
break;
261+
default:
262+
continue;
263+
}
264+
if (!(sym_is_choice(sym) && mode == def_random))
265+
sym->flags |= SYMBOL_DEF_USER;
266+
break;
267+
default:
268+
break;
269+
}
270+
271+
}
272+
273+
sym_clear_all_valid();
274+
275+
/*
276+
* We have different type of choice blocks.
277+
* If curr.tri equals to mod then we can select several
278+
* choice symbols in one block.
279+
* In this case we do nothing.
280+
* If curr.tri equals yes then only one symbol can be
281+
* selected in a choice block and we set it to yes,
282+
* and the rest to no.
283+
*/
284+
if (mode != def_random) {
285+
for_all_symbols(i, csym) {
286+
if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
287+
sym_is_choice_value(csym))
288+
csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
289+
}
290+
}
291+
292+
for_all_symbols(i, csym) {
293+
if (sym_has_value(csym) || !sym_is_choice(csym))
294+
continue;
295+
296+
sym_calc_value(csym);
297+
if (mode == def_random)
298+
has_changed |= randomize_choice_values(csym);
299+
else {
300+
set_all_choice_values(csym);
301+
has_changed = true;
302+
}
303+
}
304+
305+
return has_changed;
306+
}
307+
115308
static void conf_rewrite_mod_or_yes(enum conf_def_mode mode)
116309
{
117310
struct symbol *sym;

scripts/kconfig/confdata.c

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,54 +1127,6 @@ void conf_set_changed_callback(void (*fn)(void))
11271127
conf_changed_callback = fn;
11281128
}
11291129

1130-
static bool randomize_choice_values(struct symbol *csym)
1131-
{
1132-
struct property *prop;
1133-
struct symbol *sym;
1134-
struct expr *e;
1135-
int cnt, def;
1136-
1137-
/*
1138-
* If choice is mod then we may have more items selected
1139-
* and if no then no-one.
1140-
* In both cases stop.
1141-
*/
1142-
if (csym->curr.tri != yes)
1143-
return false;
1144-
1145-
prop = sym_get_choice_prop(csym);
1146-
1147-
/* count entries in choice block */
1148-
cnt = 0;
1149-
expr_list_for_each_sym(prop->expr, e, sym)
1150-
cnt++;
1151-
1152-
/*
1153-
* find a random value and set it to yes,
1154-
* set the rest to no so we have only one set
1155-
*/
1156-
def = (rand() % cnt);
1157-
1158-
cnt = 0;
1159-
expr_list_for_each_sym(prop->expr, e, sym) {
1160-
if (def == cnt++) {
1161-
sym->def[S_DEF_USER].tri = yes;
1162-
csym->def[S_DEF_USER].val = sym;
1163-
}
1164-
else {
1165-
sym->def[S_DEF_USER].tri = no;
1166-
}
1167-
sym->flags |= SYMBOL_DEF_USER;
1168-
/* clear VALID to get value calculated */
1169-
sym->flags &= ~SYMBOL_VALID;
1170-
}
1171-
csym->flags |= SYMBOL_DEF_USER;
1172-
/* clear VALID to get value calculated */
1173-
csym->flags &= ~(SYMBOL_VALID);
1174-
1175-
return true;
1176-
}
1177-
11781130
void set_all_choice_values(struct symbol *csym)
11791131
{
11801132
struct property *prop;
@@ -1194,131 +1146,3 @@ void set_all_choice_values(struct symbol *csym)
11941146
/* clear VALID to get value calculated */
11951147
csym->flags &= ~(SYMBOL_VALID | SYMBOL_NEED_SET_CHOICE_VALUES);
11961148
}
1197-
1198-
bool conf_set_all_new_symbols(enum conf_def_mode mode)
1199-
{
1200-
struct symbol *sym, *csym;
1201-
int i, cnt, pby, pty, ptm; /* pby: probability of bool = y
1202-
* pty: probability of tristate = y
1203-
* ptm: probability of tristate = m
1204-
*/
1205-
1206-
pby = 50; pty = ptm = 33; /* can't go as the default in switch-case
1207-
* below, otherwise gcc whines about
1208-
* -Wmaybe-uninitialized */
1209-
if (mode == def_random) {
1210-
int n, p[3];
1211-
char *env = getenv("KCONFIG_PROBABILITY");
1212-
n = 0;
1213-
while( env && *env ) {
1214-
char *endp;
1215-
int tmp = strtol( env, &endp, 10 );
1216-
if( tmp >= 0 && tmp <= 100 ) {
1217-
p[n++] = tmp;
1218-
} else {
1219-
errno = ERANGE;
1220-
perror( "KCONFIG_PROBABILITY" );
1221-
exit( 1 );
1222-
}
1223-
env = (*endp == ':') ? endp+1 : endp;
1224-
if( n >=3 ) {
1225-
break;
1226-
}
1227-
}
1228-
switch( n ) {
1229-
case 1:
1230-
pby = p[0]; ptm = pby/2; pty = pby-ptm;
1231-
break;
1232-
case 2:
1233-
pty = p[0]; ptm = p[1]; pby = pty + ptm;
1234-
break;
1235-
case 3:
1236-
pby = p[0]; pty = p[1]; ptm = p[2];
1237-
break;
1238-
}
1239-
1240-
if( pty+ptm > 100 ) {
1241-
errno = ERANGE;
1242-
perror( "KCONFIG_PROBABILITY" );
1243-
exit( 1 );
1244-
}
1245-
}
1246-
bool has_changed = false;
1247-
1248-
for_all_symbols(i, sym) {
1249-
if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
1250-
continue;
1251-
switch (sym_get_type(sym)) {
1252-
case S_BOOLEAN:
1253-
case S_TRISTATE:
1254-
has_changed = true;
1255-
switch (mode) {
1256-
case def_yes:
1257-
sym->def[S_DEF_USER].tri = yes;
1258-
break;
1259-
case def_mod:
1260-
sym->def[S_DEF_USER].tri = mod;
1261-
break;
1262-
case def_no:
1263-
if (sym->flags & SYMBOL_ALLNOCONFIG_Y)
1264-
sym->def[S_DEF_USER].tri = yes;
1265-
else
1266-
sym->def[S_DEF_USER].tri = no;
1267-
break;
1268-
case def_random:
1269-
sym->def[S_DEF_USER].tri = no;
1270-
cnt = rand() % 100;
1271-
if (sym->type == S_TRISTATE) {
1272-
if (cnt < pty)
1273-
sym->def[S_DEF_USER].tri = yes;
1274-
else if (cnt < (pty+ptm))
1275-
sym->def[S_DEF_USER].tri = mod;
1276-
} else if (cnt < pby)
1277-
sym->def[S_DEF_USER].tri = yes;
1278-
break;
1279-
default:
1280-
continue;
1281-
}
1282-
if (!(sym_is_choice(sym) && mode == def_random))
1283-
sym->flags |= SYMBOL_DEF_USER;
1284-
break;
1285-
default:
1286-
break;
1287-
}
1288-
1289-
}
1290-
1291-
sym_clear_all_valid();
1292-
1293-
/*
1294-
* We have different type of choice blocks.
1295-
* If curr.tri equals to mod then we can select several
1296-
* choice symbols in one block.
1297-
* In this case we do nothing.
1298-
* If curr.tri equals yes then only one symbol can be
1299-
* selected in a choice block and we set it to yes,
1300-
* and the rest to no.
1301-
*/
1302-
if (mode != def_random) {
1303-
for_all_symbols(i, csym) {
1304-
if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
1305-
sym_is_choice_value(csym))
1306-
csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
1307-
}
1308-
}
1309-
1310-
for_all_symbols(i, csym) {
1311-
if (sym_has_value(csym) || !sym_is_choice(csym))
1312-
continue;
1313-
1314-
sym_calc_value(csym);
1315-
if (mode == def_random)
1316-
has_changed |= randomize_choice_values(csym);
1317-
else {
1318-
set_all_choice_values(csym);
1319-
has_changed = true;
1320-
}
1321-
}
1322-
1323-
return has_changed;
1324-
}

0 commit comments

Comments
 (0)