]> git.baikalelectronics.ru Git - kernel.git/commit
module: swap the order of symbol.namespace
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Thu, 3 Oct 2019 07:58:21 +0000 (16:58 +0900)
committerJessica Yu <jeyu@kernel.org>
Mon, 7 Oct 2019 16:24:48 +0000 (18:24 +0200)
commit2812a0623add8b86b5e6a048cceaaf32a8694d72
treea1560c25488553e750ca04152719a1b9d5abaff7
parent5606c69cdef93c7ba90addeac0d4678df931cb05
module: swap the order of symbol.namespace

Currently, EXPORT_SYMBOL_NS(_GPL) constructs the kernel symbol as
follows:

  __ksymtab_SYMBOL.NAMESPACE

The sym_extract_namespace() in modpost allocates memory for the part
SYMBOL.NAMESPACE when '.' is contained. One problem is that the pointer
returned by strdup() is lost because the symbol name will be copied to
malloc'ed memory by alloc_symbol(). No one will keep track of the
pointer of strdup'ed memory.

sym->namespace still points to the NAMESPACE part. So, you can free it
with complicated code like this:

   free(sym->namespace - strlen(sym->name) - 1);

It complicates memory free.

To fix it elegantly, I swapped the order of the symbol and the
namespace as follows:

  __ksymtab_NAMESPACE.SYMBOL

then, simplified sym_extract_namespace() so that it allocates memory
only for the NAMESPACE part.

I prefer this order because it is intuitive and also matches to major
languages. For example, NAMESPACE::NAME in C++, MODULE.NAME in Python.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
include/linux/export.h
scripts/mod/modpost.c