linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Maennich <maennich@google.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Jessica Yu <jeyu@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Joel Fernandes <joel@joelfernandes.org>,
	Martijn Coenen <maco@android.com>,
	Will Deacon <will.deacon@arm.com>,
	Michal Marek <michal.lkml@markovi.net>,
	Will Deacon <will@kernel.org>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] module: swap the order of symbol.namespace
Date: Fri, 27 Sep 2019 13:07:25 +0100	[thread overview]
Message-ID: <20190927120725.GB259443@google.com> (raw)
In-Reply-To: <20190927093603.9140-3-yamada.masahiro@socionext.com>

On Fri, Sep 27, 2019 at 06:35:58PM +0900, Masahiro Yamada wrote:
>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, if you like,
>you can free it with complicated code like this:
>
>   free(sym->namespace - strlen(sym->name) - 1);
>
>I would not say it is fatal since we seldom bother to manually free
>memory in host programs. But, I can fix it in an elegant way.
>
>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.

I agree with this rationale and like the implementation. I believe the
idea of appending the namespace came from being afraid of other tools
facing the problem of parsing the namespace out of the middle of the
entry. Thanks for this improvement.

Reviewed-by: Matthias Maennich <maennich@google.com>

Cheers,
Matthias

>Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>---
>
> include/linux/export.h |  4 ++--
> scripts/mod/modpost.c  | 16 +++++++---------
> 2 files changed, 9 insertions(+), 11 deletions(-)
>
>diff --git a/include/linux/export.h b/include/linux/export.h
>index 95f55b7f83a0..0695d4e847d9 100644
>--- a/include/linux/export.h
>+++ b/include/linux/export.h
>@@ -52,7 +52,7 @@ extern struct module __this_module;
> 	__ADDRESSABLE(sym)						\
> 	asm("	.section \"___ksymtab" sec "+" #sym "\", \"a\"	\n"	\
> 	    "	.balign	4					\n"	\
>-	    "__ksymtab_" #sym NS_SEPARATOR #ns ":		\n"	\
>+	    "__ksymtab_" #ns NS_SEPARATOR #sym ":		\n"	\
> 	    "	.long	" #sym "- .				\n"	\
> 	    "	.long	__kstrtab_" #sym "- .			\n"	\
> 	    "	.long	__kstrtab_ns_" #sym "- .		\n"	\
>@@ -76,7 +76,7 @@ struct kernel_symbol {
> #else
> #define __KSYMTAB_ENTRY_NS(sym, sec, ns)				\
> 	static const struct kernel_symbol __ksymtab_##sym##__##ns	\
>-	asm("__ksymtab_" #sym NS_SEPARATOR #ns)				\
>+	asm("__ksymtab_" #ns NS_SEPARATOR #sym)				\
> 	__attribute__((section("___ksymtab" sec "+" #sym), used))	\
> 	__aligned(sizeof(void *))					\
> 	= { (unsigned long)&sym, __kstrtab_##sym, __kstrtab_ns_##sym }
>diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
>index 5c628a7d80f7..d171b0cffb05 100644
>--- a/scripts/mod/modpost.c
>+++ b/scripts/mod/modpost.c
>@@ -350,18 +350,16 @@ static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
>
> static const char *sym_extract_namespace(const char **symname)
> {
>-	size_t n;
>-	char *dupsymname;
>+	char *namespace = NULL;
>+	char *ns_separator;
>
>-	n = strcspn(*symname, ".");
>-	if (n < strlen(*symname) - 1) {
>-		dupsymname = NOFAIL(strdup(*symname));
>-		dupsymname[n] = '\0';
>-		*symname = dupsymname;
>-		return dupsymname + n + 1;
>+	ns_separator = strchr(*symname, '.');
>+	if (ns_separator) {
>+		namespace = NOFAIL(strndup(*symname, ns_separator - *symname));
>+		*symname = ns_separator + 1;
> 	}
>
>-	return NULL;
>+	return namespace;
> }
>
> /**
>-- 
>2.17.1
>

  reply	other threads:[~2019-09-27 12:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-27  9:35 [PATCH 0/7] module: various bug-fixes and clean-ups for module namespace Masahiro Yamada
2019-09-27  9:35 ` [PATCH 1/7] modpost: fix broken sym->namespace for external module builds Masahiro Yamada
2019-09-27  9:56   ` Masahiro Yamada
2019-09-27 11:46   ` Matthias Maennich
2019-09-27  9:35 ` [PATCH 2/7] module: swap the order of symbol.namespace Masahiro Yamada
2019-09-27 12:07   ` Matthias Maennich [this message]
2019-09-27  9:35 ` [PATCH 3/7] module: rename __kstrtab_ns_* to __kstrtabns_* to avoid symbol conflict Masahiro Yamada
2019-09-27 12:14   ` Matthias Maennich
2019-09-27  9:36 ` [PATCH 4/7] module: avoid code duplication in include/linux/export.h Masahiro Yamada
2019-09-27  9:58   ` Masahiro Yamada
2019-09-27 11:07   ` Rasmus Villemoes
2019-09-27 12:36     ` Matthias Maennich
2019-10-29 19:19     ` Jessica Yu
2019-10-29 21:11       ` Rasmus Villemoes
2019-10-31 10:13         ` Jessica Yu
2019-10-31 11:03           ` Rasmus Villemoes
2019-10-31 11:26             ` Jessica Yu
2019-09-27  9:36 ` [PATCH 5/7] kbuild: fix build error of 'make nsdeps' in clean tree Masahiro Yamada
2019-09-27 12:44   ` Matthias Maennich
2019-09-27  9:36 ` [PATCH 6/7] nsdeps: fix hashbang of scripts/nsdeps Masahiro Yamada
2019-09-27 13:10   ` Matthias Maennich
2019-09-27  9:36 ` [PATCH 7/7] nsdeps: make generated patches independent of locale Masahiro Yamada
2019-09-27 13:27   ` Matthias Maennich
2019-09-27 15:42     ` Masahiro Yamada
2019-09-27 18:14       ` Greg Kroah-Hartman
2019-09-29  1:18         ` Masahiro Yamada
2019-09-29  1:30           ` Masahiro Yamada
2019-10-01 11:46             ` Matthias Maennich
2019-09-29 10:14           ` Greg Kroah-Hartman
2019-09-27 13:41 ` [PATCH 0/7] module: various bug-fixes and clean-ups for module namespace Matthias Maennich
2019-09-27 15:43   ` Masahiro Yamada
2019-10-02 18:57   ` Jessica Yu
2019-10-02 20:43     ` Matthias Maennich
2019-10-03  1:26     ` Masahiro Yamada
2019-10-03  8:03     ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190927120725.GB259443@google.com \
    --to=maennich@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeyu@kernel.org \
    --cc=joel@joelfernandes.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maco@android.com \
    --cc=michal.lkml@markovi.net \
    --cc=will.deacon@arm.com \
    --cc=will@kernel.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).