Skip to content

Commit c7d1f6a

Browse files
antonblanchardmpe
authored andcommitted
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>
1 parent 9d57472 commit c7d1f6a

2 files changed

Lines changed: 31 additions & 36 deletions

File tree

‎arch/powerpc/kernel/module_32.c‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
along with this program; if not, write to the Free Software
1616
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717
*/
18+
19+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20+
1821
#include <linux/module.h>
1922
#include <linux/moduleloader.h>
2023
#include <linux/elf.h>
@@ -28,12 +31,6 @@
2831
#include <linux/sort.h>
2932
#include <asm/setup.h>
3033

31-
#if 0
32-
#define DEBUGP printk
33-
#else
34-
#define DEBUGP(fmt , ...)
35-
#endif
36-
3734
/* Count how many different relocations (different symbol, different
3835
addend) */
3936
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,
121118
continue;
122119

123120
if (sechdrs[i].sh_type == SHT_RELA) {
124-
DEBUGP("Found relocations in section %u\n", i);
125-
DEBUGP("Ptr: %p. Number: %u\n",
121+
pr_debug("Found relocations in section %u\n", i);
122+
pr_debug("Ptr: %p. Number: %u\n",
126123
(void *)hdr + sechdrs[i].sh_offset,
127124
sechdrs[i].sh_size / sizeof(Elf32_Rela));
128125

@@ -161,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
161158
me->arch.core_plt_section = i;
162159
}
163160
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");
165162
return -ENOEXEC;
166163
}
167164

@@ -189,7 +186,7 @@ static uint32_t do_plt_call(void *location,
189186
{
190187
struct ppc_plt_entry *entry;
191188

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);
193190
/* Init, or core PLT? */
194191
if (location >= mod->module_core
195192
&& location < mod->module_core + mod->core_size)
@@ -208,7 +205,7 @@ static uint32_t do_plt_call(void *location,
208205
entry->jump[2] = 0x7d8903a6; /* mtctr r12 */
209206
entry->jump[3] = 0x4e800420; /* bctr */
210207

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);
212209
return (uint32_t)entry;
213210
}
214211

@@ -224,7 +221,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
224221
uint32_t *location;
225222
uint32_t value;
226223

227-
DEBUGP("Applying ADD relocate section %u to %u\n", relsec,
224+
pr_debug("Applying ADD relocate section %u to %u\n", relsec,
228225
sechdrs[relsec].sh_info);
229226
for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
230227
/* This is where to make the change */
@@ -268,17 +265,17 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
268265
sechdrs, module);
269266

270267
/* Only replace bits 2 through 26 */
271-
DEBUGP("REL24 value = %08X. location = %08X\n",
268+
pr_debug("REL24 value = %08X. location = %08X\n",
272269
value, (uint32_t)location);
273-
DEBUGP("Location before: %08X.\n",
270+
pr_debug("Location before: %08X.\n",
274271
*(uint32_t *)location);
275272
*(uint32_t *)location
276273
= (*(uint32_t *)location & ~0x03fffffc)
277274
| ((value - (uint32_t)location)
278275
& 0x03fffffc);
279-
DEBUGP("Location after: %08X.\n",
276+
pr_debug("Location after: %08X.\n",
280277
*(uint32_t *)location);
281-
DEBUGP("ie. jump to %08X+%08X = %08X\n",
278+
pr_debug("ie. jump to %08X+%08X = %08X\n",
282279
*(uint32_t *)location & 0x03fffffc,
283280
(uint32_t)location,
284281
(*(uint32_t *)location & 0x03fffffc)
@@ -291,7 +288,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
291288
break;
292289

293290
default:
294-
printk("%s: unknown ADD relocation: %u\n",
291+
pr_err("%s: unknown ADD relocation: %u\n",
295292
module->name,
296293
ELF32_R_TYPE(rela[i].r_info));
297294
return -ENOEXEC;

‎arch/powerpc/kernel/module_64.c‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
along with this program; if not, write to the Free Software
1616
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717
*/
18+
19+
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20+
1821
#include <linux/module.h>
1922
#include <linux/elf.h>
2023
#include <linux/moduleloader.h>
@@ -36,11 +39,6 @@
3639
Using a magic allocator which places modules within 32MB solves
3740
this, and makes other things simpler. Anton?
3841
--RR. */
39-
#if 0
40-
#define DEBUGP printk
41-
#else
42-
#define DEBUGP(fmt , ...)
43-
#endif
4442

4543
#if defined(_CALL_ELF) && _CALL_ELF == 2
4644
#define R2_STACK_OFFSET 24
@@ -279,8 +277,8 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *hdr,
279277
/* Every relocated section... */
280278
for (i = 1; i < hdr->e_shnum; i++) {
281279
if (sechdrs[i].sh_type == SHT_RELA) {
282-
DEBUGP("Found relocations in section %u\n", i);
283-
DEBUGP("Ptr: %p. Number: %lu\n",
280+
pr_debug("Found relocations in section %u\n", i);
281+
pr_debug("Ptr: %p. Number: %Lu\n",
284282
(void *)sechdrs[i].sh_addr,
285283
sechdrs[i].sh_size / sizeof(Elf64_Rela));
286284

@@ -304,7 +302,7 @@ static unsigned long get_stubs_size(const Elf64_Ehdr *hdr,
304302
relocs++;
305303
#endif
306304

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);
308306
return relocs * sizeof(struct ppc64_stub_entry);
309307
}
310308

@@ -390,7 +388,7 @@ int module_frob_arch_sections(Elf64_Ehdr *hdr,
390388
}
391389

392390
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);
394392
return -ENOEXEC;
395393
}
396394

@@ -434,11 +432,11 @@ static inline int create_stub(Elf64_Shdr *sechdrs,
434432
/* Stub uses address relative to r2. */
435433
reladdr = (unsigned long)entry - my_r2(sechdrs, me);
436434
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",
438436
me->name, (void *)reladdr, (void *)my_r2);
439437
return 0;
440438
}
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);
442440

443441
entry->jump[0] |= PPC_HA(reladdr);
444442
entry->jump[1] |= PPC_LO(reladdr);
@@ -477,7 +475,7 @@ static unsigned long stub_for_addr(Elf64_Shdr *sechdrs,
477475
static int restore_r2(u32 *instruction, struct module *me)
478476
{
479477
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",
481479
me->name, *instruction);
482480
return 0;
483481
}
@@ -498,7 +496,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
498496
unsigned long *location;
499497
unsigned long value;
500498

501-
DEBUGP("Applying ADD relocate section %u to %u\n", relsec,
499+
pr_debug("Applying ADD relocate section %u to %u\n", relsec,
502500
sechdrs[relsec].sh_info);
503501

504502
/* First time we're called, we can fix up .TOC. */
@@ -519,7 +517,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
519517
sym = (Elf64_Sym *)sechdrs[symindex].sh_addr
520518
+ ELF64_R_SYM(rela[i].r_info);
521519

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",
523521
location, (long)ELF64_R_TYPE(rela[i].r_info),
524522
strtab + sym->st_name, (unsigned long)sym->st_value,
525523
(long)rela[i].r_addend);
@@ -546,7 +544,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
546544
/* Subtract TOC pointer */
547545
value -= my_r2(sechdrs, me);
548546
if (value + 0x8000 > 0xffff) {
549-
printk("%s: bad TOC16 relocation (%lu)\n",
547+
pr_err("%s: bad TOC16 relocation (0x%lx)\n",
550548
me->name, value);
551549
return -ENOEXEC;
552550
}
@@ -567,7 +565,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
567565
/* Subtract TOC pointer */
568566
value -= my_r2(sechdrs, me);
569567
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",
571569
me->name, value);
572570
return -ENOEXEC;
573571
}
@@ -580,7 +578,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
580578
/* Subtract TOC pointer */
581579
value -= my_r2(sechdrs, me);
582580
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",
584582
me->name, value);
585583
return -ENOEXEC;
586584
}
@@ -613,7 +611,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
613611
/* Convert value to relative */
614612
value -= (unsigned long)location;
615613
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",
617615
me->name, (long int)value);
618616
return -ENOEXEC;
619617
}
@@ -655,7 +653,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
655653
break;
656654

657655
default:
658-
printk("%s: Unknown ADD relocation: %lu\n",
656+
pr_err("%s: Unknown ADD relocation: %lu\n",
659657
me->name,
660658
(unsigned long)ELF64_R_TYPE(rela[i].r_info));
661659
return -ENOEXEC;

0 commit comments

Comments
 (0)