From patchwork Fri Oct 1 05:32:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45890C43219 for ; Fri, 1 Oct 2021 05:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33CBA619F5 for ; Fri, 1 Oct 2021 05:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239025AbhJAFfS (ORCPT ); Fri, 1 Oct 2021 01:35:18 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25307 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351941AbhJAFfH (ORCPT ); Fri, 1 Oct 2021 01:35:07 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVT000646; Fri, 1 Oct 2021 14:32:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVT000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066379; bh=Hk86knQX+FtOEwvSmj6Z1Ht+3JjaU0RyCPMk1FsbiQ4=; h=From:To:Cc:Subject:Date:From; b=lun/CgpTky5j/eZSDZ+5f342kVpZDv0t2wywGZSkmkmNDWrqguhh+V/AQvowk4Y8e Ly94RaVa1zs/okD/jIO2Tz2Ziw1zebGPgBSyZSVbhssDK114DxUS6NBPXMS7gPYt5m nEYK+QVdxUGiVkgdmUbBM/d9ujBx6OA/P9YEpLnKabhhdJ/4kKl2BV6CWqEqgbiN6a pOpwMftH5dyRBnrvaNb+Eid59c0E4YpEzmhIen4rDtFDxXXQ+nfMTGRL8kXcoiSG9t /4ZGkrvGXcPE9DH7S6IZK1OQxz/+4zipBlSpeLpCIdoT5swz/5KVPYwsOwwyLoxQOq fT5pnUzGDDkTg== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 01/10] kconfig: remove 'const' from the return type of sym_escape_string_value() Date: Fri, 1 Oct 2021 14:32:44 +0900 Message-Id: <20211001053253.1223316-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org sym_escape_string_value() returns a malloc'ed memory, but as (const char *). So, it must be casted to (void *) when it is free'd. This is odd. The return type of sym_escape_string_value() should be (char *). I exploited that free(NULL) has no effect. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 15 +++++++-------- scripts/kconfig/confdata.c | 27 ++++++++++++++------------- scripts/kconfig/lkc_proto.h | 2 +- scripts/kconfig/symbol.c | 3 ++- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 5d84b44a2a2a..310fdd408793 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -647,17 +647,16 @@ static void check_conf(struct menu *menu) switch (input_mode) { case listnewconfig: if (sym->name) { - const char *str; + const char *val = sym_get_string_value(sym); + char *escaped = NULL; if (sym->type == S_STRING) { - str = sym_get_string_value(sym); - str = sym_escape_string_value(str); - printf("%s%s=%s\n", CONFIG_, sym->name, str); - free((void *)str); - } else { - str = sym_get_string_value(sym); - printf("%s%s=%s\n", CONFIG_, sym->name, str); + escaped = sym_escape_string_value(val); + val = escaped; } + + printf("%s%s=%s\n", CONFIG_, sym->name, val); + free(escaped); } break; case helpnewconfig: diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index cf72680cd769..9b2271eb43d6 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -728,21 +728,22 @@ static struct conf_printer header_printer_cb = static void conf_write_symbol(FILE *fp, struct symbol *sym, struct conf_printer *printer, void *printer_arg) { - const char *str; + const char *val; + char *escaped = NULL; - switch (sym->type) { - case S_UNKNOWN: - 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); - break; - default: - str = sym_get_string_value(sym); - printer->print_symbol(fp, sym, str, printer_arg); + if (sym->type == S_UNKNOWN) + return; + + val = sym_get_string_value(sym); + + if (sym->type == S_STRING) { + escaped = sym_escape_string_value(val); + val = escaped; } + + printer->print_symbol(fp, sym, val, printer_arg); + + free(escaped); } static void diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index a11626bdc421..e6955df49973 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); +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); void sym_calc_value(struct symbol *sym); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 5844d636d38f..6bf8665a6a0f 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -871,7 +871,8 @@ struct symbol *sym_find(const char *name) return symbol; } -const char *sym_escape_string_value(const char *in) +/* The returned pointer must be freed on the caller side */ +char *sym_escape_string_value(const char *in) { const char *p; size_t reslen; From patchwork Fri Oct 1 05:32:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62157C433EF for ; Fri, 1 Oct 2021 05:33:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FDC661A60 for ; Fri, 1 Oct 2021 05:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352106AbhJAFfT (ORCPT ); Fri, 1 Oct 2021 01:35:19 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25306 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351940AbhJAFfH (ORCPT ); Fri, 1 Oct 2021 01:35:07 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVU000646; Fri, 1 Oct 2021 14:32:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVU000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066379; bh=dDFYdiulkWQCG/5vLkVRQ/0UbsBnq2pxgy3dX8uzS1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X4nYFSsAWwlYPQcu4i6XZnWtvfC50yJj1fSP9JTSZ4IV5rohr1iAQKfbBRbLm69rJ qNHZxnHNcwf3vF6+XPJaRJ0d41ucJEEEfuYCaVeP6yKelmxPnx7l6w2EB+En3P8+Xr HDeEAr9ZXCXpvMd5st4EnSFE45WBqBnMnxmhKLMR+I5nyyzmuQ1KeK29Fb16cT/4GG ALf6v+3npomUhj3izg0fV6XxeY0BMRtghzTuUNIBVD5wJ2+pKkYymYFxjUiC74mssO KM2osbpPydV2dPEpPjR0gsoSyyhzRd0SjBh9GYmcXlX7qwiIygkjgn/1WJum43eFLP B6a/b7uCY9NqQ== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 02/10] kconfig: refactor conf_write_heading() Date: Fri, 1 Oct 2021 14:32:45 +0900 Message-Id: <20211001053253.1223316-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org All the call sites of conf_write_heading() pass NULL to the third argument, and it is not used in the function. Also, the print_comment hooks are doing much more complex than needed. Rewrite the code. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 95 +++++++++++++------------------------- 1 file changed, 33 insertions(+), 62 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 9b2271eb43d6..ed1bb8ba971b 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -161,7 +161,6 @@ static int conf_touch_dep(const char *name) 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, ...) @@ -594,6 +593,36 @@ int conf_read(const char *name) return 0; } +struct comment_style { + const char *comment_line; + const char *comment_block_begin; + const char *comment_block_end; +}; + +static const struct comment_style comment_style_pound = { + .comment_line = "#", + .comment_block_begin = "#", + .comment_block_end = "#", +}; + +static const struct comment_style comment_style_c = { + .comment_line = " *", + .comment_block_begin = "/*", + .comment_block_end = " */", +}; + +static void conf_write_heading(FILE *fp, const struct comment_style *cs) +{ + fprintf(fp, "%s\n", cs->comment_block_begin); + + fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n", + cs->comment_line); + + fprintf(fp, "%s %s\n", cs->comment_line, rootmenu.prompt->text); + + fprintf(fp, "%s\n", cs->comment_block_end); +} + /* * Kconfig configuration printer * @@ -625,30 +654,9 @@ kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value); } -static void -kconfig_print_comment(FILE *fp, const char *value, void *arg) -{ - const char *p = value; - size_t l; - - for (;;) { - l = strcspn(p, "\n"); - fprintf(fp, "#"); - if (l) { - fprintf(fp, " "); - xfwrite(p, l, 1, fp); - p += l; - } - fprintf(fp, "\n"); - if (*p++ == '\0') - break; - } -} - static struct conf_printer kconfig_printer_cb = { .print_symbol = kconfig_print_symbol, - .print_comment = kconfig_print_comment, }; /* @@ -697,32 +705,9 @@ header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) } -static void -header_print_comment(FILE *fp, const char *value, void *arg) -{ - const char *p = value; - size_t l; - - fprintf(fp, "/*\n"); - for (;;) { - l = strcspn(p, "\n"); - fprintf(fp, " *"); - if (l) { - fprintf(fp, " "); - xfwrite(p, l, 1, fp); - p += l; - } - fprintf(fp, "\n"); - if (*p++ == '\0') - break; - } - fprintf(fp, " */\n"); -} - static struct conf_printer header_printer_cb = { .print_symbol = header_print_symbol, - .print_comment = header_print_comment, }; static void conf_write_symbol(FILE *fp, struct symbol *sym, @@ -746,20 +731,6 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym, free(escaped); } -static void -conf_write_heading(FILE *fp, struct conf_printer *printer, void *printer_arg) -{ - char buf[256]; - - snprintf(buf, sizeof(buf), - "\n" - "Automatically generated file; DO NOT EDIT.\n" - "%s\n", - rootmenu.prompt->text); - - printer->print_comment(fp, buf, printer_arg); -} - /* * Write out a minimal config. * All values that has default values are skipped as this is redundant. @@ -876,7 +847,7 @@ int conf_write(const char *name) if (!out) return 1; - conf_write_heading(out, &kconfig_printer_cb, NULL); + conf_write_heading(out, &comment_style_pound); if (!conf_get_changed()) sym_clear_all_valid(); @@ -1080,8 +1051,8 @@ int conf_write_autoconf(int overwrite) return 1; } - conf_write_heading(out, &kconfig_printer_cb, NULL); - conf_write_heading(out_h, &header_printer_cb, NULL); + conf_write_heading(out, &comment_style_pound); + conf_write_heading(out_h, &comment_style_c); for_all_symbols(i, sym) { sym_calc_value(sym); From patchwork Fri Oct 1 05:32:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFE92C433EF for ; Fri, 1 Oct 2021 05:33:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB05961A3A for ; Fri, 1 Oct 2021 05:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352024AbhJAFfJ (ORCPT ); Fri, 1 Oct 2021 01:35:09 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25305 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241541AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVV000646; Fri, 1 Oct 2021 14:33:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVV000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066380; bh=fQ8kuzKZhFdV66W9VpMSV4OyHXc8vSXpDVIuBoKabHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZDaBStGJluPWW8kX5Jx91FTyB8BWmra6pY/KBedZ6yXMBivP9Sik9EuAYBJsqRmz IdlRhP/Zz+aGPN0PDqFolignpilGmU511TrkvVm6C2NhXq14ESSGSlJ9dE1phb3BjT Gc4wdrR8/ZQqvXfXTgqo657CYGO44ZjVpBkQOeUvkfpOX0ZSJB1ACKkGDQDcRbzmI0 XO2Y85cEfwJiL4GsF7m30akxh144LP2NGIcwyWr7/OQgybJlJP4kEvsS90811KMIMK 39WJYfg8j4X+d/t6ey844dzzYtQ01/rOV06CxrzOLHYMy+aJwBz/yV9V4QPnlySWFr EMJzgiSH+YdBw== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 03/10] kconfig: refactor conf_write_symbol() Date: Fri, 1 Oct 2021 14:32:46 +0900 Message-Id: <20211001053253.1223316-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org I do not think 'struct conf_printer' is so useful. Add simple functions, print_symbol_for_*() to write out one symbol. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 136 ++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 79 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index ed1bb8ba971b..ce11e7442d12 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -159,10 +160,6 @@ static int conf_touch_dep(const char *name) return 0; } -struct conf_printer { - void (*print_symbol)(FILE *, struct symbol *, const char *, void *); -}; - static void conf_warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); @@ -629,91 +626,52 @@ static void conf_write_heading(FILE *fp, const struct comment_style *cs) * This printer is used when generating the resulting configuration after * kconfig invocation and `defconfig' files. Unset symbol might be omitted by * passing a non-NULL argument to the printer. - * */ -static void -kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ - - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: - if (*value == 'n') { - bool skip_unset = (arg != NULL); - - if (!skip_unset) - fprintf(fp, "# %s%s is not set\n", - CONFIG_, sym->name); - return; - } - break; - default: - break; - } - - fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value); -} +enum output_n { OUTPUT_N, OUTPUT_N_AS_UNSET, OUTPUT_N_NONE }; -static struct conf_printer kconfig_printer_cb = +static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n, + bool escape_string) { - .print_symbol = kconfig_print_symbol, -}; + const char *val; + char *escaped = NULL; -/* - * Header printer - * - * This printer is used when generating the `include/generated/autoconf.h' file. - */ -static void -header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ + if (sym->type == S_UNKNOWN) + return; - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: { - const char *suffix = ""; + val = sym_get_string_value(sym); - switch (*value) { - case 'n': - break; - case 'm': - suffix = "_MODULE"; - /* fall through */ - default: - fprintf(fp, "#define %s%s%s 1\n", - CONFIG_, sym->name, suffix); - } - break; + if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE) && + output_n != OUTPUT_N && *val == 'n') { + if (output_n == OUTPUT_N_AS_UNSET) + fprintf(fp, "# %s%s is not set\n", CONFIG_, sym->name); + return; } - case S_HEX: { - const char *prefix = ""; - if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X')) - prefix = "0x"; - fprintf(fp, "#define %s%s %s%s\n", - CONFIG_, sym->name, prefix, value); - break; - } - case S_STRING: - case S_INT: - fprintf(fp, "#define %s%s %s\n", - CONFIG_, sym->name, value); - break; - default: - break; + if (sym->type == S_STRING && escape_string) { + escaped = sym_escape_string_value(val); + val = escaped; } + fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, val); + + free(escaped); } -static struct conf_printer header_printer_cb = +static void print_symbol_for_dotconfig(FILE *fp, struct symbol *sym) { - .print_symbol = header_print_symbol, -}; + __print_symbol(fp, sym, OUTPUT_N_AS_UNSET, true); +} + +static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) +{ + __print_symbol(fp, sym, OUTPUT_N_NONE, true); +} -static void conf_write_symbol(FILE *fp, struct symbol *sym, - struct conf_printer *printer, void *printer_arg) +static void print_symbol_for_c(FILE *fp, struct symbol *sym) { const char *val; + const char *sym_suffix = ""; + const char *val_prefix = ""; char *escaped = NULL; if (sym->type == S_UNKNOWN) @@ -721,12 +679,32 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym, val = sym_get_string_value(sym); - if (sym->type == S_STRING) { + switch (sym->type) { + case S_BOOLEAN: + case S_TRISTATE: + switch (*val) { + case 'n': + return; + case 'm': + sym_suffix = "_MODULE"; + /* fall through */ + default: + val = "1"; + } + break; + case S_HEX: + if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) + val_prefix = "0x"; + break; + case S_STRING: escaped = sym_escape_string_value(val); val = escaped; + default: + break; } - printer->print_symbol(fp, sym, val, printer_arg); + fprintf(fp, "#define %s%s%s %s%s\n", CONFIG_, sym->name, sym_suffix, + val_prefix, val); free(escaped); } @@ -787,7 +765,7 @@ int conf_write_defconfig(const char *filename) goto next_menu; } } - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + print_symbol_for_dotconfig(out, sym); } next_menu: if (menu->list != NULL) { @@ -874,7 +852,7 @@ int conf_write(const char *name) need_newline = false; } sym->flags |= SYMBOL_WRITTEN; - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + print_symbol_for_dotconfig(out, sym); } next: @@ -1060,8 +1038,8 @@ int conf_write_autoconf(int overwrite) continue; /* write symbols to auto.conf and autoconf.h */ - conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1); - conf_write_symbol(out_h, sym, &header_printer_cb, NULL); + print_symbol_for_autoconf(out, sym); + print_symbol_for_c(out_h, sym); } fclose(out); fclose(out_h); From patchwork Fri Oct 1 05:32:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2BE0C433EF for ; Fri, 1 Oct 2021 05:33:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75AD061A3A for ; Fri, 1 Oct 2021 05:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351944AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25304 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238424AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVW000646; Fri, 1 Oct 2021 14:33:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVW000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066380; bh=un6DWX4+x7M43GD94+yMWT2UR1PL+dyvcY3QUplOGro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fgBnzlvb6Y3jMWsqquY4X5nT8zeaS1ZtQ0OZ+fbbhJs0Wh7UwpuoXP0BCcRkeLtbo ugXKW0umUBsJMFk3ttSUk9265/Y8HMhpgjDESI23DZiHwRGpsmlvi/hNIUO7yybUxZ 1asIjZRqGeMMqpgoMLZaHNj7lkNjQIxGxeaL4QZq/OZymRVr4Y1Ixewof3axtc8ZaM WmtsAkANIIs52TKiWiiOYBAJheUDoONtVFHo9TVSUU9ikPnT8ajZlR1a2lCCTsFLSs MTjnQHIB289gjGTu/p9EAg3uqaz6Fiuc5iHWf6OFazdjwmLNRaVtkn+896q2U/obUu syfjjP1VZduVA== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 04/10] kconfig: refactor listnewconfig code Date: Fri, 1 Oct 2021 14:32:47 +0900 Message-Id: <20211001053253.1223316-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org We can reuse __print_symbol() helper to print symbols for listnewconfig. Only the difference is the format for "n" symbols. This prints "CONFIG_FOO=n" instead of "# CONFIG_FOO is not set". Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 14 ++------------ scripts/kconfig/confdata.c | 5 +++++ scripts/kconfig/lkc_proto.h | 1 + 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 310fdd408793..971da3598fe4 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -646,18 +646,8 @@ static void check_conf(struct menu *menu) switch (input_mode) { case listnewconfig: - if (sym->name) { - const char *val = sym_get_string_value(sym); - char *escaped = NULL; - - if (sym->type == S_STRING) { - escaped = sym_escape_string_value(val); - val = escaped; - } - - printf("%s%s=%s\n", CONFIG_, sym->name, val); - free(escaped); - } + if (sym->name) + print_symbol_for_listconfig(sym); break; case helpnewconfig: printf("-----\n"); diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index ce11e7442d12..adbb9a955c43 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -667,6 +667,11 @@ static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) __print_symbol(fp, sym, OUTPUT_N_NONE, true); } +void print_symbol_for_listconfig(struct symbol *sym) +{ + __print_symbol(stdout, sym, OUTPUT_N, true); +} + static void print_symbol_for_c(FILE *fp, struct symbol *sym) { const char *val; diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index e6955df49973..ec4a01bb60ce 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -19,6 +19,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); char *sym_escape_string_value(const char *in); +void print_symbol_for_listconfig(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); From patchwork Fri Oct 1 05:32:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49D9CC4167B for ; Fri, 1 Oct 2021 05:33:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 332EB61052 for ; Fri, 1 Oct 2021 05:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352075AbhJAFfQ (ORCPT ); Fri, 1 Oct 2021 01:35:16 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25309 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351909AbhJAFfH (ORCPT ); Fri, 1 Oct 2021 01:35:07 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVX000646; Fri, 1 Oct 2021 14:33:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVX000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066381; bh=2y8u/ekcAKLI09NYZKb5pwSiSRmEUEdUJSeBwntIAss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eovQZa+Rux+ScrU718yYDencgw2tqT31bTV6V5ca3owxQxg3yixhuMLeyr/G7RWtu hOdRbhGdOadeWJJjayXeApWi7oqjWtskxr3fwEwbKhhwQBGGqdX+tntS1/1j468TGE CrFMXMpwW1gSKilJNVzy4HUZzJ8y8cwb/svI+/Gx5VtwKag9MY/8rW9JXRbYuEKRrc 57A/D9zYrCGPg+gvesS8npefUsnooo3JjLzCbv9YvvkyhyqMkffbIxXn/s0CBwtCB0 SyqsRu7+cZ3yrsYV4QKpYH8JfLlYUuQAusbdsvr9j3Z8QptXaA2n3gGXnC5xSP+WuZ VVmgRQrNtVlzQ== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 05/10] kconfig: move sym_escape_string_value() to confdata.c Date: Fri, 1 Oct 2021 14:32:48 +0900 Message-Id: <20211001053253.1223316-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Now that sym_escape_string_value() is only used in confdata.c it can be a 'static' function. Rename it escape_string_value() because it is agnostic about (struct sym *). Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 47 +++++++++++++++++++++++++++++++++++-- scripts/kconfig/lkc_proto.h | 1 - scripts/kconfig/symbol.c | 44 ---------------------------------- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index adbb9a955c43..78af1dd68894 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -620,6 +620,49 @@ static void conf_write_heading(FILE *fp, const struct comment_style *cs) fprintf(fp, "%s\n", cs->comment_block_end); } +/* The returned pointer must be freed on the caller side */ +static char *escape_string_value(const char *in) +{ + const char *p; + char *out; + size_t len; + + len = strlen(in) + strlen("\"\"") + 1; + + p = in; + while (1) { + p += strcspn(p, "\"\\"); + + if (p[0] == '\0') + break; + + len++; + p++; + } + + out = xmalloc(len); + out[0] = '\0'; + + strcat(out, "\""); + + p = in; + while (1) { + len = strcspn(p, "\"\\"); + strncat(out, p, len); + p += len; + + if (p[0] == '\0') + break; + + strcat(out, "\\"); + strncat(out, p++, 1); + } + + strcat(out, "\""); + + return out; +} + /* * Kconfig configuration printer * @@ -648,7 +691,7 @@ static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n, } if (sym->type == S_STRING && escape_string) { - escaped = sym_escape_string_value(val); + escaped = escape_string_value(val); val = escaped; } @@ -702,7 +745,7 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym) val_prefix = "0x"; break; case S_STRING: - escaped = sym_escape_string_value(val); + escaped = escape_string_value(val); val = escaped; default: break; diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index ec4a01bb60ce..edd1e617b25c 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -18,7 +18,6 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); -char *sym_escape_string_value(const char *in); void print_symbol_for_listconfig(struct symbol *sym); 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 6bf8665a6a0f..0572330bf8a7 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -871,50 +871,6 @@ struct symbol *sym_find(const char *name) return symbol; } -/* The returned pointer must be freed on the caller side */ -char *sym_escape_string_value(const char *in) -{ - const char *p; - size_t reslen; - char *res; - size_t l; - - reslen = strlen(in) + strlen("\"\"") + 1; - - p = in; - for (;;) { - l = strcspn(p, "\"\\"); - p += l; - - if (p[0] == '\0') - break; - - reslen++; - p++; - } - - res = xmalloc(reslen); - res[0] = '\0'; - - strcat(res, "\""); - - p = in; - for (;;) { - l = strcspn(p, "\"\\"); - strncat(res, p, l); - p += l; - - if (p[0] == '\0') - break; - - strcat(res, "\\"); - strncat(res, p++, 1); - } - - strcat(res, "\""); - return res; -} - struct sym_match { struct symbol *sym; off_t so, eo; From patchwork Fri Oct 1 05:32:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5D41C433FE for ; Fri, 1 Oct 2021 05:33:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1C0061052 for ; Fri, 1 Oct 2021 05:33:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238424AbhJAFfI (ORCPT ); Fri, 1 Oct 2021 01:35:08 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25308 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVY000646; Fri, 1 Oct 2021 14:33:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVY000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066381; bh=TY3pNDuHtjJvzRNvuIX7wXtebmfGI1zG24Lpl/V7eeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IEKR2PDn/KdO5HXPiyrfnsW1d/OsJ+9E2cPIRgo6lH8QNAtLB9JdkqDN6UsPq2hpc UXgV2UuWlda91GTIrgWi88nbq5cV7klPmuS3UL81abvNn8ttg8YC5Ylf4XjgriiOgY ykRrnmVzg3+1l6/D8SLY2QnaGYUUpkWKKi31ZCjn9t2LLtqSH0N4rbRzFvR87umLl0 u7+w1WCigqOq50N1AIDMYpTryULAWIB/PhbgI9nRgpxcoMXp7Sg9tuaCPFEdqtI9a/ 29ejGdBKpcdMLrvVNotvQrO21G6OtL0YHefsiQcw6MDGB+zOjXSkjgFD7EtswXXf5z 9UnDNwjbyBnfA== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 06/10] kconfig: add conf_get_autoheader_name() Date: Fri, 1 Oct 2021 14:32:49 +0900 Message-Id: <20211001053253.1223316-6-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org For consistency with conf_get_autoconfig_name() Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 78af1dd68894..2c518aaa5255 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -223,6 +223,13 @@ static const char *conf_get_autoconfig_name(void) return name ? name : "include/config/auto.conf"; } +static const char *conf_get_autoheader_name(void) +{ + char *name = getenv("KCONFIG_AUTOHEADER"); + + return name ? name : "include/generated/autoconf.h"; +} + static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) { char *p2; @@ -1092,9 +1099,7 @@ int conf_write_autoconf(int overwrite) fclose(out); fclose(out_h); - name = getenv("KCONFIG_AUTOHEADER"); - if (!name) - name = "include/generated/autoconf.h"; + name = conf_get_autoheader_name(); if (make_parent_dir(name)) return 1; if (rename(".tmpconfig.h", name)) From patchwork Fri Oct 1 05:32:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B781C433FE for ; Fri, 1 Oct 2021 05:33:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4237661A55 for ; Fri, 1 Oct 2021 05:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351998AbhJAFfI (ORCPT ); Fri, 1 Oct 2021 01:35:08 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25301 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVZ000646; Fri, 1 Oct 2021 14:33:02 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVZ000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066382; bh=imMcxxRBOk59LpGPgQvOavvO2pXMq6eJw3Tshj1dGOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XIS4NZEv7lQryZvIdtyKiL5AuLDzShsi3JpDVfP5d7mqN+3Nab40WSkPwq9b0NMnp cFyPnsVhhSCML6O4W9mvZJSYlHYMLotFjxovGheku6hfX9dGfBASB/g7f6jlZ22mfm 12t+1A/qO/nekmFDFe4uijLLmOERIArBW9w5ABPCG4XakLCnxy+l55GmJT5JaR8UBM IooldsX4PHzn2FQ2YG+FdFvPonD5uGJzf53l364YgTJoCZANF0ksAi4bbsWWshZlVN 8LxIy7DO0DXYniSIp/NDT/DBROsIuRRz//4CF2g3dCwRLqZGyVGaFkRDzWFT8OJoaw Lt9+3Gu2eQElw== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 07/10] kconfig: refactor conf_write_autoconf() Date: Fri, 1 Oct 2021 14:32:50 +0900 Message-Id: <20211001053253.1223316-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org This function does similar for auto.conf and autoconf.h Create __conf_write_autoconf() helper to factor out the common code. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 94 +++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 2c518aaa5255..6eb2c806fec0 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -1058,13 +1058,53 @@ static int conf_touch_deps(void) return 0; } +static int __conf_write_autoconf(const char *filename, + void (*print_symbol)(FILE *, struct symbol *), + const struct comment_style *comment_style) +{ + char tmp[PATH_MAX]; + FILE *file; + struct symbol *sym; + int ret, i; + + if (make_parent_dir(filename)) + return -1; + + ret = snprintf(tmp, sizeof(tmp), "%s.tmp", filename); + if (ret >= sizeof(tmp)) /* check truncation */ + return -1; + + file = fopen(tmp, "w"); + if (!file) { + perror("fopen"); + return -1; + } + + conf_write_heading(file, comment_style); + + for_all_symbols(i, sym) + if ((sym->flags & SYMBOL_WRITE) && sym->name) + print_symbol(file, sym); + + /* check possible errors in conf_write_heading() and print_symbol() */ + if (ferror(file)) + return -1; + + fclose(file); + + if (rename(tmp, filename)) { + perror("rename"); + return -1; + } + + return 0; +} + int conf_write_autoconf(int overwrite) { struct symbol *sym; - const char *name; const char *autoconf_name = conf_get_autoconfig_name(); - FILE *out, *out_h; - int i; + int ret, i; if (!overwrite && is_present(autoconf_name)) return 0; @@ -1074,45 +1114,25 @@ int conf_write_autoconf(int overwrite) if (conf_touch_deps()) return 1; - out = fopen(".tmpconfig", "w"); - if (!out) - return 1; - - out_h = fopen(".tmpconfig.h", "w"); - if (!out_h) { - fclose(out); - return 1; - } - - conf_write_heading(out, &comment_style_pound); - conf_write_heading(out_h, &comment_style_c); - - for_all_symbols(i, sym) { + for_all_symbols(i, sym) sym_calc_value(sym); - if (!(sym->flags & SYMBOL_WRITE) || !sym->name) - continue; - /* write symbols to auto.conf and autoconf.h */ - print_symbol_for_autoconf(out, sym); - print_symbol_for_c(out_h, sym); - } - fclose(out); - fclose(out_h); - - name = conf_get_autoheader_name(); - if (make_parent_dir(name)) - return 1; - if (rename(".tmpconfig.h", name)) - return 1; + ret = __conf_write_autoconf(conf_get_autoheader_name(), + print_symbol_for_c, + &comment_style_c); + if (ret) + return ret; - if (make_parent_dir(autoconf_name)) - return 1; /* - * This must be the last step, kbuild has a dependency on auto.conf - * and this marks the successful completion of the previous steps. + * Create include/config/auto.conf. This must be the last step because + * Kbuild has a dependency on auto.conf and this marks the successful + * completion of the previous steps. */ - if (rename(".tmpconfig", autoconf_name)) - return 1; + ret = __conf_write_autoconf(conf_get_autoconfig_name(), + print_symbol_for_autoconf, + &comment_style_pound); + if (ret) + return ret; return 0; } From patchwork Fri Oct 1 05:32:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E340BC433F5 for ; Fri, 1 Oct 2021 05:33:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0226619F5 for ; Fri, 1 Oct 2021 05:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351969AbhJAFfH (ORCPT ); Fri, 1 Oct 2021 01:35:07 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25298 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351850AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVa000646; Fri, 1 Oct 2021 14:33:02 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVa000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066382; bh=WTpKMRil49Ua4S75pS4uC3uoC8dv8trD2opZWKxINlY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WlqaepZjENagIx2wkk3vOaEPy6e4jNyfVfE2x86FCNkSezGV3hgzZwYlxodhaRuD8 yxzcDtphUN+NBmnQ5ZC23JUBwiyz339SQ/mHicl0rtTmtJeHJ9usUh13wNbkTUuexl q4BvY2WU6XMQRgbvTRnfxG9sQ1xSuaROvNjXpWT2CaohTckZphB/rLa5Wnxoyfipnv zw7qR4zFsc95drlHMDsVre3jZWjocO+sRFuatjNwbAkcEBO9na1Mid8WkbdRKeSfsh YbWM3DyBv4/A9Ttarry1eahZH0iX9+cfAWI6zfe56oMpmKwmQs9xbBDQKCdQ9/VMMq DuSxA1BCyPTwQ== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 08/10] kconfig: refactor conf_write_dep() Date: Fri, 1 Oct 2021 14:32:51 +0900 Message-Id: <20211001053253.1223316-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org The if ... else inside the for-loop is unneeded because one empty line is placed after printing the last element of deps_config. Currently, all errors in conf_write_dep() are ignored. Add proper error checks. Rename it to conf_write_autoconf_cmd(), which is more intuitive. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 54 ++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 6eb2c806fec0..75e45e69d660 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -957,32 +957,50 @@ int conf_write(const char *name) } /* write a dependency file as used by kbuild to track dependencies */ -static int conf_write_dep(const char *name) +static int conf_write_autoconf_cmd(const char *autoconf_name) { + char name[PATH_MAX], tmp[PATH_MAX]; struct file *file; FILE *out; + int ret; - out = fopen("..config.tmp", "w"); - if (!out) - return 1; - fprintf(out, "deps_config := \\\n"); - for (file = file_list; file; file = file->next) { - if (file->next) - fprintf(out, "\t%s \\\n", file->name); - else - fprintf(out, "\t%s\n", file->name); + ret = snprintf(name, sizeof(name), "%s.cmd", autoconf_name); + if (ret >= sizeof(name)) /* check truncation */ + return -1; + + if (make_parent_dir(name)) + return -1; + + ret = snprintf(tmp, sizeof(tmp), "%s.cmd.tmp", autoconf_name); + if (ret >= sizeof(tmp)) /* check truncation */ + return -1; + + out = fopen(tmp, "w"); + if (!out) { + perror("fopen"); + return -1; } - fprintf(out, "\n%s: \\\n" - "\t$(deps_config)\n\n", conf_get_autoconfig_name()); - env_write_dep(out, conf_get_autoconfig_name()); + fprintf(out, "deps_config := \\\n"); + for (file = file_list; file; file = file->next) + fprintf(out, "\t%s \\\n", file->name); + + fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); + + env_write_dep(out, autoconf_name); fprintf(out, "\n$(deps_config): ;\n"); + + if (ferror(out)) /* error check for all fprintf() calls */ + return -1; + fclose(out); - if (make_parent_dir(name)) - return 1; - rename("..config.tmp", name); + if (rename(tmp, name)) { + perror("rename"); + return -1; + } + return 0; } @@ -1109,7 +1127,9 @@ int conf_write_autoconf(int overwrite) if (!overwrite && is_present(autoconf_name)) return 0; - conf_write_dep("include/config/auto.conf.cmd"); + ret = conf_write_autoconf_cmd(autoconf_name); + if (ret) + return -1; if (conf_touch_deps()) return 1; From patchwork Fri Oct 1 05:32:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62901C4167E for ; Fri, 1 Oct 2021 05:33:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2591061052 for ; Fri, 1 Oct 2021 05:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352063AbhJAFfS (ORCPT ); Fri, 1 Oct 2021 01:35:18 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25300 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351929AbhJAFfH (ORCPT ); Fri, 1 Oct 2021 01:35:07 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVb000646; Fri, 1 Oct 2021 14:33:03 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVb000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066383; bh=Iqm0ebRv9z0IooNy+Maz2A58TgKBK4bu96UGV+0zUbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XoK5/WIOrS1P3CE36GBpfutpt7q9hacupBQSM4JdI8ggAvvAJM2Pp9YqZGqMRluha wX5yGYIppYOr8kvCTWD/oIgEm54K6QYj7zJ3/lvyayk1FrWjCdSGrfcMkYGaGelxUv rmUSPZbZ5xVwePpBQv8pzDnvsNe0XV7LCJM3ftJzP1DRW7Byrelk0mV3YAnf1gqXtA AXzCHE2GbsaoQlK1lXN4DuD91yym18UAdKBxRpAt+iT0BWif9Qlcheq+MnC0m5vyeW Q1QjfhpV+DesCBKFesqVTDOxv5zlEGVEUphN6fHKrmjgr5xp8hExFeQRwumxjdsZZD TP2dV6bQ/h+pw== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 09/10] kconfig: refactor conf_touch_dep() Date: Fri, 1 Oct 2021 14:32:52 +0900 Message-Id: <20211001053253.1223316-9-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org If this function fails to touch a dummy header due to missing parent directory, then it creates it and touches the file again. This was needed because CONFIG_FOO_BAR was previously tracked by include/config/foo/bar.h. (include/config/foo/ may not exist here) This is no longer the case since commit 0e0345b77ac4 ("kbuild: redo fake deps at include/config/*.h"); now all the fake headers are placed right under include/config/, like include/config/FOO_BAR. Do not try to create parent directory, include/config/, which already exists. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 75e45e69d660..9ece2f3b61a6 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -130,31 +130,17 @@ static size_t depfile_prefix_len; /* touch depfile for symbol 'name' */ static int conf_touch_dep(const char *name) { - int fd, ret; - char *d; + int fd; /* check overflow: prefix + name + '\0' must fit in buffer. */ if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path)) return -1; - d = depfile_path + depfile_prefix_len; - strcpy(d, name); + strcpy(depfile_path + depfile_prefix_len, name); - /* Assume directory path already exists. */ fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd == -1) { - if (errno != ENOENT) - return -1; - - ret = make_parent_dir(depfile_path); - if (ret) - return ret; - - /* Try it again. */ - fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd == -1) - return -1; - } + if (fd == -1) + return -1; close(fd); return 0; From patchwork Fri Oct 1 05:32:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12529707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37128C4321E for ; Fri, 1 Oct 2021 05:33:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 196A8619F5 for ; Fri, 1 Oct 2021 05:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352070AbhJAFfP (ORCPT ); Fri, 1 Oct 2021 01:35:15 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25299 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351892AbhJAFfG (ORCPT ); Fri, 1 Oct 2021 01:35:06 -0400 Received: from grover.. (133-32-232-101.west.xps.vectant.ne.jp [133.32.232.101]) (authenticated) by conuserg-10.nifty.com with ESMTP id 1915WwVc000646; Fri, 1 Oct 2021 14:33:03 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 1915WwVc000646 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1633066383; bh=fDT5+bUlmH+NExGoDYLtSJAw+fxo+1QQtTvlcIJMHwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cXFbXehx1QWuFwCVzhp2mFbtwDDEQ7QqbvsoqRkGxjxvL0er5zGEG63RET1wr4KNs n1MpfNnVedHTKK2HacwwlBJrIgBOBYgB6t/tulFqyN5Qd93ecgqsgoJXiim7u+pmzp iPj/FctWVeF7/aKXrINK/ImPj3JmSHmSdR/Ha8W/LRBuQt0WNizZ8u0CAi4SlfKXN5 m6ZFFEOgDczaQvi8/l9iz89Q9oR/QqA9e8FuNJanzntLc2n0wTVEDRHhubTeZ6mDxc bewuUnCHV8o1yw47yhaAoj9/1Xj5MOuOaPgENc83EGCNXOrd+dZ+ZsDUb/8c5+OMvb IZB+LaH2pX2cw== X-Nifty-SrcIP: [133.32.232.101] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 10/10] [for next only] kconfig: generate include/generated/rustc_cfg Date: Fri, 1 Oct 2021 14:32:53 +0900 Message-Id: <20211001053253.1223316-10-masahiroy@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001053253.1223316-1-masahiroy@kernel.org> References: <20211001053253.1223316-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org This patch is not intended for the mainline. I created this patch for Stephen Rothwell to resolve the merge conflicts more easily. The Rust tree is touching scripts/kconfig/confdata.c to generate include/generated/rustc_cfg, which would cause complicated conflicts with changes from the kbuild tree. I re-implemented it to produce the equaivalent rustc_cfg. I also fixed the memory leak; the original code from the Rust tree did not free the malloc'ed pointer. Stephen: When you resolve the conflicts in confdata.c, please take this one. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 9ece2f3b61a6..4767f3810cf4 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -603,6 +603,9 @@ static const struct comment_style comment_style_c = { static void conf_write_heading(FILE *fp, const struct comment_style *cs) { + if (!cs) /* no heading for rustc_cfg? */ + return; + fprintf(fp, "%s\n", cs->comment_block_begin); fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n", @@ -750,6 +753,39 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym) free(escaped); } +/* rustc configuration */ +static void print_symbol_for_rustc_cfg(FILE *fp, struct symbol *sym) +{ + const char *val; + char *escaped; + + if (sym->type == S_UNKNOWN) + return; + + val = sym_get_string_value(sym); + escaped = escape_string_value(val); + + if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE) { + if (*val == 'n') + return; + + /* + * To have similar functionality to the C macro `IS_ENABLED()` + * we provide an empty `--cfg CONFIG_X` here in both `y` + * and `m` cases. + * + * Then, the common `fprintf()` below will also give us + * a `--cfg CONFIG_X="y"` or `--cfg CONFIG_X="m"`, which can + * be used as the equivalent of `IS_BUILTIN()`/`IS_MODULE()`. + */ + fprintf(fp, "--cfg=%s%s\n", CONFIG_, sym->name); + } + + fprintf(fp, "--cfg=%s%s=%s\n", CONFIG_, sym->name, escaped); + + free(escaped); +} + /* * Write out a minimal config. * All values that has default values are skipped as this is redundant. @@ -1129,6 +1165,12 @@ int conf_write_autoconf(int overwrite) if (ret) return ret; + ret = __conf_write_autoconf("include/generated/rustc_cfg", + print_symbol_for_rustc_cfg, + NULL); + if (ret) + return ret; + /* * Create include/config/auto.conf. This must be the last step because * Kbuild has a dependency on auto.conf and this marks the successful