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: Sam Ravnborg <sam@ravnborg.org>
This commit is contained in:
Родитель
07f7668858
Коммит
df578e7d83
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* Copyright 2003 Kai Germaschewski
|
||||
* 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
|
||||
*
|
||||
* This software may be used and distributed according to the terms
|
||||
|
@ -74,7 +74,8 @@ static int is_vmlinux(const char *modname)
|
|||
{
|
||||
const char *myname;
|
||||
|
||||
if ((myname = strrchr(modname, '/')))
|
||||
myname = strrchr(modname, '/');
|
||||
if (myname)
|
||||
myname++;
|
||||
else
|
||||
myname = modname;
|
||||
|
@ -85,14 +86,13 @@ static int is_vmlinux(const char *modname)
|
|||
|
||||
void *do_nofail(void *ptr, const char *expr)
|
||||
{
|
||||
if (!ptr) {
|
||||
if (!ptr)
|
||||
fatal("modpost: Memory allocation failure: %s.\n", expr);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* A list of all modules we processed */
|
||||
|
||||
static struct module *modules;
|
||||
|
||||
static struct module *find_module(char *modname)
|
||||
|
@ -115,7 +115,8 @@ static struct module *new_module(char *modname)
|
|||
p = NOFAIL(strdup(modname));
|
||||
|
||||
/* strip trailing .o */
|
||||
if ((s = strrchr(p, '.')) != NULL)
|
||||
s = strrchr(p, '.');
|
||||
if (s != NULL)
|
||||
if (strcmp(s, ".o") == 0)
|
||||
*s = '\0';
|
||||
|
||||
|
@ -228,6 +229,7 @@ static const char *export_str(enum export ex)
|
|||
static enum export export_no(const char *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!s)
|
||||
return export_unknown;
|
||||
for (i = 0; export_list[i].export != export_unknown; i++) {
|
||||
|
@ -325,8 +327,7 @@ char* get_next_line(unsigned long *pos, void *file, unsigned long size)
|
|||
signed char *p = (signed char *)file + *pos;
|
||||
char *s = line;
|
||||
|
||||
for (; *pos < size ; (*pos)++)
|
||||
{
|
||||
for (; *pos < size ; (*pos)++) {
|
||||
if (skip && isspace(*p)) {
|
||||
p++;
|
||||
continue;
|
||||
|
@ -388,7 +389,9 @@ static int parse_elf(struct elf_info *info, const char *filename)
|
|||
|
||||
/* Check if file offset is correct */
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -409,7 +412,10 @@ static int parse_elf(struct elf_info *info, const char *filename)
|
|||
const char *secname;
|
||||
|
||||
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;
|
||||
}
|
||||
secname = secstrings + sechdrs[i].sh_name;
|
||||
|
@ -436,9 +442,9 @@ static int parse_elf(struct elf_info *info, const char *filename)
|
|||
info->strtab = (void *)hdr +
|
||||
sechdrs[sechdrs[i].sh_link].sh_offset;
|
||||
}
|
||||
if (!info->symtab_start) {
|
||||
if (!info->symtab_start)
|
||||
fatal("%s has no symtab?\n", filename);
|
||||
}
|
||||
|
||||
/* Fix endianness in symbols */
|
||||
for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
|
||||
sym->st_shndx = TO_NATIVE(sym->st_shndx);
|
||||
|
@ -507,11 +513,13 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
|
|||
#endif
|
||||
|
||||
if (memcmp(symname, MODULE_SYMBOL_PREFIX,
|
||||
strlen(MODULE_SYMBOL_PREFIX)) == 0)
|
||||
mod->unres = alloc_symbol(symname +
|
||||
strlen(MODULE_SYMBOL_PREFIX)) == 0) {
|
||||
mod->unres =
|
||||
alloc_symbol(symname +
|
||||
strlen(MODULE_SYMBOL_PREFIX),
|
||||
ELF_ST_BIND(sym->st_info) == STB_WEAK,
|
||||
mod->unres);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* All exported symbols */
|
||||
|
@ -671,7 +679,8 @@ static int data_section(const char *name)
|
|||
* the pattern is identified by:
|
||||
* tosec = init or exit 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:
|
||||
* Whitelist all refereces from .text.head to .init.data
|
||||
|
@ -731,7 +740,8 @@ static int secref_whitelist(const char *modname, const char *tosec,
|
|||
return 1;
|
||||
|
||||
/* 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++)
|
||||
if (strrcmp(atsym, *s) == 0)
|
||||
return 1;
|
||||
|
@ -842,23 +852,18 @@ static void find_symbols_between(struct elf_info *elf, Elf_Addr addr,
|
|||
if ((addr - sym->st_value) < beforediff) {
|
||||
beforediff = addr - sym->st_value;
|
||||
*before = sym;
|
||||
}
|
||||
else if ((addr - sym->st_value) == beforediff) {
|
||||
} else if ((addr - sym->st_value) == beforediff) {
|
||||
*before = sym;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ((sym->st_value - addr) < afterdiff) {
|
||||
afterdiff = sym->st_value - addr;
|
||||
*after = sym;
|
||||
}
|
||||
else if ((sym->st_value - addr) == afterdiff) {
|
||||
} else if ((sym->st_value - addr) == afterdiff)
|
||||
*after = sym;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a warning about a section mismatch.
|
||||
|
@ -952,11 +957,13 @@ static int addend_arm_rel(struct elf_info *elf, int rsection, Elf_Rela *r)
|
|||
switch (r_typ) {
|
||||
case R_ARM_ABS32:
|
||||
/* 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;
|
||||
case R_ARM_PC24:
|
||||
/* 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));
|
||||
break;
|
||||
default:
|
||||
|
@ -1221,7 +1228,8 @@ static int init_section_ref_ok(const char *name)
|
|||
return 1;
|
||||
|
||||
/* 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)
|
||||
return 1;
|
||||
|
@ -1465,9 +1473,8 @@ static int add_versions(struct buffer *b, struct module *mod)
|
|||
buf_printf(b, "__attribute__((section(\"__versions\"))) = {\n");
|
||||
|
||||
for (s = mod->unres; s; s = s->next) {
|
||||
if (!s->module) {
|
||||
if (!s->module)
|
||||
continue;
|
||||
}
|
||||
if (!s->crc_valid) {
|
||||
warn("\"%s\" [%s.ko] has no CRC!\n",
|
||||
s->name, mod->name);
|
||||
|
@ -1488,9 +1495,8 @@ static void add_depends(struct buffer *b, struct module *mod,
|
|||
struct module *m;
|
||||
int first = 1;
|
||||
|
||||
for (m = modules; m; m = m->next) {
|
||||
for (m = modules; m; m = m->next)
|
||||
m->seen = is_vmlinux(m->name);
|
||||
}
|
||||
|
||||
buf_printf(b, "\n");
|
||||
buf_printf(b, "static const char __module_depends[]\n");
|
||||
|
@ -1506,7 +1512,8 @@ static void add_depends(struct buffer *b, struct module *mod,
|
|||
continue;
|
||||
|
||||
s->module->seen = 1;
|
||||
if ((p = strrchr(s->module->name, '/')) != NULL)
|
||||
p = strrchr(s->module->name, '/');
|
||||
if (p)
|
||||
p++;
|
||||
else
|
||||
p = s->module->name;
|
||||
|
@ -1601,11 +1608,10 @@ static void read_dump(const char *fname, unsigned int kernel)
|
|||
crc = strtoul(line, &d, 16);
|
||||
if (*symname == '\0' || *modname == '\0' || *d != '\0')
|
||||
goto fail;
|
||||
|
||||
if (!(mod = find_module(modname))) {
|
||||
if (is_vmlinux(modname)) {
|
||||
mod = find_module(modname);
|
||||
if (!mod) {
|
||||
if (is_vmlinux(modname))
|
||||
have_vmlinux = 1;
|
||||
}
|
||||
mod = new_module(NOFAIL(strdup(modname)));
|
||||
mod->skip = 1;
|
||||
}
|
||||
|
@ -1695,9 +1701,8 @@ int main(int argc, char **argv)
|
|||
if (module_read)
|
||||
read_dump(module_read, 0);
|
||||
|
||||
while (optind < argc) {
|
||||
while (optind < argc)
|
||||
read_symbols(argv[optind++]);
|
||||
}
|
||||
|
||||
for (mod = modules; mod; mod = mod->next) {
|
||||
if (mod->skip)
|
||||
|
|
Загрузка…
Ссылка в новой задаче