From 1b9eda2e4892cb373c7d4cf23439f357c8739e27 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 31 Jan 2018 10:34:30 +0100 Subject: kconfig: Warn if help text is blank Blank help texts are probably either a typo, a Kconfig misunderstanding, or some kind of half-committing to adding a help text (in which case a TODO comment would be clearer, if the help text really can't be added right away). Best to flag them, IMO. Example warning: drivers/mmc/host/Kconfig:877: warning: 'MMC_TOSHIBA_PCI' defined with blank help text Signed-off-by: Ulf Magnusson Acked-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- scripts/kconfig/zconf.y | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'scripts') diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 21ce883e5d9e..4be98050b961 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -436,6 +436,12 @@ help: help_start T_HELPTEXT zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used", current_entry->sym->name ?: ""); } + + /* Is the help text empty or all whitespace? */ + if ($2[strspn($2, " \f\n\r\t\v")] == '\0') + zconfprint("warning: '%s' defined with blank help text", + current_entry->sym->name ?: ""); + current_entry->help = $2; }; -- cgit v1.2.3-58-ga151 From e856f3a7d706b37d8be9b41e41b19f4919570e57 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Thu, 1 Feb 2018 10:48:52 +0100 Subject: coccinelle: devm_free: reduce false positives Some files use both a non-devm allocation and a devm_allocation. Don't complain about a free when the same function contains a non-devm allocation. Signed-off-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/free/devm_free.cocci | 55 ++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci index c990d2c7ee16..b2a2cf8bf81f 100644 --- a/scripts/coccinelle/free/devm_free.cocci +++ b/scripts/coccinelle/free/devm_free.cocci @@ -56,9 +56,62 @@ expression x; x = devm_ioport_map(...) ) +@safe depends on context || org || report exists@ +expression x; +position p; +@@ + +( + x = kmalloc(...) +| + x = kvasprintf(...) +| + x = kasprintf(...) +| + x = kzalloc(...) +| + x = kmalloc_array(...) +| + x = kcalloc(...) +| + x = kstrdup(...) +| + x = kmemdup(...) +| + x = get_free_pages(...) +| + x = request_irq(...) +| + x = ioremap(...) +| + x = ioremap_nocache(...) +| + x = ioport_map(...) +) +... +( + kfree@p(x) +| + kzfree@p(x) +| + __krealloc@p(x, ...) +| + krealloc@p(x, ...) +| + free_pages@p(x, ...) +| + free_page@p(x) +| + free_irq@p(x) +| + iounmap@p(x) +| + ioport_unmap@p(x) +) + @pb@ expression r.x; -position p; +position p != safe.p; @@ ( -- cgit v1.2.3-58-ga151 From a2b0fe7435faee6f6fbb27409878013bc4727e98 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 3 Feb 2018 08:44:58 +0100 Subject: coccinelle: deref_null: avoid useless computation The effect of the rules ifm1, pr11, and pr12 is only used in the final rule, which depends on context && !org && !report. Thus these rules should only be performed in those circumstances. Signed-off-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/null/deref_null.cocci | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/coccinelle/null/deref_null.cocci b/scripts/coccinelle/null/deref_null.cocci index f192d6035d02..b16ccb7663a7 100644 --- a/scripts/coccinelle/null/deref_null.cocci +++ b/scripts/coccinelle/null/deref_null.cocci @@ -212,7 +212,7 @@ else S3 // The following three rules are duplicates of ifm, pr1 and pr2 respectively. // It is need because the previous rule as already made a "change". -@ifm1@ +@ifm1 depends on context && !org && !report@ expression *E; statement S1,S2; position p1; @@ -220,7 +220,7 @@ position p1; if@p1 ((E == NULL && ...) || ...) S1 else S2 -@pr11 expression@ +@pr11 depends on context && !org && !report expression@ expression *ifm1.E; identifier f; position p1; @@ -228,7 +228,7 @@ position p1; (E != NULL && ...) ? <+...E->f@p1...+> : ... -@pr12 expression@ +@pr12 depends on context && !org && !report expression@ expression *ifm1.E; identifier f; position p2; -- cgit v1.2.3-58-ga151 From cb67ab2cd2b8abd9650292c986c79901e3073a59 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 6 Feb 2018 09:34:42 +0900 Subject: kconfig: do not write choice values when their dependency becomes n "# CONFIG_... is not set" for choice values are wrongly written into the .config file if they are once visible, then become invisible later. Test case --------- ---------------------------(Kconfig)---------------------------- config A bool "A" choice prompt "Choice ?" depends on A config CHOICE_B bool "Choice B" config CHOICE_C bool "Choice C" endchoice ---------------------------------------------------------------- ---------------------------(.config)---------------------------- CONFIG_A=y ---------------------------------------------------------------- With the Kconfig and .config above, $ make config scripts/kconfig/conf --oldaskconfig Kconfig * * Linux Kernel Configuration * A (A) [Y/n] n # # configuration written to .config # $ cat .config # # Automatically generated file; DO NOT EDIT. # Linux Kernel Configuration # # CONFIG_A is not set # CONFIG_CHOICE_B is not set # CONFIG_CHOICE_C is not set Here, # CONFIG_CHOICE_B is not set # CONFIG_CHOICE_C is not set should not be written into the .config file because their dependency "depends on A" is unmet. Currently, there is no code that clears SYMBOL_WRITE of choice values. Clear SYMBOL_WRITE for all symbols in sym_calc_value(), then set it again after calculating visibility. To simplify the logic, set the flag if they have non-n visibility, regardless of types, and regardless of whether they are choice values or not. Signed-off-by: Masahiro Yamada Reviewed-by: Ulf Magnusson --- scripts/kconfig/symbol.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index c9123ed2b791..13f7fdfe328d 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -371,11 +371,13 @@ void sym_calc_value(struct symbol *sym) sym->curr.tri = no; return; } - if (!sym_is_choice_value(sym)) - sym->flags &= ~SYMBOL_WRITE; + sym->flags &= ~SYMBOL_WRITE; sym_calc_visibility(sym); + if (sym->visible != no) + sym->flags |= SYMBOL_WRITE; + /* set default if recursively called */ sym->curr = newval; @@ -390,7 +392,6 @@ void sym_calc_value(struct symbol *sym) /* if the symbol is visible use the user value * if available, otherwise try the default value */ - sym->flags |= SYMBOL_WRITE; if (sym_has_value(sym)) { newval.tri = EXPR_AND(sym->def[S_DEF_USER].tri, sym->visible); @@ -433,12 +434,9 @@ void sym_calc_value(struct symbol *sym) case S_STRING: case S_HEX: case S_INT: - if (sym->visible != no) { - sym->flags |= SYMBOL_WRITE; - if (sym_has_value(sym)) { - newval.val = sym->def[S_DEF_USER].val; - break; - } + if (sym->visible != no && sym_has_value(sym)) { + newval.val = sym->def[S_DEF_USER].val; + break; } prop = sym_get_default_prop(sym); if (prop) { -- cgit v1.2.3-58-ga151 From 4f208f392103e8d5bcc7558dba69348b27d8ce42 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 6 Feb 2018 09:34:43 +0900 Subject: kconfig: show '?' prompt even if no help text is available 'make config', 'make oldconfig', etc. always receive '?' as a valid input and show useful information even if no help text is available. ------------------------>8------------------------ foo (FOO) [N/y] (NEW) ? There is no help available for this option. Symbol: FOO [=n] Type : bool Prompt: foo Defined at Kconfig:1 ------------------------>8------------------------ However, '?' is not shown in the prompt if its help text is missing. Let's show '?' all the time so that the prompt and the behavior match. Signed-off-by: Masahiro Yamada Reviewed-by: Ulf Magnusson --- scripts/kconfig/conf.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 307bc3f7b945..fc446acbf6d6 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -199,9 +199,7 @@ static int conf_sym(struct menu *menu) printf("/m"); if (oldval != yes && sym_tristate_within_range(sym, yes)) printf("/y"); - if (menu_has_help(menu)) - printf("/?"); - printf("] "); + printf("/?] "); if (!conf_askvalue(sym, sym_get_string_value(sym))) return 0; strip(line); @@ -303,10 +301,7 @@ static int conf_choice(struct menu *menu) printf("[1]: 1\n"); goto conf_childs; } - printf("[1-%d", cnt); - if (menu_has_help(menu)) - printf("?"); - printf("]: "); + printf("[1-%d?]: ", cnt); switch (input_mode) { case oldconfig: case silentoldconfig: -- cgit v1.2.3-58-ga151 From cd58a91def2accba1a07960889e89a63d372119a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 6 Feb 2018 09:34:45 +0900 Subject: kconfig: remove 'config*' pattern from .gitignnore I could not figure out why this pattern should be ignored. Checking commit 1e65174a3378 ("Add some basic .gitignore files") did not help. Let's remove this pattern, then see if it is really needed. Signed-off-by: Masahiro Yamada Reviewed-by: Ulf Magnusson --- scripts/kconfig/.gitignore | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kconfig/.gitignore b/scripts/kconfig/.gitignore index 51f1c877b543..a76856e559c0 100644 --- a/scripts/kconfig/.gitignore +++ b/scripts/kconfig/.gitignore @@ -1,7 +1,6 @@ # # Generated files # -config* *.lex.c *.tab.c *.tab.h -- cgit v1.2.3-58-ga151 From d2a04648a5dbc3d1d043b35257364f0197d4d868 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 8 Feb 2018 14:56:39 +0900 Subject: kconfig: remove check_stdin() Except silentoldconfig, valid_stdin is 1, so check_stdin() is no-op. oldconfig and silentoldconfig work almost in the same way except that the latter generates additional files under include/. Both ask users for input for new symbols. I do not know why only silentoldconfig requires stdio be tty. $ rm -f .config; touch .config $ yes "" | make oldconfig > stdout $ rm -f .config; touch .config $ yes "" | make silentoldconfig > stdout make[1]: *** [silentoldconfig] Error 1 make: *** [silentoldconfig] Error 2 $ tail -n 4 stdout Console input/output is redirected. Run 'make oldconfig' to update configuration. scripts/kconfig/Makefile:40: recipe for target 'silentoldconfig' failed Makefile:507: recipe for target 'silentoldconfig' failed Redirection is useful, for example, for testing where we want to give particular key inputs from a test file, then check the result. Signed-off-by: Masahiro Yamada Reviewed-by: Ulf Magnusson --- scripts/kconfig/conf.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index fc446acbf6d6..92111a077680 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -39,7 +39,6 @@ static enum input_mode input_mode = oldaskconfig; static int indent = 1; static int tty_stdio; -static int valid_stdin = 1; static int sync_kconfig; static int conf_cnt; static char line[PATH_MAX]; @@ -72,16 +71,6 @@ static void strip(char *str) *p-- = 0; } -static void check_stdin(void) -{ - if (!valid_stdin) { - printf(_("aborted!\n\n")); - printf(_("Console input/output is redirected. ")); - printf(_("Run 'make oldconfig' to update configuration.\n\n")); - exit(1); - } -} - /* Helper function to facilitate fgets() by Jean Sacren. */ static void xfgets(char *str, int size, FILE *in) { @@ -113,7 +102,6 @@ static int conf_askvalue(struct symbol *sym, const char *def) printf("%s\n", def); return 0; } - check_stdin(); /* fall through */ case oldaskconfig: fflush(stdout); @@ -310,7 +298,6 @@ static int conf_choice(struct menu *menu) printf("%d\n", cnt); break; } - check_stdin(); /* fall through */ case oldaskconfig: fflush(stdout); @@ -645,7 +632,6 @@ int main(int ac, char **av) return 1; } } - valid_stdin = tty_stdio; } switch (input_mode) { -- cgit v1.2.3-58-ga151 From f3ff6fb5db68bcd460e9880d5fb4902520dd645b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 8 Feb 2018 14:56:40 +0900 Subject: kconfig: echo stdin to stdout if either is redirected If stdio is not tty, conf_askvalue() puts additional new line to prevent prompts from being concatenated into a single line. This care is missing in conf_choice(), so a 'choice' prompt and the next prompt are shown in the same line. Move the code into xfgets() to cater to all cases. To improve this more, let's echo stdin to stdout. This clarifies what keys were input from stdio and the stdout looks like as if it were from tty. I removed the isatty(2) check since stderr is unrelated here. Signed-off-by: Masahiro Yamada Reviewed-by: Ulf Magnusson --- scripts/kconfig/conf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 92111a077680..fe59f6df4b45 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -76,6 +76,9 @@ static void xfgets(char *str, int size, FILE *in) { if (!fgets(str, size, in)) fprintf(stderr, "\nError in reading or end of file.\n"); + + if (!tty_stdio) + printf("%s", str); } static int conf_askvalue(struct symbol *sym, const char *def) @@ -106,8 +109,6 @@ static int conf_askvalue(struct symbol *sym, const char *def) case oldaskconfig: fflush(stdout); xfgets(line, sizeof(line), stdin); - if (!tty_stdio) - printf("\n"); return 1; default: break; @@ -490,7 +491,7 @@ int main(int ac, char **av) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - tty_stdio = isatty(0) && isatty(1) && isatty(2); + tty_stdio = isatty(0) && isatty(1); while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) { if (opt == 's') { -- cgit v1.2.3-58-ga151 From 9e3e10c725360b9d07018cfcd5b7b6b7d325fae5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 6 Feb 2018 09:34:41 +0900 Subject: kconfig: send error messages to stderr These messages should be directed to stderr. Signed-off-by: Masahiro Yamada Reviewed-by: Ulf Magnusson --- scripts/kconfig/conf.c | 10 ++++++---- scripts/kconfig/expr.c | 4 ++-- scripts/kconfig/symbol.c | 2 +- scripts/kconfig/zconf.l | 27 +++++++++++++++------------ 4 files changed, 24 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index fe59f6df4b45..822dc51923d6 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -548,7 +548,7 @@ int main(int ac, char **av) } } if (ac == optind) { - printf(_("%s: Kconfig file missing\n"), av[0]); + fprintf(stderr, _("%s: Kconfig file missing\n"), av[0]); conf_usage(progname); exit(1); } @@ -573,9 +573,11 @@ int main(int ac, char **av) if (!defconfig_file) defconfig_file = conf_get_default_confname(); if (conf_read(defconfig_file)) { - printf(_("***\n" - "*** Can't find default configuration \"%s\"!\n" - "***\n"), defconfig_file); + fprintf(stderr, + _("***\n" + "*** Can't find default configuration \"%s\"!\n" + "***\n"), + defconfig_file); exit(1); } break; diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index 2ba332b3fed7..d45381986ac7 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c @@ -94,7 +94,7 @@ struct expr *expr_copy(const struct expr *org) e->right.expr = expr_copy(org->right.expr); break; default: - printf("can't copy type %d\n", e->type); + fprintf(stderr, "can't copy type %d\n", e->type); free(e); e = NULL; break; @@ -127,7 +127,7 @@ void expr_free(struct expr *e) expr_free(e->right.expr); break; default: - printf("how to free type %d?\n", e->type); + fprintf(stderr, "how to free type %d?\n", e->type); break; } free(e); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 13f7fdfe328d..c4409ee7fee2 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1221,7 +1221,7 @@ static struct symbol *sym_check_expr_deps(struct expr *e) default: break; } - printf("Oops! How to check %d?\n", e->type); + fprintf(stderr, "Oops! How to check %d?\n", e->type); return NULL; } diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 07e074dc68a1..0ba4900050c1 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -184,7 +184,9 @@ n [A-Za-z0-9_-] append_string(yytext, 1); } \n { - printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno()); + fprintf(stderr, + "%s:%d:warning: multi-line strings not supported\n", + zconf_curname(), zconf_lineno()); current_file->lineno++; BEGIN(INITIAL); return T_EOL; @@ -294,7 +296,7 @@ void zconf_initscan(const char *name) { yyin = zconf_fopen(name); if (!yyin) { - printf("can't find file %s\n", name); + fprintf(stderr, "can't find file %s\n", name); exit(1); } @@ -315,8 +317,8 @@ void zconf_nextfile(const char *name) current_buf->state = YY_CURRENT_BUFFER; yyin = zconf_fopen(file->name); if (!yyin) { - printf("%s:%d: can't open file \"%s\"\n", - zconf_curname(), zconf_lineno(), file->name); + fprintf(stderr, "%s:%d: can't open file \"%s\"\n", + zconf_curname(), zconf_lineno(), file->name); exit(1); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); @@ -325,20 +327,21 @@ void zconf_nextfile(const char *name) for (iter = current_file->parent; iter; iter = iter->parent ) { if (!strcmp(current_file->name,iter->name) ) { - printf("%s:%d: recursive inclusion detected. " - "Inclusion path:\n current file : '%s'\n", - zconf_curname(), zconf_lineno(), - zconf_curname()); + fprintf(stderr, + "%s:%d: recursive inclusion detected. " + "Inclusion path:\n current file : '%s'\n", + zconf_curname(), zconf_lineno(), + zconf_curname()); iter = current_file->parent; while (iter && \ strcmp(iter->name,current_file->name)) { - printf(" included from: '%s:%d'\n", - iter->name, iter->lineno-1); + fprintf(stderr, " included from: '%s:%d'\n", + iter->name, iter->lineno-1); iter = iter->parent; } if (iter) - printf(" included from: '%s:%d'\n", - iter->name, iter->lineno+1); + fprintf(stderr, " included from: '%s:%d'\n", + iter->name, iter->lineno+1); exit(1); } } -- cgit v1.2.3-58-ga151 From d717f24d8c68081caae2374cf5ea6c4e62c490fc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 9 Feb 2018 01:19:07 +0900 Subject: kconfig: add xrealloc() helper We already have xmalloc(), xcalloc(). Add xrealloc() as well to save tedious error handling. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 2 +- scripts/kconfig/lkc.h | 1 + scripts/kconfig/nconf.gui.c | 3 ++- scripts/kconfig/symbol.c | 2 +- scripts/kconfig/util.c | 11 ++++++++++- scripts/kconfig/zconf.l | 2 +- 6 files changed, 16 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f7927391de30..5c12dc91ef34 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -201,7 +201,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; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 16cb62b92650..4e23febbe4b2 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -114,6 +114,7 @@ struct file *file_lookup(const char *name); int file_write_dep(const char *name); void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); +void *xrealloc(void *p, size_t size); struct gstr { size_t len; diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index a64b1c31253e..88874acfda36 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -6,6 +6,7 @@ * */ #include "nconf.h" +#include "lkc.h" /* a list of all the different widgets we use */ attributes_t attributes[ATTR_MAX+1] = {0}; @@ -374,7 +375,7 @@ int dialog_inputbox(WINDOW *main_window, if (strlen(init)+1 > *result_len) { *result_len = strlen(init)+1; - *resultp = result = realloc(result, *result_len); + *resultp = result = xrealloc(result, *result_len); } /* find the widest line of msg: */ diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index c4409ee7fee2..60a76f958f33 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -936,7 +936,7 @@ const char *sym_expand_string_value(const char *in) newlen = strlen(res) + strlen(symval) + strlen(src) + 1; if (newlen > reslen) { reslen = newlen; - res = realloc(res, reslen); + res = xrealloc(res, reslen); } strcat(res, symval); diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 0e76042473cc..138894ef49ea 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -104,7 +104,7 @@ void str_append(struct gstr *gs, const char *s) if (s) { l = strlen(gs->s) + strlen(s) + 1; if (l > gs->len) { - gs->s = realloc(gs->s, l); + gs->s = xrealloc(gs->s, l); gs->len = l; } strcat(gs->s, s); @@ -145,3 +145,12 @@ void *xcalloc(size_t nmemb, size_t size) fprintf(stderr, "Out of memory.\n"); exit(1); } + +void *xrealloc(void *p, size_t size) +{ + p = realloc(p, size); + if (p) + return p; + fprintf(stderr, "Out of memory.\n"); + exit(1); +} diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 0ba4900050c1..02de6fe302a9 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -52,7 +52,7 @@ static void append_string(const char *str, int size) if (new_size > text_asize) { new_size += START_STRSIZE - 1; new_size &= -START_STRSIZE; - text = realloc(text, new_size); + text = xrealloc(text, new_size); text_asize = new_size; } memcpy(text + text_size, str, size); -- cgit v1.2.3-58-ga151 From 523ca58b7db2e30e3c185a7927dd80a30c1bc743 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 9 Feb 2018 01:19:08 +0900 Subject: kconfig: remove const qualifier from sym_expand_string_value() This function returns realloc'ed memory, so the returned pointer must be passed to free() when done. So, 'const' qualifier is odd. It is allowed to modify the expanded string. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc_proto.h | 2 +- scripts/kconfig/symbol.c | 2 +- scripts/kconfig/util.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 5d86e2dfae59..9dc8abfb1dc3 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -31,7 +31,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); -const char * sym_expand_string_value(const char *in); +char *sym_expand_string_value(const char *in); const char * sym_escape_string_value(const char *in); struct symbol ** sym_re_search(const char *pattern); const char * sym_type_name(enum symbol_type type); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 60a76f958f33..cca9663be5dd 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -899,7 +899,7 @@ struct symbol *sym_find(const char *name) * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to * the empty string. */ -const char *sym_expand_string_value(const char *in) +char *sym_expand_string_value(const char *in) { const char *src; char *res; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 138894ef49ea..b98a79e30e04 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -14,11 +14,11 @@ struct file *file_lookup(const char *name) { struct file *file; - const char *file_name = sym_expand_string_value(name); + char *file_name = sym_expand_string_value(name); for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { - free((void *)file_name); + free(file_name); return file; } } -- cgit v1.2.3-58-ga151