Skip to content

Commit

Permalink
powerpc: Add __printf verification to prom_printf
Browse files Browse the repository at this point in the history
__printf is useful to verify format and arguments. Fix arg mismatch
reported by gcc, remove the following warnings (with W=1):

  arch/powerpc/kernel/prom_init.c:1467:31: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1471:31: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1504:33: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1505:33: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1506:33: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1507:33: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1508:33: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1509:33: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:1975:39: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘unsigned int’
  arch/powerpc/kernel/prom_init.c:1986:27: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:2567:38: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:2567:46: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:2569:38: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘long unsigned int’
  arch/powerpc/kernel/prom_init.c:2569:46: error: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’

The patch also include arg mismatch fix for case with #define DEBUG_PROM
(warning not listed here).

This patch fix also the following warnings revealed by checkpatch:

  WARNING: Prefer using '"%s...", __func__' to using 'alloc_up', this function's name, in a string
  #101: FILE: arch/powerpc/kernel/prom_init.c:1235:
  + prom_debug("alloc_up(%lx, %lx)\n", size, align);

and

  WARNING: Prefer using '"%s...", __func__' to using 'alloc_down', this function's name, in a string
  #138: FILE: arch/powerpc/kernel/prom_init.c:1278:
  + prom_debug("alloc_down(%lx, %lx, %s)\n", size, align,

Signed-off-by: Mathieu Malaterre <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
malaterre authored and mpe committed May 25, 2018
1 parent 2e0986d commit eae5f70
Showing 1 changed file with 58 additions and 56 deletions.
114 changes: 58 additions & 56 deletions arch/powerpc/kernel/prom_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ static void __init prom_print_dec(unsigned long val)
call_prom("write", 3, 1, prom.stdout, buf+i, size);
}

__printf(1, 2)
static void __init prom_printf(const char *format, ...)
{
const char *p, *q, *s;
Expand Down Expand Up @@ -1160,7 +1161,7 @@ static void __init prom_send_capabilities(void)
*/

cores = DIV_ROUND_UP(NR_CPUS, prom_count_smt_threads());
prom_printf("Max number of cores passed to firmware: %lu (NR_CPUS = %lu)\n",
prom_printf("Max number of cores passed to firmware: %u (NR_CPUS = %d)\n",
cores, NR_CPUS);

ibm_architecture_vec.vec5.max_cpus = cpu_to_be32(cores);
Expand Down Expand Up @@ -1242,7 +1243,7 @@ static unsigned long __init alloc_up(unsigned long size, unsigned long align)

if (align)
base = _ALIGN_UP(base, align);
prom_debug("alloc_up(%x, %x)\n", size, align);
prom_debug("%s(%lx, %lx)\n", __func__, size, align);
if (ram_top == 0)
prom_panic("alloc_up() called with mem not initialized\n");

Expand All @@ -1253,7 +1254,7 @@ static unsigned long __init alloc_up(unsigned long size, unsigned long align)

for(; (base + size) <= alloc_top;
base = _ALIGN_UP(base + 0x100000, align)) {
prom_debug(" trying: 0x%x\n\r", base);
prom_debug(" trying: 0x%lx\n\r", base);
addr = (unsigned long)prom_claim(base, size, 0);
if (addr != PROM_ERROR && addr != 0)
break;
Expand All @@ -1265,12 +1266,12 @@ static unsigned long __init alloc_up(unsigned long size, unsigned long align)
return 0;
alloc_bottom = addr + size;

prom_debug(" -> %x\n", addr);
prom_debug(" alloc_bottom : %x\n", alloc_bottom);
prom_debug(" alloc_top : %x\n", alloc_top);
prom_debug(" alloc_top_hi : %x\n", alloc_top_high);
prom_debug(" rmo_top : %x\n", rmo_top);
prom_debug(" ram_top : %x\n", ram_top);
prom_debug(" -> %lx\n", addr);
prom_debug(" alloc_bottom : %lx\n", alloc_bottom);
prom_debug(" alloc_top : %lx\n", alloc_top);
prom_debug(" alloc_top_hi : %lx\n", alloc_top_high);
prom_debug(" rmo_top : %lx\n", rmo_top);
prom_debug(" ram_top : %lx\n", ram_top);

return addr;
}
Expand All @@ -1285,7 +1286,7 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
{
unsigned long base, addr = 0;

prom_debug("alloc_down(%x, %x, %s)\n", size, align,
prom_debug("%s(%lx, %lx, %s)\n", __func__, size, align,
highmem ? "(high)" : "(low)");
if (ram_top == 0)
prom_panic("alloc_down() called with mem not initialized\n");
Expand Down Expand Up @@ -1313,7 +1314,7 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
base = _ALIGN_DOWN(alloc_top - size, align);
for (; base > alloc_bottom;
base = _ALIGN_DOWN(base - 0x100000, align)) {
prom_debug(" trying: 0x%x\n\r", base);
prom_debug(" trying: 0x%lx\n\r", base);
addr = (unsigned long)prom_claim(base, size, 0);
if (addr != PROM_ERROR && addr != 0)
break;
Expand All @@ -1324,12 +1325,12 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
alloc_top = addr;

bail:
prom_debug(" -> %x\n", addr);
prom_debug(" alloc_bottom : %x\n", alloc_bottom);
prom_debug(" alloc_top : %x\n", alloc_top);
prom_debug(" alloc_top_hi : %x\n", alloc_top_high);
prom_debug(" rmo_top : %x\n", rmo_top);
prom_debug(" ram_top : %x\n", ram_top);
prom_debug(" -> %lx\n", addr);
prom_debug(" alloc_bottom : %lx\n", alloc_bottom);
prom_debug(" alloc_top : %lx\n", alloc_top);
prom_debug(" alloc_top_hi : %lx\n", alloc_top_high);
prom_debug(" rmo_top : %lx\n", rmo_top);
prom_debug(" ram_top : %lx\n", ram_top);

return addr;
}
Expand Down Expand Up @@ -1455,7 +1456,7 @@ static void __init prom_init_mem(void)

if (size == 0)
continue;
prom_debug(" %x %x\n", base, size);
prom_debug(" %lx %lx\n", base, size);
if (base == 0 && (of_platform & PLATFORM_LPAR))
rmo_top = size;
if ((base + size) > ram_top)
Expand All @@ -1475,12 +1476,12 @@ static void __init prom_init_mem(void)

if (prom_memory_limit) {
if (prom_memory_limit <= alloc_bottom) {
prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
prom_memory_limit);
prom_printf("Ignoring mem=%lx <= alloc_bottom.\n",
prom_memory_limit);
prom_memory_limit = 0;
} else if (prom_memory_limit >= ram_top) {
prom_printf("Ignoring mem=%x >= ram_top.\n",
prom_memory_limit);
prom_printf("Ignoring mem=%lx >= ram_top.\n",
prom_memory_limit);
prom_memory_limit = 0;
} else {
ram_top = prom_memory_limit;
Expand Down Expand Up @@ -1512,12 +1513,13 @@ static void __init prom_init_mem(void)
alloc_bottom = PAGE_ALIGN(prom_initrd_end);

prom_printf("memory layout at init:\n");
prom_printf(" memory_limit : %x (16 MB aligned)\n", prom_memory_limit);
prom_printf(" alloc_bottom : %x\n", alloc_bottom);
prom_printf(" alloc_top : %x\n", alloc_top);
prom_printf(" alloc_top_hi : %x\n", alloc_top_high);
prom_printf(" rmo_top : %x\n", rmo_top);
prom_printf(" ram_top : %x\n", ram_top);
prom_printf(" memory_limit : %lx (16 MB aligned)\n",
prom_memory_limit);
prom_printf(" alloc_bottom : %lx\n", alloc_bottom);
prom_printf(" alloc_top : %lx\n", alloc_top);
prom_printf(" alloc_top_hi : %lx\n", alloc_top_high);
prom_printf(" rmo_top : %lx\n", rmo_top);
prom_printf(" ram_top : %lx\n", ram_top);
}

static void __init prom_close_stdin(void)
Expand Down Expand Up @@ -1578,7 +1580,7 @@ static void __init prom_instantiate_opal(void)
return;
}

prom_printf("instantiating opal at 0x%x...", base);
prom_printf("instantiating opal at 0x%llx...", base);

if (call_prom_ret("call-method", 4, 3, rets,
ADDR("load-opal-runtime"),
Expand All @@ -1594,10 +1596,10 @@ static void __init prom_instantiate_opal(void)

reserve_mem(base, size);

prom_debug("opal base = 0x%x\n", base);
prom_debug("opal align = 0x%x\n", align);
prom_debug("opal entry = 0x%x\n", entry);
prom_debug("opal size = 0x%x\n", (long)size);
prom_debug("opal base = 0x%llx\n", base);
prom_debug("opal align = 0x%llx\n", align);
prom_debug("opal entry = 0x%llx\n", entry);
prom_debug("opal size = 0x%llx\n", size);

prom_setprop(opal_node, "/ibm,opal", "opal-base-address",
&base, sizeof(base));
Expand Down Expand Up @@ -1674,7 +1676,7 @@ static void __init prom_instantiate_rtas(void)

prom_debug("rtas base = 0x%x\n", base);
prom_debug("rtas entry = 0x%x\n", entry);
prom_debug("rtas size = 0x%x\n", (long)size);
prom_debug("rtas size = 0x%x\n", size);

prom_debug("prom_instantiate_rtas: end...\n");
}
Expand Down Expand Up @@ -1732,7 +1734,7 @@ static void __init prom_instantiate_sml(void)
if (base == 0)
prom_panic("Could not allocate memory for sml\n");

prom_printf("instantiating sml at 0x%x...", base);
prom_printf("instantiating sml at 0x%llx...", base);

memset((void *)base, 0, size);

Expand All @@ -1751,8 +1753,8 @@ static void __init prom_instantiate_sml(void)
prom_setprop(ibmvtpm_node, "/vdevice/vtpm", "linux,sml-size",
&size, sizeof(size));

prom_debug("sml base = 0x%x\n", base);
prom_debug("sml size = 0x%x\n", (long)size);
prom_debug("sml base = 0x%llx\n", base);
prom_debug("sml size = 0x%x\n", size);

prom_debug("prom_instantiate_sml: end...\n");
}
Expand Down Expand Up @@ -1845,7 +1847,7 @@ static void __init prom_initialize_tce_table(void)

prom_debug("TCE table: %s\n", path);
prom_debug("\tnode = 0x%x\n", node);
prom_debug("\tbase = 0x%x\n", base);
prom_debug("\tbase = 0x%llx\n", base);
prom_debug("\tsize = 0x%x\n", minsize);

/* Initialize the table to have a one-to-one mapping
Expand Down Expand Up @@ -1932,12 +1934,12 @@ static void __init prom_hold_cpus(void)
}

prom_debug("prom_hold_cpus: start...\n");
prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
prom_debug(" 1) acknowledge = 0x%x\n",
prom_debug(" 1) spinloop = 0x%lx\n", (unsigned long)spinloop);
prom_debug(" 1) *spinloop = 0x%lx\n", *spinloop);
prom_debug(" 1) acknowledge = 0x%lx\n",
(unsigned long)acknowledge);
prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
prom_debug(" 1) *acknowledge = 0x%lx\n", *acknowledge);
prom_debug(" 1) secondary_hold = 0x%lx\n", secondary_hold);

/* Set the common spinloop variable, so all of the secondary cpus
* will block when they are awakened from their OF spinloop.
Expand Down Expand Up @@ -1965,7 +1967,7 @@ static void __init prom_hold_cpus(void)
prom_getprop(node, "reg", &reg, sizeof(reg));
cpu_no = be32_to_cpu(reg);

prom_debug("cpu hw idx = %lu\n", cpu_no);
prom_debug("cpu hw idx = %u\n", cpu_no);

/* Init the acknowledge var which will be reset by
* the secondary cpu when it awakens from its OF
Expand All @@ -1975,7 +1977,7 @@ static void __init prom_hold_cpus(void)

if (cpu_no != prom.cpu) {
/* Primary Thread of non-boot cpu or any thread */
prom_printf("starting cpu hw idx %lu... ", cpu_no);
prom_printf("starting cpu hw idx %u... ", cpu_no);
call_prom("start-cpu", 3, 0, node,
secondary_hold, cpu_no);

Expand All @@ -1986,11 +1988,11 @@ static void __init prom_hold_cpus(void)
if (*acknowledge == cpu_no)
prom_printf("done\n");
else
prom_printf("failed: %x\n", *acknowledge);
prom_printf("failed: %lx\n", *acknowledge);
}
#ifdef CONFIG_SMP
else
prom_printf("boot cpu hw idx %lu\n", cpu_no);
prom_printf("boot cpu hw idx %u\n", cpu_no);
#endif /* CONFIG_SMP */
}

Expand Down Expand Up @@ -2268,7 +2270,7 @@ static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end,
while ((*mem_start + needed) > *mem_end) {
unsigned long room, chunk;

prom_debug("Chunk exhausted, claiming more at %x...\n",
prom_debug("Chunk exhausted, claiming more at %lx...\n",
alloc_bottom);
room = alloc_top - alloc_bottom;
if (room > DEVTREE_CHUNK_SIZE)
Expand Down Expand Up @@ -2494,7 +2496,7 @@ static void __init flatten_device_tree(void)
room = alloc_top - alloc_bottom - 0x4000;
if (room > DEVTREE_CHUNK_SIZE)
room = DEVTREE_CHUNK_SIZE;
prom_debug("starting device tree allocs at %x\n", alloc_bottom);
prom_debug("starting device tree allocs at %lx\n", alloc_bottom);

/* Now try to claim that */
mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
Expand Down Expand Up @@ -2557,7 +2559,7 @@ static void __init flatten_device_tree(void)
int i;
prom_printf("reserved memory map:\n");
for (i = 0; i < mem_reserve_cnt; i++)
prom_printf(" %x - %x\n",
prom_printf(" %llx - %llx\n",
be64_to_cpu(mem_reserve_map[i].base),
be64_to_cpu(mem_reserve_map[i].size));
}
Expand All @@ -2567,9 +2569,9 @@ static void __init flatten_device_tree(void)
*/
mem_reserve_cnt = MEM_RESERVE_MAP_SIZE;

prom_printf("Device tree strings 0x%x -> 0x%x\n",
prom_printf("Device tree strings 0x%lx -> 0x%lx\n",
dt_string_start, dt_string_end);
prom_printf("Device tree struct 0x%x -> 0x%x\n",
prom_printf("Device tree struct 0x%lx -> 0x%lx\n",
dt_struct_start, dt_struct_end);
}

Expand Down Expand Up @@ -3001,7 +3003,7 @@ static void __init prom_find_boot_cpu(void)
prom_getprop(cpu_pkg, "reg", &rval, sizeof(rval));
prom.cpu = be32_to_cpu(rval);

prom_debug("Booting CPU hw index = %lu\n", prom.cpu);
prom_debug("Booting CPU hw index = %d\n", prom.cpu);
}

static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
Expand All @@ -3023,8 +3025,8 @@ static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
reserve_mem(prom_initrd_start,
prom_initrd_end - prom_initrd_start);

prom_debug("initrd_start=0x%x\n", prom_initrd_start);
prom_debug("initrd_end=0x%x\n", prom_initrd_end);
prom_debug("initrd_start=0x%lx\n", prom_initrd_start);
prom_debug("initrd_end=0x%lx\n", prom_initrd_end);
}
#endif /* CONFIG_BLK_DEV_INITRD */
}
Expand Down Expand Up @@ -3277,7 +3279,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
/* Don't print anything after quiesce under OPAL, it crashes OFW */
if (of_platform != PLATFORM_OPAL) {
prom_printf("Booting Linux via __start() @ 0x%lx ...\n", kbase);
prom_debug("->dt_header_start=0x%x\n", hdr);
prom_debug("->dt_header_start=0x%lx\n", hdr);
}

#ifdef CONFIG_PPC32
Expand Down

0 comments on commit eae5f70

Please sign in to comment.