]> git.sur5r.net Git - u-boot/blobdiff - scripts/kconfig/confdata.c
kconfig: re-sync with Linux 4.17-rc4
[u-boot] / scripts / kconfig / confdata.c
index ae6ce669e17a7864bb9c858a1068fd64cb2ca39b..e4cbb87d760bfffb2935a95a4fc4da0b2495cb8c 100644 (file)
 
 #include "lkc.h"
 
+struct conf_printer {
+       void (*print_symbol)(FILE *, struct symbol *, const char *, void *);
+       void (*print_comment)(FILE *, const char *, void *);
+};
+
 static void conf_warning(const char *fmt, ...)
        __attribute__ ((format (printf, 1, 2)));
 
@@ -23,7 +28,7 @@ static void conf_message(const char *fmt, ...)
        __attribute__ ((format (printf, 1, 2)));
 
 static const char *conf_filename;
-static int conf_lineno, conf_warnings, conf_unsaved;
+static int conf_lineno, conf_warnings;
 
 const char conf_defname[] = "arch/$ARCH/defconfig";
 
@@ -59,6 +64,7 @@ static void conf_message(const char *fmt, ...)
        va_start(ap, fmt);
        if (conf_message_callback)
                conf_message_callback(fmt, ap);
+       va_end(ap);
 }
 
 const char *conf_get_configname(void)
@@ -155,24 +161,20 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
        case S_STRING:
                if (*p++ != '"')
                        break;
-               for (p2 = p; (p2 = strpbrk(p2, "\"\\")); p2++) {
-                       if (*p2 == '"') {
-                               *p2 = 0;
-                               break;
-                       }
-                       memmove(p2, p2 + 1, strlen(p2));
-               }
-               if (!p2) {
+               /* Last char has to be a '"' */
+               if (p[strlen(p) - 1] != '"') {
                        if (def != S_DEF_AUTO)
                                conf_warning("invalid string found");
                        return 1;
                }
+               /* Overwrite '"' with \0 for string termination */
+               p[strlen(p) - 1] = 0;
                /* fall through */
        case S_INT:
        case S_HEX:
        done:
                if (sym_string_valid(sym, p)) {
-                       sym->def[def].val = strdup(p);
+                       sym->def[def].val = xstrdup(p);
                        sym->flags |= def_flags;
                } else {
                        if (def != S_DEF_AUTO)
@@ -195,7 +197,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
        if (new_size > *n) {
                new_size += LINE_GROWTH - 1;
                new_size *= 2;
-               nline = realloc(*lineptr, new_size);
+               nline = xrealloc(*lineptr, new_size);
                if (!nline)
                        return -1;
 
@@ -261,11 +263,8 @@ int conf_read_simple(const char *name, int def)
                if (in)
                        goto load;
                sym_add_change_count(1);
-               if (!sym_defconfig_list) {
-                       if (modules_sym)
-                               sym_calc_value(modules_sym);
+               if (!sym_defconfig_list)
                        return 1;
-               }
 
                for_all_defaults(sym_defconfig_list, prop) {
                        if (expr_calc_value(prop->visible.expr) == no ||
@@ -287,7 +286,6 @@ load:
        conf_filename = name;
        conf_lineno = 0;
        conf_warnings = 0;
-       conf_unsaved = 0;
 
        def_flags = SYMBOL_DEF << def;
        for_all_symbols(i, sym) {
@@ -372,7 +370,9 @@ load:
                                continue;
                } else {
                        if (line[0] != '\r' && line[0] != '\n')
-                               conf_warning("unexpected data");
+                               conf_warning("unexpected data: %.*s",
+                                            (int)strcspn(line, "\r\n"), line);
+
                        continue;
                }
 setsym:
@@ -398,21 +398,23 @@ setsym:
        }
        free(line);
        fclose(in);
-
-       if (modules_sym)
-               sym_calc_value(modules_sym);
        return 0;
 }
 
 int conf_read(const char *name)
 {
        struct symbol *sym;
+       int conf_unsaved = 0;
        int i;
 
        sym_set_change_count(0);
 
-       if (conf_read_simple(name, S_DEF_USER))
+       if (conf_read_simple(name, S_DEF_USER)) {
+               sym_calc_value(modules_sym);
                return 1;
+       }
+
+       sym_calc_value(modules_sym);
 
        for_all_symbols(i, sym) {
                sym_calc_value(sym);
@@ -624,6 +626,7 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym,
                              struct conf_printer *printer, void *printer_arg)
 {
        const char *str;
+       char *str2;
 
        switch (sym->type) {
        case S_OTHER:
@@ -631,9 +634,10 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym,
                break;
        case S_STRING:
                str = sym_get_string_value(sym);
-               str = sym_escape_string_value(str);
-               printer->print_symbol(fp, sym, str, printer_arg);
-               free((void *)str);
+               str2 = xmalloc(strlen(str) + 3);
+               sprintf(str2, "\"%s\"", str);
+               printer->print_symbol(fp, sym, str2, printer_arg);
+               free((void *)str2);
                break;
        default:
                str = sym_get_string_value(sym);
@@ -843,6 +847,7 @@ static int conf_split_config(void)
 
        name = conf_get_autoconfig_name();
        conf_read_simple(name, S_DEF_AUTO);
+       sym_calc_value(modules_sym);
 
        if (chdir("include/config"))
                return 1;
@@ -951,14 +956,6 @@ int conf_write_autoconf(void)
        FILE *out, *tristate, *out_h;
        int i;
 
-       /*
-        * Added for U-Boot SPL/TPL
-        */
-       name = getenv("KCONFIG_OBJDIR");
-       if (name && name[0])
-               if (chdir(name))
-                       return 1;
-
        sym_clear_all_valid();
 
        file_write_dep("include/config/auto.conf.cmd");
@@ -1124,7 +1121,7 @@ void set_all_choice_values(struct symbol *csym)
 bool conf_set_all_new_symbols(enum conf_def_mode mode)
 {
        struct symbol *sym, *csym;
-       int i, cnt, pby, pty, ptm;      /* pby: probability of boolean  = y
+       int i, cnt, pby, pty, ptm;      /* pby: probability of bool     = y
                                         * pty: probability of tristate = y
                                         * ptm: probability of tristate = m
                                         */