[PATCH v2] kconfig: Clear "written" flag to avoid data loss

From: M. Vefa Bicakci
Date: Sat Aug 03 2019 - 06:02:48 EST

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@xxxxxxxxxxxxxxx> # 4.19+
Signed-off-by: M. Vefa Bicakci <m.v.b@xxxxxxxxxx>


Changes since v1:
* As suggested by Masahiro Yamada, instead of defining a new helper
function to traverse over all symbols in a pre-defined order, use
the for_all_symbols iterator.
scripts/kconfig/confdata.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 1134892599da..3569d2dec37c 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -848,6 +848,7 @@ int conf_write(const char *name)
const char *str;
char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1];
char *env;
+ int i;
bool need_newline = false;

if (!name)
@@ -930,6 +931,9 @@ int conf_write(const char *name)

+ for_all_symbols(i, sym)
+ sym->flags &= ~SYMBOL_WRITTEN;
if (*tmpname) {
if (is_same(name, tmpname)) {
conf_message("No change to %s", name);