aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/confdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/confdata.c')
-rw-r--r--scripts/kconfig/confdata.c59
1 files changed, 55 insertions, 4 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 13ddf1126c2a..43eda40c3838 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -1106,10 +1106,54 @@ static void set_all_choice_values(struct symbol *csym)
1106void conf_set_all_new_symbols(enum conf_def_mode mode) 1106void conf_set_all_new_symbols(enum conf_def_mode mode)
1107{ 1107{
1108 struct symbol *sym, *csym; 1108 struct symbol *sym, *csym;
1109 int i, cnt; 1109 int i, cnt, pby, pty, ptm; /* pby: probability of boolean = y
1110 * pty: probability of tristate = y
1111 * ptm: probability of tristate = m
1112 */
1113
1114 pby = 50; pty = ptm = 33; /* can't go as the default in switch-case
1115 * below, otherwise gcc whines about
1116 * -Wmaybe-uninitialized */
1117 if (mode == def_random) {
1118 int n, p[3];
1119 char *env = getenv("KCONFIG_PROBABILITY");
1120 n = 0;
1121 while( env && *env ) {
1122 char *endp;
1123 int tmp = strtol( env, &endp, 10 );
1124 if( tmp >= 0 && tmp <= 100 ) {
1125 p[n++] = tmp;
1126 } else {
1127 errno = ERANGE;
1128 perror( "KCONFIG_PROBABILITY" );
1129 exit( 1 );
1130 }
1131 env = (*endp == ':') ? endp+1 : endp;
1132 if( n >=3 ) {
1133 break;
1134 }
1135 }
1136 switch( n ) {
1137 case 1:
1138 pby = p[0]; ptm = pby/2; pty = pby-ptm;
1139 break;
1140 case 2:
1141 pty = p[0]; ptm = p[1]; pby = pty + ptm;
1142 break;
1143 case 3:
1144 pby = p[0]; pty = p[1]; ptm = p[2];
1145 break;
1146 }
1147
1148 if( pty+ptm > 100 ) {
1149 errno = ERANGE;
1150 perror( "KCONFIG_PROBABILITY" );
1151 exit( 1 );
1152 }
1153 }
1110 1154
1111 for_all_symbols(i, sym) { 1155 for_all_symbols(i, sym) {
1112 if (sym_has_value(sym)) 1156 if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
1113 continue; 1157 continue;
1114 switch (sym_get_type(sym)) { 1158 switch (sym_get_type(sym)) {
1115 case S_BOOLEAN: 1159 case S_BOOLEAN:
@@ -1125,8 +1169,15 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
1125 sym->def[S_DEF_USER].tri = no; 1169 sym->def[S_DEF_USER].tri = no;
1126 break; 1170 break;
1127 case def_random: 1171 case def_random:
1128 cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2; 1172 sym->def[S_DEF_USER].tri = no;
1129 sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt); 1173 cnt = rand() % 100;
1174 if (sym->type == S_TRISTATE) {
1175 if (cnt < pty)
1176 sym->def[S_DEF_USER].tri = yes;
1177 else if (cnt < (pty+ptm))
1178 sym->def[S_DEF_USER].tri = mod;
1179 } else if (cnt < pby)
1180 sym->def[S_DEF_USER].tri = yes;
1130 break; 1181 break;
1131 default: 1182 default:
1132 continue; 1183 continue;