[PATCH 1/2] kconfig: Refactor sym_escape_string_value

From: Richard Weinberger
Date: Mon Sep 20 2021 - 17:42:35 EST


sym_escape_string_value() can take a struct symbol directly
and use sym_get_string_value() itself to obtain the string value.
We will need struct symbol later for error reporting.

Signed-off-by: Richard Weinberger <richard@xxxxxx>
---
scripts/kconfig/conf.c | 3 +--
scripts/kconfig/confdata.c | 3 +--
scripts/kconfig/lkc_proto.h | 2 +-
scripts/kconfig/symbol.c | 6 ++++--
4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 5d84b44a2a2a..a6dad4a2e7a2 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -650,8 +650,7 @@ static void check_conf(struct menu *menu)
const char *str;

if (sym->type == S_STRING) {
- str = sym_get_string_value(sym);
- str = sym_escape_string_value(str);
+ str = sym_escape_string(sym);
printf("%s%s=%s\n", CONFIG_, sym->name, str);
free((void *)str);
} else {
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index cf72680cd769..4e053f2477f9 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -734,8 +734,7 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym,
case S_UNKNOWN:
break;
case S_STRING:
- str = sym_get_string_value(sym);
- str = sym_escape_string_value(str);
+ str = sym_escape_string(sym);
printer->print_symbol(fp, sym, str, printer_arg);
free((void *)str);
break;
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index a11626bdc421..035cc522808b 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -18,7 +18,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_escape_string_value(const char *in);
+const char * sym_escape_string(struct symbol *sym);
struct symbol ** sym_re_search(const char *pattern);
const char * sym_type_name(enum symbol_type type);
void sym_calc_value(struct symbol *sym);
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 5844d636d38f..4a31bb943f79 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -871,13 +871,15 @@ struct symbol *sym_find(const char *name)
return symbol;
}

-const char *sym_escape_string_value(const char *in)
+const char *sym_escape_string(struct symbol *sym)
{
- const char *p;
+ const char *in, *p;
size_t reslen;
char *res;
size_t l;

+ in = sym_get_string_value(sym);
+
reslen = strlen(in) + strlen("\"\"") + 1;

p = in;
--
2.26.2