Commit 700c48b4 authored by Masahiro Yamada's avatar Masahiro Yamada

modpost: use null string instead of NULL pointer for default namespace

The default namespace is the null string, "".

When set, the null string "" is converted to NULL:

  s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL;

When printed, the NULL pointer is get back to the null string:

  sym->namespace ?: ""

This saves 1 byte memory allocated for "", but loses the readability.

In kernel-space, we strive to save memory, but modpost is a userspace
tool used to build the kernel. On modern systems, such small piece of
memory is not a big deal.

Handle the namespace string as is.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
parent 6e7611c4
...@@ -300,6 +300,13 @@ static bool contains_namespace(struct list_head *head, const char *namespace) ...@@ -300,6 +300,13 @@ static bool contains_namespace(struct list_head *head, const char *namespace)
{ {
struct namespace_list *list; struct namespace_list *list;
/*
* The default namespace is null string "", which is always implicitly
* contained.
*/
if (!namespace[0])
return true;
list_for_each_entry(list, head, list) { list_for_each_entry(list, head, list) {
if (!strcmp(list->namespace, namespace)) if (!strcmp(list->namespace, namespace))
return true; return true;
...@@ -369,7 +376,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod, ...@@ -369,7 +376,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
s = alloc_symbol(name); s = alloc_symbol(name);
s->module = mod; s->module = mod;
s->is_gpl_only = gpl_only; s->is_gpl_only = gpl_only;
s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; s->namespace = NOFAIL(strdup(namespace));
list_add_tail(&s->list, &mod->exported_symbols); list_add_tail(&s->list, &mod->exported_symbols);
hash_add_symbol(s); hash_add_symbol(s);
...@@ -1829,8 +1836,7 @@ static void check_exports(struct module *mod) ...@@ -1829,8 +1836,7 @@ static void check_exports(struct module *mod)
else else
basename = mod->name; basename = mod->name;
if (exp->namespace && if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR, modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
"module %s uses symbol %s from namespace %s, but does not import it.\n", "module %s uses symbol %s from namespace %s, but does not import it.\n",
basename, exp->name, exp->namespace); basename, exp->name, exp->namespace);
...@@ -1916,8 +1922,7 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod) ...@@ -1916,8 +1922,7 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod)
list_for_each_entry(sym, &mod->exported_symbols, list) list_for_each_entry(sym, &mod->exported_symbols, list)
buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n", buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n",
sym->is_func ? "FUNC" : "DATA", sym->name, sym->is_func ? "FUNC" : "DATA", sym->name,
sym->is_gpl_only ? "_gpl" : "", sym->is_gpl_only ? "_gpl" : "", sym->namespace);
sym->namespace ?: "");
if (!modversions) if (!modversions)
return; return;
...@@ -2185,7 +2190,7 @@ static void write_dump(const char *fname) ...@@ -2185,7 +2190,7 @@ static void write_dump(const char *fname)
buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n", buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n",
sym->crc, sym->name, mod->name, sym->crc, sym->name, mod->name,
sym->is_gpl_only ? "_GPL" : "", sym->is_gpl_only ? "_GPL" : "",
sym->namespace ?: ""); sym->namespace);
} }
} }
write_buf(&buf, fname); write_buf(&buf, fname);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment