Commit df578e7d authored by Sam Ravnborg's avatar Sam Ravnborg

kbuild: clean up modpost.c

akpm complained about overly long lines in modpost.c and
when started additional style issues were fixed:

o Updated my copyright
o Removed unneeded {}
o Drop assignments in if ()
o Spaces around operators
o Break long lines
o locate * near variable not type
o Fix a format specifier for sizeof()
o Corrected placement of '{' and '}'
o spaces to tabs (but use tabs only for indention)

modpost.c is not checkpatch clean. Readability were favoured
on top of checkpatch compliance.
But checkpatch were used to find additional stuff to clean up.
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent 07f76688
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* *
* Copyright 2003 Kai Germaschewski * Copyright 2003 Kai Germaschewski
* Copyright 2002-2004 Rusty Russell, IBM Corporation * Copyright 2002-2004 Rusty Russell, IBM Corporation
* Copyright 2006 Sam Ravnborg * Copyright 2006-2008 Sam Ravnborg
* Based in part on module-init-tools/depmod.c,file2alias * Based in part on module-init-tools/depmod.c,file2alias
* *
* This software may be used and distributed according to the terms * This software may be used and distributed according to the terms
...@@ -74,7 +74,8 @@ static int is_vmlinux(const char *modname) ...@@ -74,7 +74,8 @@ static int is_vmlinux(const char *modname)
{ {
const char *myname; const char *myname;
if ((myname = strrchr(modname, '/'))) myname = strrchr(modname, '/');
if (myname)
myname++; myname++;
else else
myname = modname; myname = modname;
...@@ -85,14 +86,13 @@ static int is_vmlinux(const char *modname) ...@@ -85,14 +86,13 @@ static int is_vmlinux(const char *modname)
void *do_nofail(void *ptr, const char *expr) void *do_nofail(void *ptr, const char *expr)
{ {
if (!ptr) { if (!ptr)
fatal("modpost: Memory allocation failure: %s.\n", expr); fatal("modpost: Memory allocation failure: %s.\n", expr);
}
return ptr; return ptr;
} }
/* A list of all modules we processed */ /* A list of all modules we processed */
static struct module *modules; static struct module *modules;
static struct module *find_module(char *modname) static struct module *find_module(char *modname)
...@@ -115,7 +115,8 @@ static struct module *new_module(char *modname) ...@@ -115,7 +115,8 @@ static struct module *new_module(char *modname)
p = NOFAIL(strdup(modname)); p = NOFAIL(strdup(modname));
/* strip trailing .o */ /* strip trailing .o */
if ((s = strrchr(p, '.')) != NULL) s = strrchr(p, '.');
if (s != NULL)
if (strcmp(s, ".o") == 0) if (strcmp(s, ".o") == 0)
*s = '\0'; *s = '\0';
...@@ -156,7 +157,7 @@ static inline unsigned int tdb_hash(const char *name) ...@@ -156,7 +157,7 @@ static inline unsigned int tdb_hash(const char *name)
unsigned i; /* Used to cycle through random values. */ unsigned i; /* Used to cycle through random values. */
/* Set the initial value from the key size. */ /* Set the initial value from the key size. */
for (value = 0x238F13AF * strlen(name), i=0; name[i]; i++) for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++)
value = (value + (((unsigned char *)name)[i] << (i*5 % 24))); value = (value + (((unsigned char *)name)[i] << (i*5 % 24)));
return (1103515243 * value + 12345); return (1103515243 * value + 12345);
...@@ -200,7 +201,7 @@ static struct symbol *find_symbol(const char *name) ...@@ -200,7 +201,7 @@ static struct symbol *find_symbol(const char *name)
if (name[0] == '.') if (name[0] == '.')
name++; name++;
for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s=s->next) { for (s = symbolhash[tdb_hash(name) % SYMBOL_HASH_SIZE]; s; s = s->next) {
if (strcmp(s->name, name) == 0) if (strcmp(s->name, name) == 0)
return s; return s;
} }
...@@ -225,9 +226,10 @@ static const char *export_str(enum export ex) ...@@ -225,9 +226,10 @@ static const char *export_str(enum export ex)
return export_list[ex].str; return export_list[ex].str;
} }
static enum export export_no(const char * s) static enum export export_no(const char *s)
{ {
int i; int i;
if (!s) if (!s)
return export_unknown; return export_unknown;
for (i = 0; export_list[i].export != export_unknown; i++) { for (i = 0; export_list[i].export != export_unknown; i++) {
...@@ -317,7 +319,7 @@ void *grab_file(const char *filename, unsigned long *size) ...@@ -317,7 +319,7 @@ void *grab_file(const char *filename, unsigned long *size)
* spaces in the beginning of the line is trimmed away. * spaces in the beginning of the line is trimmed away.
* Return a pointer to a static buffer. * Return a pointer to a static buffer.
**/ **/
char* get_next_line(unsigned long *pos, void *file, unsigned long size) char *get_next_line(unsigned long *pos, void *file, unsigned long size)
{ {
static char line[4096]; static char line[4096];
int skip = 1; int skip = 1;
...@@ -325,8 +327,7 @@ char* get_next_line(unsigned long *pos, void *file, unsigned long size) ...@@ -325,8 +327,7 @@ char* get_next_line(unsigned long *pos, void *file, unsigned long size)
signed char *p = (signed char *)file + *pos; signed char *p = (signed char *)file + *pos;
char *s = line; char *s = line;
for (; *pos < size ; (*pos)++) for (; *pos < size ; (*pos)++) {
{
if (skip && isspace(*p)) { if (skip && isspace(*p)) {
p++; p++;
continue; continue;
...@@ -388,7 +389,9 @@ static int parse_elf(struct elf_info *info, const char *filename) ...@@ -388,7 +389,9 @@ static int parse_elf(struct elf_info *info, const char *filename)
/* Check if file offset is correct */ /* Check if file offset is correct */
if (hdr->e_shoff > info->size) { if (hdr->e_shoff > info->size) {
fatal("section header offset=%lu in file '%s' is bigger then filesize=%lu\n", (unsigned long)hdr->e_shoff, filename, info->size); fatal("section header offset=%lu in file '%s' is bigger than "
"filesize=%lu\n", (unsigned long)hdr->e_shoff,
filename, info->size);
return 0; return 0;
} }
...@@ -409,7 +412,10 @@ static int parse_elf(struct elf_info *info, const char *filename) ...@@ -409,7 +412,10 @@ static int parse_elf(struct elf_info *info, const char *filename)
const char *secname; const char *secname;
if (sechdrs[i].sh_offset > info->size) { if (sechdrs[i].sh_offset > info->size) {
fatal("%s is truncated. sechdrs[i].sh_offset=%lu > sizeof(*hrd)=%lu\n", filename, (unsigned long)sechdrs[i].sh_offset, sizeof(*hdr)); fatal("%s is truncated. sechdrs[i].sh_offset=%lu > "
"sizeof(*hrd)=%zu\n", filename,
(unsigned long)sechdrs[i].sh_offset,
sizeof(*hdr));
return 0; return 0;
} }
secname = secstrings + sechdrs[i].sh_name; secname = secstrings + sechdrs[i].sh_name;
...@@ -436,9 +442,9 @@ static int parse_elf(struct elf_info *info, const char *filename) ...@@ -436,9 +442,9 @@ static int parse_elf(struct elf_info *info, const char *filename)
info->strtab = (void *)hdr + info->strtab = (void *)hdr +
sechdrs[sechdrs[i].sh_link].sh_offset; sechdrs[sechdrs[i].sh_link].sh_offset;
} }
if (!info->symtab_start) { if (!info->symtab_start)
fatal("%s has no symtab?\n", filename); fatal("%s has no symtab?\n", filename);
}
/* Fix endianness in symbols */ /* Fix endianness in symbols */
for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
sym->st_shndx = TO_NATIVE(sym->st_shndx); sym->st_shndx = TO_NATIVE(sym->st_shndx);
...@@ -507,11 +513,13 @@ static void handle_modversions(struct module *mod, struct elf_info *info, ...@@ -507,11 +513,13 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
#endif #endif
if (memcmp(symname, MODULE_SYMBOL_PREFIX, if (memcmp(symname, MODULE_SYMBOL_PREFIX,
strlen(MODULE_SYMBOL_PREFIX)) == 0) strlen(MODULE_SYMBOL_PREFIX)) == 0) {
mod->unres = alloc_symbol(symname + mod->unres =
alloc_symbol(symname +
strlen(MODULE_SYMBOL_PREFIX), strlen(MODULE_SYMBOL_PREFIX),
ELF_ST_BIND(sym->st_info) == STB_WEAK, ELF_ST_BIND(sym->st_info) == STB_WEAK,
mod->unres); mod->unres);
}
break; break;
default: default:
/* All exported symbols */ /* All exported symbols */
...@@ -671,7 +679,8 @@ static int data_section(const char *name) ...@@ -671,7 +679,8 @@ static int data_section(const char *name)
* the pattern is identified by: * the pattern is identified by:
* tosec = init or exit section * tosec = init or exit section
* fromsec = data section * fromsec = data section
* atsym = *driver, *_template, *_sht, *_ops, *_probe, *probe_one, *_console, *_timer * atsym = *driver, *_template, *_sht, *_ops, *_probe,
* *probe_one, *_console, *_timer
* *
* Pattern 3: * Pattern 3:
* Whitelist all refereces from .text.head to .init.data * Whitelist all refereces from .text.head to .init.data
...@@ -731,7 +740,8 @@ static int secref_whitelist(const char *modname, const char *tosec, ...@@ -731,7 +740,8 @@ static int secref_whitelist(const char *modname, const char *tosec,
return 1; return 1;
/* Check for pattern 2 */ /* Check for pattern 2 */
if ((init_section(tosec) || exit_section(tosec)) && data_section(fromsec)) if ((init_section(tosec) || exit_section(tosec))
&& data_section(fromsec))
for (s = pat2sym; *s; s++) for (s = pat2sym; *s; s++)
if (strrcmp(atsym, *s) == 0) if (strrcmp(atsym, *s) == 0)
return 1; return 1;
...@@ -842,22 +852,17 @@ static void find_symbols_between(struct elf_info *elf, Elf_Addr addr, ...@@ -842,22 +852,17 @@ static void find_symbols_between(struct elf_info *elf, Elf_Addr addr,
if ((addr - sym->st_value) < beforediff) { if ((addr - sym->st_value) < beforediff) {
beforediff = addr - sym->st_value; beforediff = addr - sym->st_value;
*before = sym; *before = sym;
} } else if ((addr - sym->st_value) == beforediff) {
else if ((addr - sym->st_value) == beforediff) {
*before = sym; *before = sym;
} }
} } else {
else
{
if ((sym->st_value - addr) < afterdiff) { if ((sym->st_value - addr) < afterdiff) {
afterdiff = sym->st_value - addr; afterdiff = sym->st_value - addr;
*after = sym; *after = sym;
} } else if ((sym->st_value - addr) == afterdiff)
else if ((sym->st_value - addr) == afterdiff) {
*after = sym; *after = sym;
} }
} }
}
} }
/** /**
...@@ -952,11 +957,13 @@ static int addend_arm_rel(struct elf_info *elf, int rsection, Elf_Rela *r) ...@@ -952,11 +957,13 @@ static int addend_arm_rel(struct elf_info *elf, int rsection, Elf_Rela *r)
switch (r_typ) { switch (r_typ) {
case R_ARM_ABS32: case R_ARM_ABS32:
/* From ARM ABI: (S + A) | T */ /* From ARM ABI: (S + A) | T */
r->r_addend = (int)(long)(elf->symtab_start + ELF_R_SYM(r->r_info)); r->r_addend = (int)(long)
(elf->symtab_start + ELF_R_SYM(r->r_info));
break; break;
case R_ARM_PC24: case R_ARM_PC24:
/* From ARM ABI: ((S + A) | T) - P */ /* From ARM ABI: ((S + A) | T) - P */
r->r_addend = (int)(long)(elf->hdr + elf->sechdrs[rsection].sh_offset + r->r_addend = (int)(long)(elf->hdr +
elf->sechdrs[rsection].sh_offset +
(r->r_offset - elf->sechdrs[rsection].sh_addr)); (r->r_offset - elf->sechdrs[rsection].sh_addr));
break; break;
default: default:
...@@ -1002,7 +1009,7 @@ static int addend_mips_rel(struct elf_info *elf, int rsection, Elf_Rela *r) ...@@ -1002,7 +1009,7 @@ static int addend_mips_rel(struct elf_info *elf, int rsection, Elf_Rela *r)
**/ **/
static void check_sec_ref(struct module *mod, const char *modname, static void check_sec_ref(struct module *mod, const char *modname,
struct elf_info *elf, struct elf_info *elf,
int section(const char*), int section(const char *),
int section_ref_ok(const char *)) int section_ref_ok(const char *))
{ {
int i; int i;
...@@ -1022,7 +1029,7 @@ static void check_sec_ref(struct module *mod, const char *modname, ...@@ -1022,7 +1029,7 @@ static void check_sec_ref(struct module *mod, const char *modname,
if (sechdrs[i].sh_type == SHT_RELA) { if (sechdrs[i].sh_type == SHT_RELA) {
Elf_Rela *rela; Elf_Rela *rela;
Elf_Rela *start = (void *)hdr + sechdrs[i].sh_offset; Elf_Rela *start = (void *)hdr + sechdrs[i].sh_offset;
Elf_Rela *stop = (void*)start + sechdrs[i].sh_size; Elf_Rela *stop = (void *)start + sechdrs[i].sh_size;
name += strlen(".rela"); name += strlen(".rela");
if (section_ref_ok(name)) if (section_ref_ok(name))
continue; continue;
...@@ -1059,7 +1066,7 @@ static void check_sec_ref(struct module *mod, const char *modname, ...@@ -1059,7 +1066,7 @@ static void check_sec_ref(struct module *mod, const char *modname,
} else if (sechdrs[i].sh_type == SHT_REL) { } else if (sechdrs[i].sh_type == SHT_REL) {
Elf_Rel *rel; Elf_Rel *rel;
Elf_Rel *start = (void *)hdr + sechdrs[i].sh_offset; Elf_Rel *start = (void *)hdr + sechdrs[i].sh_offset;
Elf_Rel *stop = (void*)start + sechdrs[i].sh_size; Elf_Rel *stop = (void *)start + sechdrs[i].sh_size;
name += strlen(".rel"); name += strlen(".rel");
if (section_ref_ok(name)) if (section_ref_ok(name))
continue; continue;
...@@ -1088,7 +1095,7 @@ static void check_sec_ref(struct module *mod, const char *modname, ...@@ -1088,7 +1095,7 @@ static void check_sec_ref(struct module *mod, const char *modname,
continue; continue;
break; break;
case EM_ARM: case EM_ARM:
if(addend_arm_rel(elf, i, &r)) if (addend_arm_rel(elf, i, &r))
continue; continue;
break; break;
case EM_MIPS: case EM_MIPS:
...@@ -1221,7 +1228,8 @@ static int init_section_ref_ok(const char *name) ...@@ -1221,7 +1228,8 @@ static int init_section_ref_ok(const char *name)
return 1; return 1;
/* If section name ends with ".init" we allow references /* If section name ends with ".init" we allow references
* as is the case with .initcallN.init, .early_param.init, .taglist.init etc * as is the case with .initcallN.init, .early_param.init,
* .taglist.init etc
*/ */
if (strrcmp(name, ".init") == 0) if (strrcmp(name, ".init") == 0)
return 1; return 1;
...@@ -1368,7 +1376,7 @@ static void check_for_gpl_usage(enum export exp, const char *m, const char *s) ...@@ -1368,7 +1376,7 @@ static void check_for_gpl_usage(enum export exp, const char *m, const char *s)
} }
} }
static void check_for_unused(enum export exp, const char* m, const char* s) static void check_for_unused(enum export exp, const char *m, const char *s)
{ {
const char *e = is_vmlinux(m) ?"":".ko"; const char *e = is_vmlinux(m) ?"":".ko";
...@@ -1465,9 +1473,8 @@ static int add_versions(struct buffer *b, struct module *mod) ...@@ -1465,9 +1473,8 @@ static int add_versions(struct buffer *b, struct module *mod)
buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n"); buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n");
for (s = mod->unres; s; s = s->next) { for (s = mod->unres; s; s = s->next) {
if (!s->module) { if (!s->module)
continue; continue;
}
if (!s->crc_valid) { if (!s->crc_valid) {
warn("\"%s\" [%s.ko] has no CRC!\n", warn("\"%s\" [%s.ko] has no CRC!\n",
s->name, mod->name); s->name, mod->name);
...@@ -1488,9 +1495,8 @@ static void add_depends(struct buffer *b, struct module *mod, ...@@ -1488,9 +1495,8 @@ static void add_depends(struct buffer *b, struct module *mod,
struct module *m; struct module *m;
int first = 1; int first = 1;
for (m = modules; m; m = m->next) { for (m = modules; m; m = m->next)
m->seen = is_vmlinux(m->name); m->seen = is_vmlinux(m->name);
}
buf_printf(b, "\n"); buf_printf(b, "\n");
buf_printf(b, "static const char __module_depends[]\n"); buf_printf(b, "static const char __module_depends[]\n");
...@@ -1506,7 +1512,8 @@ static void add_depends(struct buffer *b, struct module *mod, ...@@ -1506,7 +1512,8 @@ static void add_depends(struct buffer *b, struct module *mod,
continue; continue;
s->module->seen = 1; s->module->seen = 1;
if ((p = strrchr(s->module->name, '/')) != NULL) p = strrchr(s->module->name, '/');
if (p)
p++; p++;
else else
p = s->module->name; p = s->module->name;
...@@ -1601,11 +1608,10 @@ static void read_dump(const char *fname, unsigned int kernel) ...@@ -1601,11 +1608,10 @@ static void read_dump(const char *fname, unsigned int kernel)
crc = strtoul(line, &d, 16); crc = strtoul(line, &d, 16);
if (*symname == '\0' || *modname == '\0' || *d != '\0') if (*symname == '\0' || *modname == '\0' || *d != '\0')
goto fail; goto fail;
mod = find_module(modname);
if (!(mod = find_module(modname))) { if (!mod) {
if (is_vmlinux(modname)) { if (is_vmlinux(modname))
have_vmlinux = 1; have_vmlinux = 1;
}
mod = new_module(NOFAIL(strdup(modname))); mod = new_module(NOFAIL(strdup(modname)));
mod->skip = 1; mod->skip = 1;
} }
...@@ -1662,7 +1668,7 @@ int main(int argc, char **argv) ...@@ -1662,7 +1668,7 @@ int main(int argc, char **argv)
int err; int err;
while ((opt = getopt(argc, argv, "i:I:mso:aw")) != -1) { while ((opt = getopt(argc, argv, "i:I:mso:aw")) != -1) {
switch(opt) { switch (opt) {
case 'i': case 'i':
kernel_read = optarg; kernel_read = optarg;
break; break;
...@@ -1695,9 +1701,8 @@ int main(int argc, char **argv) ...@@ -1695,9 +1701,8 @@ int main(int argc, char **argv)
if (module_read) if (module_read)
read_dump(module_read, 0); read_dump(module_read, 0);
while (optind < argc) { while (optind < argc)
read_symbols(argv[optind++]); read_symbols(argv[optind++]);
}
for (mod = modules; mod; mod = mod->next) { for (mod = modules; mod; mod = mod->next) {
if (mod->skip) if (mod->skip)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment