From 7c921951784cbc978a5e0193b91f0c3f8a464810 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@gmail.com>
Date: Fri, 15 Mar 2013 12:22:26 +0100
Subject: [PATCH] CONFIG_SYMBOL_PREFIX: cleanup (improved version)

Import missing bits from improved version pending in modules-next.

This is a follow up to commit 837718bfd28b ("CONFIG_SYMBOL_PREFIX: cleanup.")
in Linux-Next (next-20130315).

Signed-off-by: Sedat Dilek <sedat.dilek@gmail.com>
---
 Makefile                      |  2 +-
 drivers/mtd/chips/gen_probe.c |  8 +++++---
 include/linux/export.h        |  9 ++-------
 scripts/mod/modpost.c         | 17 +++++++++--------
 4 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile
index 10fb6c7..0b09ba5 100644
--- a/Makefile
+++ b/Makefile
@@ -1398,7 +1398,7 @@ quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files))
 # Run depmod only if we have System.map and depmod is executable
 quiet_cmd_depmod = DEPMOD  $(KERNELRELEASE)
       cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
-                   $(KERNELRELEASE) "$(patsubst y,_,$(CONFIG_HAVE_SYMBOL_PREFIX_UNDERSCORE))"
+                   $(KERNELRELEASE) "$(patsubst y,_,$(CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX))"
 
 # Create temporary dir for module support files
 # clean it up only when building all modules
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
index 00d20ad..74dbb6b 100644
--- a/drivers/mtd/chips/gen_probe.c
+++ b/drivers/mtd/chips/gen_probe.c
@@ -204,14 +204,16 @@ static inline struct mtd_info *cfi_cmdset_unknown(struct map_info *map,
 	struct cfi_private *cfi = map->fldrv_priv;
 	__u16 type = primary?cfi->cfiq->P_ID:cfi->cfiq->A_ID;
 #ifdef CONFIG_MODULES
-	char probename[16+sizeof(VMLINUX_SYMBOL_PREFIX_STR)];
+	char probename[sizeof(VMLINUX_SYMBOL_STR(cfi_cmdset_%4.4X))];
 	cfi_cmdset_fn_t *probe_function;
 
-	sprintf(probename, VMLINUX_SYMBOL_PREFIX_STR "cfi_cmdset_%4.4X", type);
+	sprintf(probename, VMLINUX_SYMBOL_STR(cfi_cmdset_%4.4X), type);
 
 	probe_function = __symbol_get(probename);
 	if (!probe_function) {
-		request_module(probename + sizeof(VMLINUX_SYMBOL_PREFIX_STR)-1);
+		char modname[sizeof("cfi_cmdset_%4.4X")];
+		sprintf(modname, "cfi_cmdset_%4.4X", type);
+		request_module(modname);
 		probe_function = __symbol_get(probename);
 	}
 
diff --git a/include/linux/export.h b/include/linux/export.h
index fc83b2a..412cd50 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -5,22 +5,17 @@
  * to reduce the amount of pointless cruft we feed to gcc when only
  * exporting a simple symbol or two.
  *
- * If you feel the need to add #include <linux/foo.h> to this file
- * then you are doing something wrong and should go away silently.
- *
- * If you think the above arrogance just encourages more people to add
- * random crap to this file, you're not alone.
+ * Try not to add #includes here.  It slows compilation and makes kernel
+ * hackers place grumpy comments in header files.
  */
 
 /* Some toolchains use a `_' prefix for all user symbols. */
 #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
 #define __VMLINUX_SYMBOL(x) _##x
 #define __VMLINUX_SYMBOL_STR(x) "_" #x
-#define VMLINUX_SYMBOL_PREFIX_STR "_"
 #else
 #define __VMLINUX_SYMBOL(x) x
 #define __VMLINUX_SYMBOL_STR(x) #x
-#define VMLINUX_SYMBOL_PREFIX_STR ""
 #endif
 
 /* Indirect, so macros are expanded before pasting. */
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 6985021..282decf 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -630,14 +630,15 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
 		}
 #endif
 
-		if (memcmp(symname, VMLINUX_SYMBOL_PREFIX_STR,
-			   strlen(VMLINUX_SYMBOL_PREFIX_STR)) == 0) {
-			mod->unres =
-			  alloc_symbol(symname +
-			               strlen(VMLINUX_SYMBOL_PREFIX_STR),
-			               ELF_ST_BIND(sym->st_info) == STB_WEAK,
-			               mod->unres);
-		}
+#ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
+		if (symname[0] != '_')
+			break;
+		else
+			symname++;
+#endif
+		mod->unres = alloc_symbol(symname,
+					  ELF_ST_BIND(sym->st_info) == STB_WEAK,
+					  mod->unres);
 		break;
 	default:
 		/* All exported symbols */
-- 
1.8.2

