From: Rusty Russell <rusty@rustcorp.com.au>
Subject: module: document the use of strmap

I have to re-read this code carefully every time to figure out what
it's doing.  Add some comments for next time.

Cc: Jan Beulich <JBeulich@novell.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 kernel/module.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/module.c b/kernel/module.c
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2157,6 +2157,7 @@ static char elf_type(const Elf_Sym *sym,
 	return '?';
 }
 
+/* These are the only symbols we save for kallsyms. */
 static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs,
                            unsigned int shnum)
 {
@@ -2191,12 +2192,15 @@ static void layout_symtab(struct module 
 					 info->index.sym) | INIT_OFFSET_MASK;
 	DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
 
+	/* Look at all symbols in symtab, figure out how many we're keeping. */
 	src = (void *)info->hdr + symsect->sh_offset;
 	nsrc = symsect->sh_size / sizeof(*src);
 	for (ndst = i = 1; i < nsrc; ++i, ++src)
 		if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
+			/* We are keeping this one! */
 			unsigned int j = src->st_name;
 
+			/* Mark string from strtab as used in strmap bitmap. */
 			while (!__test_and_set_bit(j, info->strmap)
 			       && info->strtab[j])
 				++j;
@@ -2215,7 +2219,6 @@ static void layout_symtab(struct module 
 
 	/* Append room for core symbols' strings at end of core part. */
 	info->stroffs = mod->core_size;
-	__set_bit(0, info->strmap);
 	mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
 }
 
@@ -2239,6 +2242,7 @@ static void add_kallsyms(struct module *
 	mod->core_symtab = dst = mod->module_core + info->symoffs;
 	mod->core_strtab = s = mod->module_core + info->stroffs;
 	src = mod->symtab;
+	/* Always copy first symbol. */
 	*dst = *src;
 	*s++ = 0;
 	for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
@@ -2753,6 +2757,7 @@ static struct module *layout_and_allocat
 	   special cases for the architectures. */
 	layout_sections(mod, info);
 
+	/* This bitmap is used to track what's used in the strtab. */
 	info->strmap = kzalloc(BITS_TO_LONGS(info->sechdrs[info->index.str].sh_size)
 			 * sizeof(long), GFP_KERNEL);
 	if (!info->strmap) {
