diff options
author | Anton Blanchard <anton@samba.org> | 2014-09-17 00:39:35 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2014-10-02 03:33:54 -0400 |
commit | c7d1f6afe062d2dc4bb8109856519570f2fe3c13 (patch) | |
tree | 3111cac07f96f632bd95dd730b18f23f65e78d73 /arch | |
parent | 9d57472f61acd7c3a33ebf5a79361e316d8ffbef (diff) |
powerpc: Use pr_fmt in module loader code
Use pr_fmt to give some context to the error messages in the
module code, and convert open coded debug printk to pr_debug.
Use pr_err for error messages.
Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/powerpc/kernel/module_32.c | 31 | ||||
-rw-r--r-- | arch/powerpc/kernel/module_64.c | 36 |
2 files changed, 31 insertions, 36 deletions
diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c index 6cff040bf456..c94d2e018d84 100644 --- a/arch/powerpc/kernel/module_32.c +++ b/arch/powerpc/kernel/module_32.c | |||
@@ -15,6 +15,9 @@ | |||
15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | */ | 17 | */ |
18 | |||
19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
20 | |||
18 | #include <linux/module.h> | 21 | #include <linux/module.h> |
19 | #include <linux/moduleloader.h> | 22 | #include <linux/moduleloader.h> |
20 | #include <linux/elf.h> | 23 | #include <linux/elf.h> |
@@ -28,12 +31,6 @@ | |||
28 | #include <linux/sort.h> | 31 | #include <linux/sort.h> |
29 | #include <asm/setup.h> | 32 | #include <asm/setup.h> |
30 | 33 | ||
31 | #if 0 | ||
32 | #define DEBUGP printk | ||
33 | #else | ||
34 | #define DEBUGP(fmt , ...) | ||
35 | #endif | ||
36 | |||
37 | /* Count how many different relocations (different symbol, different | 34 | /* Count how many different relocations (different symbol, different |
38 | addend) */ | 35 | addend) */ |
39 | static unsigned int count_relocs(const Elf32_Rela *rela, unsigned int num) | 36 | static unsigned int count_relocs(const Elf32_Rela *rela, unsigned int num) |
@@ -121,8 +118,8 @@ static unsigned long get_plt_size(const Elf32_Ehdr *hdr, | |||
121 | continue; | 118 | continue; |
122 | 119 | ||
123 | if (sechdrs[i].sh_type == SHT_RELA) { | 120 | if (sechdrs[i].sh_type == SHT_RELA) { |
124 | DEBUGP("Found relocations in section %u\n", i); | 121 | pr_debug("Found relocations in section %u\n", i); |
125 | DEBUGP("Ptr: %p. Number: %u\n", | 122 | pr_debug("Ptr: %p. Number: %u\n", |
126 | (void *)hdr + sechdrs[i].sh_offset, | 123 | (void *)hdr + sechdrs[i].sh_offset, |
127 | sechdrs[i].sh_size / sizeof(Elf32_Rela)); | 124 | sechdrs[i].sh_size / sizeof(Elf32_Rela)); |
128 | 125 | ||
@@ -161,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr, | |||
161 | me->arch.core_plt_section = i; | 158 | me->arch.core_plt_section = i; |
162 | } | 159 | } |
163 | if (!me->arch.core_plt_section || !me->arch.init_plt_section) { | 160 | if (!me->arch.core_plt_section || !me->arch.init_plt_section) { |
164 | printk("Module doesn't contain .plt or .init.plt sections.\n"); | 161 | pr_err("Module doesn't contain .plt or .init.plt sections.\n"); |
165 | return -ENOEXEC; | 162 | return -ENOEXEC; |
166 | } | 163 | } |
167 | 164 | ||
@@ -189,7 +186,7 @@ static uint32_t do_plt_call(void *location, | |||
189 | { | 186 | { |
190 | struct ppc_plt_entry *entry; | 187 | struct ppc_plt_entry *entry; |
191 | 188 | ||
192 | DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location); | 189 | pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location); |
193 | /* Init, or core PLT? */ | 190 | /* Init, or core PLT? */ |
194 | if (location >= mod->module_core | 191 | if (location >= mod->module_core |
195 | && location < mod->module_core + mod->core_size) | 192 | && location < mod->module_core + mod->core_size) |
@@ -208,7 +205,7 @@ static uint32_t do_plt_call(void *location, | |||
208 | entry->jump[2] = 0x7d8903a6; /* mtctr r12 */ | 205 | entry->jump[2] = 0x7d8903a6; /* mtctr r12 */ |
209 | entry->jump[3] = 0x4e800420; /* bctr */ | 206 | entry->jump[3] = 0x4e800420; /* bctr */ |
210 | 207 | ||
211 | DEBUGP("Initialized plt for 0x%x at %p\n", val, entry); | 208 | pr_debug("Initialized plt for 0x%x at %p\n", val, entry); |
212 | return (uint32_t)entry; | 209 | return (uint32_t)entry; |
213 | } | 210 | } |
214 | 211 | ||
@@ -224,7 +221,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, | |||
224 | uint32_t *location; | 221 | uint32_t *location; |
225 | uint32_t value; | 222 | uint32_t value; |
226 | 223 | ||
227 | DEBUGP("Applying ADD relocate section %u to %u\n", relsec, | 224 | pr_debug("Applying ADD relocate section %u to %u\n", relsec, |
228 | sechdrs[relsec].sh_info); | 225 | sechdrs[relsec].sh_info); |
229 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) { | 226 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) { |
230 | /* This is where to make the change */ | 227 | /* This is where to make the change */ |
@@ -268,17 +265,17 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, | |||
268 | sechdrs, module); | 265 | sechdrs, module); |
269 | 266 | ||
270 | /* Only replace bits 2 through 26 */ | 267 | /* Only replace bits 2 through 26 */ |
271 | DEBUGP("REL24 value = %08X. location = %08X\n", | 268 | pr_debug("REL24 value = %08X. location = %08X\n", |
272 | value, (uint32_t)location); | 269 | value, (uint32_t)location); |
273 | DEBUGP("Location before: %08X.\n", | 270 | pr_debug("Location before: %08X.\n", |
274 | *(uint32_t *)location); | 271 | *(uint32_t *)location); |
275 | *(uint32_t *)location | 272 | *(uint32_t *)location |
276 | = (*(uint32_t *)location & ~0x03fffffc) | 273 | = (*(uint32_t *)location & ~0x03fffffc) |
277 | | ((value - (uint32_t)location) | 274 | | ((value - (uint32_t)location) |
278 | & 0x03fffffc); | 275 | & 0x03fffffc); |
279 | DEBUGP("Location after: %08X.\n", | 276 | pr_debug("Location after: %08X.\n", |
280 | *(uint32_t *)location); | 277 | *(uint32_t *)location); |
281 | DEBUGP("ie. jump to %08X+%08X = %08X\n", | 278 | pr_debug("ie. jump to %08X+%08X = %08X\n", |
282 | *(uint32_t *)location & 0x03fffffc, | 279 | *(uint32_t *)location & 0x03fffffc, |
283 | (uint32_t)location, | 280 | (uint32_t)location, |
284 | (*(uint32_t *)location & 0x03fffffc) | 281 | (*(uint32_t *)location & 0x03fffffc) |
@@ -291,7 +288,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, | |||
291 | break; | 288 | break; |
292 | 289 | ||
293 | default: | 290 | default: |
294 | printk("%s: unknown ADD relocation: %u\n", | 291 | pr_err("%s: unknown ADD relocation: %u\n", |
295 | module->name, | 292 | module->name, |
296 | ELF32_R_TYPE(rela[i].r_info)); | 293 | ELF32_R_TYPE(rela[i].r_info)); |
297 | return -ENOEXEC; | 294 | return -ENOEXEC; |
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index d807ee626af9..68384514506b 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c | |||
@@ -15,6 +15,9 @@ | |||
15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | */ | 17 | */ |
18 | |||
19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
20 | |||
18 | #include <linux/module.h> | 21 | #include <linux/module.h> |
19 | #include <linux/elf.h> | 22 | #include <linux/elf.h> |
20 | #include <linux/moduleloader.h> | 23 | #include <linux/moduleloader.h> |
@@ -36,11 +39,6 @@ | |||
36 | Using a magic allocator which places modules within 32MB solves | 39 | Using a magic allocator which places modules within 32MB solves |
37 | this, and makes other things simpler. Anton? | 40 | this, and makes other things simpler. Anton? |
38 | --RR. */ | 41 | --RR. */ |
39 | #if 0 | ||
40 | #define DEBUGP printk | ||
41 | #else | ||
42 | #define DEBUGP(fmt , ...) | ||
43 | #endif | ||
44 | 42 | ||
45 | #if defined(_CALL_ELF) && _CALL_ELF == 2 | 43 | #if defined(_CALL_ELF) && _CALL_ELF == 2 |
46 | #define R2_STACK_OFFSET 24 | 44 | #define R2_STACK_OFFSET 24 |
@@ -279,8 +277,8 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *hdr, | |||
279 | /* Every relocated section... */ | 277 | /* Every relocated section... */ |
280 | for (i = 1; i < hdr->e_shnum; i++) { | 278 | for (i = 1; i < hdr->e_shnum; i++) { |
281 | if (sechdrs[i].sh_type == SHT_RELA) { | 279 | if (sechdrs[i].sh_type == SHT_RELA) { |
282 | DEBUGP("Found relocations in section %u\n", i); | 280 | pr_debug("Found relocations in section %u\n", i); |
283 | DEBUGP("Ptr: %p. Number: %lu\n", | 281 | pr_debug("Ptr: %p. Number: %Lu\n", |
284 | (void *)sechdrs[i].sh_addr, | 282 | (void *)sechdrs[i].sh_addr, |
285 | sechdrs[i].sh_size / sizeof(Elf64_Rela)); | 283 | sechdrs[i].sh_size / sizeof(Elf64_Rela)); |
286 | 284 | ||
@@ -304,7 +302,7 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *hdr, | |||
304 | relocs++; | 302 | relocs++; |
305 | #endif | 303 | #endif |
306 | 304 | ||
307 | DEBUGP("Looks like a total of %lu stubs, max\n", relocs); | 305 | pr_debug("Looks like a total of %lu stubs, max\n", relocs); |
308 | return relocs * sizeof(struct ppc64_stub_entry); | 306 | return relocs * sizeof(struct ppc64_stub_entry); |
309 | } | 307 | } |
310 | 308 | ||
@@ -390,7 +388,7 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr, | |||
390 | } | 388 | } |
391 | 389 | ||
392 | if (!me->arch.stubs_section) { | 390 | if (!me->arch.stubs_section) { |
393 | printk("%s: doesn't contain .stubs.\n", me->name); | 391 | pr_err("%s: doesn't contain .stubs.\n", me->name); |
394 | return -ENOEXEC; | 392 | return -ENOEXEC; |
395 | } | 393 | } |
396 | 394 | ||
@@ -434,11 +432,11 @@ static inline int create_stub(Elf64_Shdr *sechdrs, | |||
434 | /* Stub uses address relative to r2. */ | 432 | /* Stub uses address relative to r2. */ |
435 | reladdr = (unsigned long)entry - my_r2(sechdrs, me); | 433 | reladdr = (unsigned long)entry - my_r2(sechdrs, me); |
436 | if (reladdr > 0x7FFFFFFF || reladdr < -(0x80000000L)) { | 434 | if (reladdr > 0x7FFFFFFF || reladdr < -(0x80000000L)) { |
437 | printk("%s: Address %p of stub out of range of %p.\n", | 435 | pr_err("%s: Address %p of stub out of range of %p.\n", |
438 | me->name, (void *)reladdr, (void *)my_r2); | 436 | me->name, (void *)reladdr, (void *)my_r2); |
439 | return 0; | 437 | return 0; |
440 | } | 438 | } |
441 | DEBUGP("Stub %p get data from reladdr %li\n", entry, reladdr); | 439 | pr_debug("Stub %p get data from reladdr %li\n", entry, reladdr); |
442 | 440 | ||
443 | entry->jump[0] |= PPC_HA(reladdr); | 441 | entry->jump[0] |= PPC_HA(reladdr); |
444 | entry->jump[1] |= PPC_LO(reladdr); | 442 | entry->jump[1] |= PPC_LO(reladdr); |
@@ -477,7 +475,7 @@ static unsigned long stub_for_addr(Elf64_Shdr *sechdrs, | |||
477 | static int restore_r2(u32 *instruction, struct module *me) | 475 | static int restore_r2(u32 *instruction, struct module *me) |
478 | { | 476 | { |
479 | if (*instruction != PPC_INST_NOP) { | 477 | if (*instruction != PPC_INST_NOP) { |
480 | printk("%s: Expect noop after relocate, got %08x\n", | 478 | pr_err("%s: Expect noop after relocate, got %08x\n", |
481 | me->name, *instruction); | 479 | me->name, *instruction); |
482 | return 0; | 480 | return 0; |
483 | } | 481 | } |
@@ -498,7 +496,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
498 | unsigned long *location; | 496 | unsigned long *location; |
499 | unsigned long value; | 497 | unsigned long value; |
500 | 498 | ||
501 | DEBUGP("Applying ADD relocate section %u to %u\n", relsec, | 499 | pr_debug("Applying ADD relocate section %u to %u\n", relsec, |
502 | sechdrs[relsec].sh_info); | 500 | sechdrs[relsec].sh_info); |
503 | 501 | ||
504 | /* First time we're called, we can fix up .TOC. */ | 502 | /* First time we're called, we can fix up .TOC. */ |
@@ -519,7 +517,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
519 | sym = (Elf64_Sym *)sechdrs[symindex].sh_addr | 517 | sym = (Elf64_Sym *)sechdrs[symindex].sh_addr |
520 | + ELF64_R_SYM(rela[i].r_info); | 518 | + ELF64_R_SYM(rela[i].r_info); |
521 | 519 | ||
522 | DEBUGP("RELOC at %p: %li-type as %s (%lu) + %li\n", | 520 | pr_debug("RELOC at %p: %li-type as %s (0x%lx) + %li\n", |
523 | location, (long)ELF64_R_TYPE(rela[i].r_info), | 521 | location, (long)ELF64_R_TYPE(rela[i].r_info), |
524 | strtab + sym->st_name, (unsigned long)sym->st_value, | 522 | strtab + sym->st_name, (unsigned long)sym->st_value, |
525 | (long)rela[i].r_addend); | 523 | (long)rela[i].r_addend); |
@@ -546,7 +544,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
546 | /* Subtract TOC pointer */ | 544 | /* Subtract TOC pointer */ |
547 | value -= my_r2(sechdrs, me); | 545 | value -= my_r2(sechdrs, me); |
548 | if (value + 0x8000 > 0xffff) { | 546 | if (value + 0x8000 > 0xffff) { |
549 | printk("%s: bad TOC16 relocation (%lu)\n", | 547 | pr_err("%s: bad TOC16 relocation (0x%lx)\n", |
550 | me->name, value); | 548 | me->name, value); |
551 | return -ENOEXEC; | 549 | return -ENOEXEC; |
552 | } | 550 | } |
@@ -567,7 +565,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
567 | /* Subtract TOC pointer */ | 565 | /* Subtract TOC pointer */ |
568 | value -= my_r2(sechdrs, me); | 566 | value -= my_r2(sechdrs, me); |
569 | if ((value & 3) != 0 || value + 0x8000 > 0xffff) { | 567 | if ((value & 3) != 0 || value + 0x8000 > 0xffff) { |
570 | printk("%s: bad TOC16_DS relocation (%lu)\n", | 568 | pr_err("%s: bad TOC16_DS relocation (0x%lx)\n", |
571 | me->name, value); | 569 | me->name, value); |
572 | return -ENOEXEC; | 570 | return -ENOEXEC; |
573 | } | 571 | } |
@@ -580,7 +578,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
580 | /* Subtract TOC pointer */ | 578 | /* Subtract TOC pointer */ |
581 | value -= my_r2(sechdrs, me); | 579 | value -= my_r2(sechdrs, me); |
582 | if ((value & 3) != 0) { | 580 | if ((value & 3) != 0) { |
583 | printk("%s: bad TOC16_LO_DS relocation (%lu)\n", | 581 | pr_err("%s: bad TOC16_LO_DS relocation (0x%lx)\n", |
584 | me->name, value); | 582 | me->name, value); |
585 | return -ENOEXEC; | 583 | return -ENOEXEC; |
586 | } | 584 | } |
@@ -613,7 +611,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
613 | /* Convert value to relative */ | 611 | /* Convert value to relative */ |
614 | value -= (unsigned long)location; | 612 | value -= (unsigned long)location; |
615 | if (value + 0x2000000 > 0x3ffffff || (value & 3) != 0){ | 613 | if (value + 0x2000000 > 0x3ffffff || (value & 3) != 0){ |
616 | printk("%s: REL24 %li out of range!\n", | 614 | pr_err("%s: REL24 %li out of range!\n", |
617 | me->name, (long int)value); | 615 | me->name, (long int)value); |
618 | return -ENOEXEC; | 616 | return -ENOEXEC; |
619 | } | 617 | } |
@@ -655,7 +653,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, | |||
655 | break; | 653 | break; |
656 | 654 | ||
657 | default: | 655 | default: |
658 | printk("%s: Unknown ADD relocation: %lu\n", | 656 | pr_err("%s: Unknown ADD relocation: %lu\n", |
659 | me->name, | 657 | me->name, |
660 | (unsigned long)ELF64_R_TYPE(rela[i].r_info)); | 658 | (unsigned long)ELF64_R_TYPE(rela[i].r_info)); |
661 | return -ENOEXEC; | 659 | return -ENOEXEC; |