Merge branch 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild-2.6

* 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild-2.6:
kconfig: Fix warning: ignoring return value of 'fgets'
kconfig: Fix warning: ignoring return value of 'fwrite'
nconfig: Fix segfault when menu is empty
kconfig: fix tristate choice with minimal config
kconfig: fix savedefconfig for tristate choices

+97 -43
+13 -2
scripts/kconfig/conf.c
··· 108 108 check_stdin(); 109 109 case oldaskconfig: 110 110 fflush(stdout); 111 - fgets(line, 128, stdin); 111 + xfgets(line, 128, stdin); 112 112 return 1; 113 113 default: 114 114 break; ··· 306 306 check_stdin(); 307 307 case oldaskconfig: 308 308 fflush(stdout); 309 - fgets(line, 128, stdin); 309 + xfgets(line, 128, stdin); 310 310 strip(line); 311 311 if (line[0] == '?') { 312 312 print_help(menu); ··· 643 643 } 644 644 } 645 645 return 0; 646 + } 647 + /* 648 + * Helper function to facilitate fgets() by Jean Sacren. 649 + */ 650 + void xfgets(str, size, in) 651 + char *str; 652 + int size; 653 + FILE *in; 654 + { 655 + if (fgets(str, size, in) == NULL) 656 + fprintf(stderr, "\nError in reading or end of file.\n"); 646 657 }
+71 -40
scripts/kconfig/confdata.c
··· 412 412 while (1) { 413 413 l = strcspn(str, "\"\\"); 414 414 if (l) { 415 - fwrite(str, l, 1, out); 415 + xfwrite(str, l, 1, out); 416 416 str += l; 417 417 } 418 418 if (!*str) ··· 497 497 /* 498 498 * If symbol is a choice value and equals to the 499 499 * default for a choice - skip. 500 - * But only if value equal to "y". 500 + * But only if value is bool and equal to "y" . 501 501 */ 502 502 if (sym_is_choice_value(sym)) { 503 503 struct symbol *cs; ··· 506 506 cs = prop_get_symbol(sym_get_choice_prop(sym)); 507 507 ds = sym_choice_default(cs); 508 508 if (sym == ds) { 509 - if ((sym->type == S_BOOLEAN || 510 - sym->type == S_TRISTATE) && 511 - sym_get_tristate_value(sym) == yes) 509 + if ((sym->type == S_BOOLEAN) && 510 + sym_get_tristate_value(sym) == yes) 512 511 goto next_menu; 513 512 } 514 513 } ··· 918 919 conf_changed_callback = fn; 919 920 } 920 921 922 + static void randomize_choice_values(struct symbol *csym) 923 + { 924 + struct property *prop; 925 + struct symbol *sym; 926 + struct expr *e; 927 + int cnt, def; 928 + 929 + /* 930 + * If choice is mod then we may have more items slected 931 + * and if no then no-one. 932 + * In both cases stop. 933 + */ 934 + if (csym->curr.tri != yes) 935 + return; 936 + 937 + prop = sym_get_choice_prop(csym); 938 + 939 + /* count entries in choice block */ 940 + cnt = 0; 941 + expr_list_for_each_sym(prop->expr, e, sym) 942 + cnt++; 943 + 944 + /* 945 + * find a random value and set it to yes, 946 + * set the rest to no so we have only one set 947 + */ 948 + def = (rand() % cnt); 949 + 950 + cnt = 0; 951 + expr_list_for_each_sym(prop->expr, e, sym) { 952 + if (def == cnt++) { 953 + sym->def[S_DEF_USER].tri = yes; 954 + csym->def[S_DEF_USER].val = sym; 955 + } 956 + else { 957 + sym->def[S_DEF_USER].tri = no; 958 + } 959 + } 960 + csym->flags |= SYMBOL_DEF_USER; 961 + /* clear VALID to get value calculated */ 962 + csym->flags &= ~(SYMBOL_VALID); 963 + } 964 + 965 + static void set_all_choice_values(struct symbol *csym) 966 + { 967 + struct property *prop; 968 + struct symbol *sym; 969 + struct expr *e; 970 + 971 + prop = sym_get_choice_prop(csym); 972 + 973 + /* 974 + * Set all non-assinged choice values to no 975 + */ 976 + expr_list_for_each_sym(prop->expr, e, sym) { 977 + if (!sym_has_value(sym)) 978 + sym->def[S_DEF_USER].tri = no; 979 + } 980 + csym->flags |= SYMBOL_DEF_USER; 981 + /* clear VALID to get value calculated */ 982 + csym->flags &= ~(SYMBOL_VALID); 983 + } 921 984 922 985 void conf_set_all_new_symbols(enum conf_def_mode mode) 923 986 { 924 987 struct symbol *sym, *csym; 925 - struct property *prop; 926 - struct expr *e; 927 - int i, cnt, def; 988 + int i, cnt; 928 989 929 990 for_all_symbols(i, sym) { 930 991 if (sym_has_value(sym)) ··· 1020 961 1021 962 sym_clear_all_valid(); 1022 963 1023 - if (mode != def_random) 1024 - return; 1025 964 /* 1026 965 * We have different type of choice blocks. 1027 966 * If curr.tri equal to mod then we can select several ··· 1034 977 continue; 1035 978 1036 979 sym_calc_value(csym); 1037 - 1038 - if (csym->curr.tri != yes) 1039 - continue; 1040 - 1041 - prop = sym_get_choice_prop(csym); 1042 - 1043 - /* count entries in choice block */ 1044 - cnt = 0; 1045 - expr_list_for_each_sym(prop->expr, e, sym) 1046 - cnt++; 1047 - 1048 - /* 1049 - * find a random value and set it to yes, 1050 - * set the rest to no so we have only one set 1051 - */ 1052 - def = (rand() % cnt); 1053 - 1054 - cnt = 0; 1055 - expr_list_for_each_sym(prop->expr, e, sym) { 1056 - if (def == cnt++) { 1057 - sym->def[S_DEF_USER].tri = yes; 1058 - csym->def[S_DEF_USER].val = sym; 1059 - } 1060 - else { 1061 - sym->def[S_DEF_USER].tri = no; 1062 - } 1063 - } 1064 - csym->flags |= SYMBOL_DEF_USER; 1065 - /* clear VALID to get value calculated */ 1066 - csym->flags &= ~(SYMBOL_VALID); 980 + if (mode == def_random) 981 + randomize_choice_values(csym); 982 + else 983 + set_all_choice_values(csym); 1067 984 } 1068 985 }
+1 -1
scripts/kconfig/expr.c
··· 1087 1087 1088 1088 static void expr_print_file_helper(void *data, struct symbol *sym, const char *str) 1089 1089 { 1090 - fwrite(str, strlen(str), 1, data); 1090 + xfwrite(str, strlen(str), 1, data); 1091 1091 } 1092 1092 1093 1093 void expr_fprint(struct expr *e, FILE *out)
+10
scripts/kconfig/lkc.h
··· 72 72 int zconf_lineno(void); 73 73 char *zconf_curname(void); 74 74 75 + /* conf.c */ 76 + void xfgets(char *str, int size, FILE *in); 77 + 75 78 /* confdata.c */ 76 79 const char *conf_get_configname(void); 77 80 const char *conf_get_autoconfig_name(void); ··· 82 79 void sym_set_change_count(int count); 83 80 void sym_add_change_count(int count); 84 81 void conf_set_all_new_symbols(enum conf_def_mode mode); 82 + 83 + /* confdata.c and expr.c */ 84 + static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) 85 + { 86 + if (fwrite(str, len, count, out) < count) 87 + fprintf(stderr, "\nError in writing or end of file.\n"); 88 + } 85 89 86 90 /* kconfig_load.c */ 87 91 void kconfig_load(void);
+2
scripts/kconfig/nconf.c
··· 676 676 struct mitem *mcur; 677 677 678 678 cur = current_item(curses_menu); 679 + if (!cur) 680 + return NULL; 679 681 mcur = (struct mitem *) item_userptr(cur); 680 682 return mcur->usrptr; 681 683