Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp39945ybn; Thu, 3 Oct 2019 01:00:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwN0CekwIVNG7sf4Ouf/kgkmSVytkh3xfdGkJEEFz2Jm7Nf51m+OjrirsGcLERRe25d+FD2 X-Received: by 2002:a17:906:8246:: with SMTP id f6mr6512132ejx.179.1570089640554; Thu, 03 Oct 2019 01:00:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570089640; cv=none; d=google.com; s=arc-20160816; b=qm0AlEBTbPmnuuiXg+oZZ84MXk/Ap1la34dnH+FAHGAqEdpxxzmChtSRPPreWa2qVo CJ53NKRbarQVAMMfLcTMWI/y7/fnc0adihx66A4Hl61puSVk3Xrfk9nhtMTpwJHOJt1d pJMNBamjLnvj78+lUIFWUh7x1Vvx4pKwVCmFh6N8wBj0V/QbqgAy+uFN+Epw7gD3VH+6 MFBDn2Lw3Ykf22BufNOI+GIhY0mtCxWho+P+XQlSbj7iu5W9f9jvYxPEY76psdD1xPQl 3O20YEPK8+k8qgnTPND8M6J3mTUs60lDtFEB8XIauOyoUsz51arSfVoK3LCE+6y/n2LG Kz+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=Ne5AozHKQBV/eN5L7U5RW8n+qn4kZ0PpPgZtYlmXwqs=; b=X5TTqGWfl0YuTvVTTbBO8Ow/eKJrQh6UFeN/Hx3YPOCyGIZKCNjFEydUkc1+KoZY5s 3xaAGoi/VSr/Z//QmRngUK6vxUmD1hSR1COEcri7DiNJIMMUtqYZaOTWeh/3gTkBQyax LTo7mIo4tSD+6B0zbFd3ItIpPK2KbCJXWDyqXuHKB+FdadUsJVEC1IPapoAh72zdSaNS sXQJVe3g62sXOKvLdwuIbazns2sydseXr//sXymp+YAGw8WFvvZeViHJ3M0WgthfUTAf fj+h/R4ssecICEzjjHKu7NfWs+MkgASPCG6b4CWSoYJ4wa+ePRTMai0qblLRHK+V/0G7 p6Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=SzfFwVTm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si1069183edi.442.2019.10.03.01.00.15; Thu, 03 Oct 2019 01:00:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=SzfFwVTm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728710AbfJCH7a (ORCPT + 99 others); Thu, 3 Oct 2019 03:59:30 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:59227 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726523AbfJCH7R (ORCPT ); Thu, 3 Oct 2019 03:59:17 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id x937wTkT007720; Thu, 3 Oct 2019 16:58:30 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com x937wTkT007720 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1570089510; bh=Ne5AozHKQBV/eN5L7U5RW8n+qn4kZ0PpPgZtYlmXwqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SzfFwVTmehv9gNGgR1TE+D93JWeJI0/ZGZ0C2AeH6e2XkAyF3tUnI1aDCk3wVcaCA EOcO4fYSej8XhnLNgrg90VBGe7z/Zv+ki/Wia+TcRSOgKSpCl6oG+iuNPpzeWggyTk b8EBuTJEE+jY/i3bKdZnET9RDYhA9zDM3o/bjepQsYJScchVY3owxI2mB87R+8qDPx 0t+Y9LXZdnzB7oxd9traZRR4sqyWx3vblOAAyk5OffgU6tjhWFrocsPE/LSJGhdnwm zF2HLmhZHBZW+aIdcALgxtBxl4cXrPhurmfcvHvm6R7GkdZwQxWVSX4E8KmuS6mpi/ 12l3jabmBktsQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Shaun Ruffell , linux-kbuild@vger.kernel.org, Masahiro Yamada , Martijn Coenen , Michal Marek , Will Deacon , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/6] module: swap the order of symbol.namespace Date: Thu, 3 Oct 2019 16:58:21 +0900 Message-Id: <20191003075826.7478-2-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191003075826.7478-1-yamada.masahiro@socionext.com> References: <20191003075826.7478-1-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Masahiro Yamada Reviewed-by: Matthias Maennich --- Changes in v2: None 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 442d5e2ad688..2c644086c412 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