Skip to content

Commit 700c48b

Browse files
committed
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: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
1 parent 6e7611c commit 700c48b

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

scripts/mod/modpost.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ static bool contains_namespace(struct list_head *head, const char *namespace)
300300
{
301301
struct namespace_list *list;
302302

303+
/*
304+
* The default namespace is null string "", which is always implicitly
305+
* contained.
306+
*/
307+
if (!namespace[0])
308+
return true;
309+
303310
list_for_each_entry(list, head, list) {
304311
if (!strcmp(list->namespace, namespace))
305312
return true;
@@ -369,7 +376,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
369376
s = alloc_symbol(name);
370377
s->module = mod;
371378
s->is_gpl_only = gpl_only;
372-
s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL;
379+
s->namespace = NOFAIL(strdup(namespace));
373380
list_add_tail(&s->list, &mod->exported_symbols);
374381
hash_add_symbol(s);
375382

@@ -1829,8 +1836,7 @@ static void check_exports(struct module *mod)
18291836
else
18301837
basename = mod->name;
18311838

1832-
if (exp->namespace &&
1833-
!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
1839+
if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {
18341840
modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
18351841
"module %s uses symbol %s from namespace %s, but does not import it.\n",
18361842
basename, exp->name, exp->namespace);
@@ -1916,8 +1922,7 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod)
19161922
list_for_each_entry(sym, &mod->exported_symbols, list)
19171923
buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n",
19181924
sym->is_func ? "FUNC" : "DATA", sym->name,
1919-
sym->is_gpl_only ? "_gpl" : "",
1920-
sym->namespace ?: "");
1925+
sym->is_gpl_only ? "_gpl" : "", sym->namespace);
19211926

19221927
if (!modversions)
19231928
return;
@@ -2185,7 +2190,7 @@ static void write_dump(const char *fname)
21852190
buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n",
21862191
sym->crc, sym->name, mod->name,
21872192
sym->is_gpl_only ? "_GPL" : "",
2188-
sym->namespace ?: "");
2193+
sym->namespace);
21892194
}
21902195
}
21912196
write_buf(&buf, fname);

0 commit comments

Comments
 (0)