public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "M. Vefa Bicakci" <m.v.b@runbox.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: linux-kbuild@vger.kernel.org, joonas.kylmala@iki.fi,
	ulfalizer@gmail.com, linux-stable <stable@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kconfig: fix missing choice values in auto.conf
Date: Fri, 2 Aug 2019 19:52:43 -0400	[thread overview]
Message-ID: <20190802195243.09a87651@runbox.com> (raw)
In-Reply-To: <20190712060709.20609-1-yamada.masahiro@socionext.com>

Hello,

> conf_write() must be changed accordingly. Currently, it clears
> SYMBOL_WRITE after the symbol is written into the .config file. This
> is needed to prevent it from writing the same symbol multiple times in
> case the symbol is declared in two or more locations. I added the new
> flag SYMBOL_WRITTEN, to track the symbols that have been written.
[snip]
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index cbb6efa4a5a6..e0972b255aac 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
[snip]
> @@ -903,7 +904,7 @@ int conf_write(const char *name)
>  				fprintf(out, "\n");
>  				need_newline = false;
>  			}
> -			sym->flags &= ~SYMBOL_WRITE;
> +			sym->flags |= SYMBOL_WRITTEN;

The SYMBOL_WRITTEN flag is never cleared after being set in this
function, which unfortunately causes data loss to occur when a user
starts xconfig, gconfig, or nconfig and saves a config file more than
once. Every save operation after the first one causes the saved .config
file to contain only comments.

I am appending a patch that resolves this issue. The patch is a bit
ugly because of the code duplication, but it fixes this bug. (I have
lightly tested the patch.) Even if the patch is not merged, I would
appreciate it if this bug could be fixed.

Thank you,

Vefa

=== 8< === Patch Follows === >8 ===

From: "M. Vefa Bicakci" <m.v.b@runbox.com>
Date: Fri, 2 Aug 2019 17:44:40 -0400
Subject: [PATCH] kconfig: Clear "written" flag to avoid data loss

Prior to this commit, starting nconfig, xconfig or gconfig, and saving
the .config file more than once caused data loss, where a .config file
that contained only comments would be written to disk starting from the
second save operation.

This bug manifests itself because the SYMBOL_WRITTEN flag is never
cleared after the first call to conf_write, and subsequent calls to
conf_write then skip all of the configuration symbols due to the
SYMBOL_WRITTEN flag being set.

This commit resolves this issue by clearing the SYMBOL_WRITTEN flag
from all symbols before conf_write returns.

Fixes: 8e2442a5f86e ("kconfig: fix missing choice values in auto.conf")
Cc: linux-stable <stable@vger.kernel.org> # 4.19+
Signed-off-by: M. Vefa Bicakci <m.v.b@runbox.com>
---
 scripts/kconfig/confdata.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 1134892599da..24fe0c851e8c 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -840,6 +840,35 @@ int conf_write_defconfig(const char *filename)
 	return 0;
 }
 
+static void conf_clear_written_flag(void)
+{
+	struct menu *menu;
+	struct symbol *sym;
+
+	menu = rootmenu.list;
+	while (menu) {
+		sym = menu->sym;
+		if (sym && (sym->flags & SYMBOL_WRITTEN))
+			sym->flags &= ~SYMBOL_WRITTEN;
+
+		if (menu->list) {
+			menu = menu->list;
+			continue;
+		}
+
+		if (menu->next) {
+			menu = menu->next;
+		} else {
+			while ((menu = menu->parent)) {
+				if (menu->next) {
+					menu = menu->next;
+					break;
+				}
+			}
+		}
+	}
+}
+
 int conf_write(const char *name)
 {
 	FILE *out;
@@ -930,6 +959,8 @@ int conf_write(const char *name)
 	}
 	fclose(out);
 
+	conf_clear_written_flag();
+
 	if (*tmpname) {
 		if (is_same(name, tmpname)) {
 			conf_message("No change to %s", name);
-- 
2.21.0


  parent reply	other threads:[~2019-08-03  0:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-12  6:07 [PATCH] kconfig: fix missing choice values in auto.conf Masahiro Yamada
2019-07-12 10:59 ` Joonas Kylmälä
2019-08-02 23:52 ` M. Vefa Bicakci [this message]
2019-08-03  2:32   ` Masahiro Yamada
2019-08-03 10:02     ` [PATCH v2] kconfig: Clear "written" flag to avoid data loss M. Vefa Bicakci
2019-08-04  3:50       ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190802195243.09a87651@runbox.com \
    --to=m.v.b@runbox.com \
    --cc=joonas.kylmala@iki.fi \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=ulfalizer@gmail.com \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox