Commit fb0fecf2 authored by Masahiro Yamada's avatar Masahiro Yamada Committed by Wentao Guan
Browse files

kconfig: deduplicate code in conf_read_simple()

stable inclusion
from stable-v6.6.76
commit 487852a55a4817421907a2957718848efa4b6a85
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBW08Q

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=487852a55a4817421907a2957718848efa4b6a85



--------------------------------

[ Upstream commit d854b4b21de684a16a7d6163c7b0e9c5ff8a09d3 ]

Kconfig accepts both "# CONFIG_FOO is not set" and "CONFIG_FOO=n" as
a valid input, but conf_read_simple() duplicates similar code to handle
them. Factor out the common code.

Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Stable-dep-of: a409fc1463d6 ("kconfig: fix memory leak in sym_warn_unmet_dep()")
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
(cherry picked from commit 487852a55a4817421907a2957718848efa4b6a85)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent f80bffeb
Loading
Loading
Loading
Loading
+35 −54
Original line number Diff line number Diff line
@@ -346,11 +346,10 @@ int conf_read_simple(const char *name, int def)
	FILE *in = NULL;
	char   *line = NULL;
	size_t  line_asize = 0;
	char *p, *p2;
	char *p, *p2, *val;
	struct symbol *sym;
	int i, def_flags;
	const char *warn_unknown;
	const char *werror;
	const char *warn_unknown, *werror, *sym_name;

	warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
	werror = getenv("KCONFIG_WERROR");
@@ -430,84 +429,66 @@ int conf_read_simple(const char *name, int def)

	while (compat_getline(&line, &line_asize, in) != -1) {
		conf_lineno++;
		sym = NULL;
		if (line[0] == '#') {
			if (line[1] != ' ')
				continue;
			if (memcmp(line + 2, CONFIG_, strlen(CONFIG_)))
			p = line + 2;
			if (memcmp(p, CONFIG_, strlen(CONFIG_)))
				continue;
			p = strchr(line + 2 + strlen(CONFIG_), ' ');
			sym_name = p + strlen(CONFIG_);
			p = strchr(sym_name, ' ');
			if (!p)
				continue;
			*p++ = 0;
			if (strncmp(p, "is not set", 10))
				continue;

			sym = sym_find(line + 2 + strlen(CONFIG_));
			if (!sym) {
				if (warn_unknown)
					conf_warning("unknown symbol: %s",
						     line + 2 + strlen(CONFIG_));

				conf_set_changed(true);
				continue;
			}
			if (sym->flags & def_flags) {
				conf_warning("override: reassigning to symbol %s", sym->name);
			}
			switch (sym->type) {
			case S_BOOLEAN:
			case S_TRISTATE:
				sym->def[def].tri = no;
				sym->flags |= def_flags;
				break;
			default:
				;
			}
			val = "n";
		} else if (memcmp(line, CONFIG_, strlen(CONFIG_)) == 0) {
			p = strchr(line + strlen(CONFIG_), '=');
			sym_name = line + strlen(CONFIG_);
			p = strchr(sym_name, '=');
			if (!p)
				continue;
			*p++ = 0;
			val = p;
			p2 = strchr(p, '\n');
			if (p2) {
				*p2-- = 0;
				if (*p2 == '\r')
					*p2 = 0;
			}
		} else {
			if (line[0] != '\r' && line[0] != '\n')
				conf_warning("unexpected data: %.*s",
					     (int)strcspn(line, "\r\n"), line);

			continue;
		}

			sym = sym_find(line + strlen(CONFIG_));
		sym = sym_find(sym_name);
		if (!sym) {
			if (def == S_DEF_AUTO) {
				/*
					 * Reading from include/config/auto.conf
					 * If CONFIG_FOO previously existed in
					 * auto.conf but it is missing now,
					 * include/config/FOO must be touched.
				 * Reading from include/config/auto.conf.
				 * If CONFIG_FOO previously existed in auto.conf
				 * but it is missing now, include/config/FOO
				 * must be touched.
				 */
					conf_touch_dep(line + strlen(CONFIG_));
				conf_touch_dep(sym_name);
			} else {
				if (warn_unknown)
						conf_warning("unknown symbol: %s",
							     line + strlen(CONFIG_));
					conf_warning("unknown symbol: %s", sym_name);

				conf_set_changed(true);
			}
			continue;
		}

			if (sym->flags & def_flags) {
		if (sym->flags & def_flags)
			conf_warning("override: reassigning to symbol %s", sym->name);
			}
			if (conf_set_sym_val(sym, def, def_flags, p))
				continue;
		} else {
			if (line[0] != '\r' && line[0] != '\n')
				conf_warning("unexpected data: %.*s",
					     (int)strcspn(line, "\r\n"), line);

		if (conf_set_sym_val(sym, def, def_flags, val))
			continue;
		}

		if (sym && sym_is_choice_value(sym)) {
			struct symbol *cs = prop_get_symbol(sym_get_choice_prop(sym));