Skip to contentSkip to conversation

kconfig: add fflush() before ferror() check

PATCH In review Masahiro Yamada 1 participant 2 messages Feb 12, 2022 – Feb 18, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kconfig: add fflush() before ferror() check

As David Laight pointed out, there is not much point in calling ferror() unless you call fflush() first.

---

 scripts/kconfig/confdata.c | 2 ++
 1 file changed, 2 insertions(+)
scripts/kconfig/confdata.c +2 -0
index d3c3a61308ad..94dcec2cc803 100644
@@ -979,6 +979,7 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
 
 	fprintf(out, "\n$(deps_config): ;\n");
 
+	fflush(out);
 	ret = ferror(out); /* error check for all fprintf() calls */
 	fclose(out);
 	if (ret)
@@ -1097,6 +1098,7 @@ static int __conf_write_autoconf(const char *filename,
 		if ((sym->flags & SYMBOL_WRITE) && sym->name)
 			print_symbol(file, sym);
 
+	fflush(file);
 	/* check possible errors in conf_write_heading() and print_symbol() */
 	ret = ferror(file);
 	fclose(file);
Signature · 1 line
2.32.0
#1 lore raw
Quoted 7 lines · Masahiro Yamada

As David Laight pointed out, there is not much point in calling ferror() unless you call fflush() first.

---

Applied to linux-kbuild.

Quoted 27 lines
 scripts/kconfig/confdata.c | 2 ++
 1 file changed, 2 insertions(+)
scripts/kconfig/confdata.c +2 -1
index d3c3a61308ad..94dcec2cc803 100644
@@ -979,6 +979,7 @@ static int conf_write_autoconf_cmd(const char *autoconf_name)
 
        fprintf(out, "\n$(deps_config): ;\n");
 
+       fflush(out);
        ret = ferror(out); /* error check for all fprintf() calls */
        fclose(out);
        if (ret)
@@ -1097,6 +1098,7 @@ static int __conf_write_autoconf(const char *filename,
                if ((sym->flags & SYMBOL_WRITE) && sym->name)
                        print_symbol(file, sym);
 
+       fflush(file);
        /* check possible errors in conf_write_heading() and print_symbol() */
        ret = ferror(file);
        fclose(file);
--

2.32.0

Signature · 2 lines
Best Regards
Masahiro Yamada