Skip to content

Commit eae5f70

Browse files
malaterrempe
authored andcommitted
powerpc: Add __printf verification to prom_printf
__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]>
1 parent 2e0986d commit eae5f70

File tree

1 file changed

+58
-56
lines changed

1 file changed

+58
-56
lines changed

arch/powerpc/kernel/prom_init.c

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ static void __init prom_print_dec(unsigned long val)
334334
call_prom("write", 3, 1, prom.stdout, buf+i, size);
335335
}
336336

337+
__printf(1, 2)
337338
static void __init prom_printf(const char *format, ...)
338339
{
339340
const char *p, *q, *s;
@@ -1160,7 +1161,7 @@ static void __init prom_send_capabilities(void)
11601161
*/
11611162

11621163
cores = DIV_ROUND_UP(NR_CPUS, prom_count_smt_threads());
1163-
prom_printf("Max number of cores passed to firmware: %lu (NR_CPUS = %lu)\n",
1164+
prom_printf("Max number of cores passed to firmware: %u (NR_CPUS = %d)\n",
11641165
cores, NR_CPUS);
11651166

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

12431244
if (align)
12441245
base = _ALIGN_UP(base, align);
1245-
prom_debug("alloc_up(%x, %x)\n", size, align);
1246+
prom_debug("%s(%lx, %lx)\n", __func__, size, align);
12461247
if (ram_top == 0)
12471248
prom_panic("alloc_up() called with mem not initialized\n");
12481249

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

12541255
for(; (base + size) <= alloc_top;
12551256
base = _ALIGN_UP(base + 0x100000, align)) {
1256-
prom_debug(" trying: 0x%x\n\r", base);
1257+
prom_debug(" trying: 0x%lx\n\r", base);
12571258
addr = (unsigned long)prom_claim(base, size, 0);
12581259
if (addr != PROM_ERROR && addr != 0)
12591260
break;
@@ -1265,12 +1266,12 @@ static unsigned long __init alloc_up(unsigned long size, unsigned long align)
12651266
return 0;
12661267
alloc_bottom = addr + size;
12671268

1268-
prom_debug(" -> %x\n", addr);
1269-
prom_debug(" alloc_bottom : %x\n", alloc_bottom);
1270-
prom_debug(" alloc_top : %x\n", alloc_top);
1271-
prom_debug(" alloc_top_hi : %x\n", alloc_top_high);
1272-
prom_debug(" rmo_top : %x\n", rmo_top);
1273-
prom_debug(" ram_top : %x\n", ram_top);
1269+
prom_debug(" -> %lx\n", addr);
1270+
prom_debug(" alloc_bottom : %lx\n", alloc_bottom);
1271+
prom_debug(" alloc_top : %lx\n", alloc_top);
1272+
prom_debug(" alloc_top_hi : %lx\n", alloc_top_high);
1273+
prom_debug(" rmo_top : %lx\n", rmo_top);
1274+
prom_debug(" ram_top : %lx\n", ram_top);
12741275

12751276
return addr;
12761277
}
@@ -1285,7 +1286,7 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
12851286
{
12861287
unsigned long base, addr = 0;
12871288

1288-
prom_debug("alloc_down(%x, %x, %s)\n", size, align,
1289+
prom_debug("%s(%lx, %lx, %s)\n", __func__, size, align,
12891290
highmem ? "(high)" : "(low)");
12901291
if (ram_top == 0)
12911292
prom_panic("alloc_down() called with mem not initialized\n");
@@ -1313,7 +1314,7 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
13131314
base = _ALIGN_DOWN(alloc_top - size, align);
13141315
for (; base > alloc_bottom;
13151316
base = _ALIGN_DOWN(base - 0x100000, align)) {
1316-
prom_debug(" trying: 0x%x\n\r", base);
1317+
prom_debug(" trying: 0x%lx\n\r", base);
13171318
addr = (unsigned long)prom_claim(base, size, 0);
13181319
if (addr != PROM_ERROR && addr != 0)
13191320
break;
@@ -1324,12 +1325,12 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
13241325
alloc_top = addr;
13251326

13261327
bail:
1327-
prom_debug(" -> %x\n", addr);
1328-
prom_debug(" alloc_bottom : %x\n", alloc_bottom);
1329-
prom_debug(" alloc_top : %x\n", alloc_top);
1330-
prom_debug(" alloc_top_hi : %x\n", alloc_top_high);
1331-
prom_debug(" rmo_top : %x\n", rmo_top);
1332-
prom_debug(" ram_top : %x\n", ram_top);
1328+
prom_debug(" -> %lx\n", addr);
1329+
prom_debug(" alloc_bottom : %lx\n", alloc_bottom);
1330+
prom_debug(" alloc_top : %lx\n", alloc_top);
1331+
prom_debug(" alloc_top_hi : %lx\n", alloc_top_high);
1332+
prom_debug(" rmo_top : %lx\n", rmo_top);
1333+
prom_debug(" ram_top : %lx\n", ram_top);
13331334

13341335
return addr;
13351336
}
@@ -1455,7 +1456,7 @@ static void __init prom_init_mem(void)
14551456

14561457
if (size == 0)
14571458
continue;
1458-
prom_debug(" %x %x\n", base, size);
1459+
prom_debug(" %lx %lx\n", base, size);
14591460
if (base == 0 && (of_platform & PLATFORM_LPAR))
14601461
rmo_top = size;
14611462
if ((base + size) > ram_top)
@@ -1475,12 +1476,12 @@ static void __init prom_init_mem(void)
14751476

14761477
if (prom_memory_limit) {
14771478
if (prom_memory_limit <= alloc_bottom) {
1478-
prom_printf("Ignoring mem=%x <= alloc_bottom.\n",
1479-
prom_memory_limit);
1479+
prom_printf("Ignoring mem=%lx <= alloc_bottom.\n",
1480+
prom_memory_limit);
14801481
prom_memory_limit = 0;
14811482
} else if (prom_memory_limit >= ram_top) {
1482-
prom_printf("Ignoring mem=%x >= ram_top.\n",
1483-
prom_memory_limit);
1483+
prom_printf("Ignoring mem=%lx >= ram_top.\n",
1484+
prom_memory_limit);
14841485
prom_memory_limit = 0;
14851486
} else {
14861487
ram_top = prom_memory_limit;
@@ -1512,12 +1513,13 @@ static void __init prom_init_mem(void)
15121513
alloc_bottom = PAGE_ALIGN(prom_initrd_end);
15131514

15141515
prom_printf("memory layout at init:\n");
1515-
prom_printf(" memory_limit : %x (16 MB aligned)\n", prom_memory_limit);
1516-
prom_printf(" alloc_bottom : %x\n", alloc_bottom);
1517-
prom_printf(" alloc_top : %x\n", alloc_top);
1518-
prom_printf(" alloc_top_hi : %x\n", alloc_top_high);
1519-
prom_printf(" rmo_top : %x\n", rmo_top);
1520-
prom_printf(" ram_top : %x\n", ram_top);
1516+
prom_printf(" memory_limit : %lx (16 MB aligned)\n",
1517+
prom_memory_limit);
1518+
prom_printf(" alloc_bottom : %lx\n", alloc_bottom);
1519+
prom_printf(" alloc_top : %lx\n", alloc_top);
1520+
prom_printf(" alloc_top_hi : %lx\n", alloc_top_high);
1521+
prom_printf(" rmo_top : %lx\n", rmo_top);
1522+
prom_printf(" ram_top : %lx\n", ram_top);
15211523
}
15221524

15231525
static void __init prom_close_stdin(void)
@@ -1578,7 +1580,7 @@ static void __init prom_instantiate_opal(void)
15781580
return;
15791581
}
15801582

1581-
prom_printf("instantiating opal at 0x%x...", base);
1583+
prom_printf("instantiating opal at 0x%llx...", base);
15821584

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

15951597
reserve_mem(base, size);
15961598

1597-
prom_debug("opal base = 0x%x\n", base);
1598-
prom_debug("opal align = 0x%x\n", align);
1599-
prom_debug("opal entry = 0x%x\n", entry);
1600-
prom_debug("opal size = 0x%x\n", (long)size);
1599+
prom_debug("opal base = 0x%llx\n", base);
1600+
prom_debug("opal align = 0x%llx\n", align);
1601+
prom_debug("opal entry = 0x%llx\n", entry);
1602+
prom_debug("opal size = 0x%llx\n", size);
16011603

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

16751677
prom_debug("rtas base = 0x%x\n", base);
16761678
prom_debug("rtas entry = 0x%x\n", entry);
1677-
prom_debug("rtas size = 0x%x\n", (long)size);
1679+
prom_debug("rtas size = 0x%x\n", size);
16781680

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

1735-
prom_printf("instantiating sml at 0x%x...", base);
1737+
prom_printf("instantiating sml at 0x%llx...", base);
17361738

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

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

1754-
prom_debug("sml base = 0x%x\n", base);
1755-
prom_debug("sml size = 0x%x\n", (long)size);
1756+
prom_debug("sml base = 0x%llx\n", base);
1757+
prom_debug("sml size = 0x%x\n", size);
17561758

17571759
prom_debug("prom_instantiate_sml: end...\n");
17581760
}
@@ -1845,7 +1847,7 @@ static void __init prom_initialize_tce_table(void)
18451847

18461848
prom_debug("TCE table: %s\n", path);
18471849
prom_debug("\tnode = 0x%x\n", node);
1848-
prom_debug("\tbase = 0x%x\n", base);
1850+
prom_debug("\tbase = 0x%llx\n", base);
18491851
prom_debug("\tsize = 0x%x\n", minsize);
18501852

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

19341936
prom_debug("prom_hold_cpus: start...\n");
1935-
prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop);
1936-
prom_debug(" 1) *spinloop = 0x%x\n", *spinloop);
1937-
prom_debug(" 1) acknowledge = 0x%x\n",
1937+
prom_debug(" 1) spinloop = 0x%lx\n", (unsigned long)spinloop);
1938+
prom_debug(" 1) *spinloop = 0x%lx\n", *spinloop);
1939+
prom_debug(" 1) acknowledge = 0x%lx\n",
19381940
(unsigned long)acknowledge);
1939-
prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge);
1940-
prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold);
1941+
prom_debug(" 1) *acknowledge = 0x%lx\n", *acknowledge);
1942+
prom_debug(" 1) secondary_hold = 0x%lx\n", secondary_hold);
19411943

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

1968-
prom_debug("cpu hw idx = %lu\n", cpu_no);
1970+
prom_debug("cpu hw idx = %u\n", cpu_no);
19691971

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

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

@@ -1986,11 +1988,11 @@ static void __init prom_hold_cpus(void)
19861988
if (*acknowledge == cpu_no)
19871989
prom_printf("done\n");
19881990
else
1989-
prom_printf("failed: %x\n", *acknowledge);
1991+
prom_printf("failed: %lx\n", *acknowledge);
19901992
}
19911993
#ifdef CONFIG_SMP
19921994
else
1993-
prom_printf("boot cpu hw idx %lu\n", cpu_no);
1995+
prom_printf("boot cpu hw idx %u\n", cpu_no);
19941996
#endif /* CONFIG_SMP */
19951997
}
19961998

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

2271-
prom_debug("Chunk exhausted, claiming more at %x...\n",
2273+
prom_debug("Chunk exhausted, claiming more at %lx...\n",
22722274
alloc_bottom);
22732275
room = alloc_top - alloc_bottom;
22742276
if (room > DEVTREE_CHUNK_SIZE)
@@ -2494,7 +2496,7 @@ static void __init flatten_device_tree(void)
24942496
room = alloc_top - alloc_bottom - 0x4000;
24952497
if (room > DEVTREE_CHUNK_SIZE)
24962498
room = DEVTREE_CHUNK_SIZE;
2497-
prom_debug("starting device tree allocs at %x\n", alloc_bottom);
2499+
prom_debug("starting device tree allocs at %lx\n", alloc_bottom);
24982500

24992501
/* Now try to claim that */
25002502
mem_start = (unsigned long)alloc_up(room, PAGE_SIZE);
@@ -2557,7 +2559,7 @@ static void __init flatten_device_tree(void)
25572559
int i;
25582560
prom_printf("reserved memory map:\n");
25592561
for (i = 0; i < mem_reserve_cnt; i++)
2560-
prom_printf(" %x - %x\n",
2562+
prom_printf(" %llx - %llx\n",
25612563
be64_to_cpu(mem_reserve_map[i].base),
25622564
be64_to_cpu(mem_reserve_map[i].size));
25632565
}
@@ -2567,9 +2569,9 @@ static void __init flatten_device_tree(void)
25672569
*/
25682570
mem_reserve_cnt = MEM_RESERVE_MAP_SIZE;
25692571

2570-
prom_printf("Device tree strings 0x%x -> 0x%x\n",
2572+
prom_printf("Device tree strings 0x%lx -> 0x%lx\n",
25712573
dt_string_start, dt_string_end);
2572-
prom_printf("Device tree struct 0x%x -> 0x%x\n",
2574+
prom_printf("Device tree struct 0x%lx -> 0x%lx\n",
25732575
dt_struct_start, dt_struct_end);
25742576
}
25752577

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

3004-
prom_debug("Booting CPU hw index = %lu\n", prom.cpu);
3006+
prom_debug("Booting CPU hw index = %d\n", prom.cpu);
30053007
}
30063008

30073009
static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
@@ -3023,8 +3025,8 @@ static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
30233025
reserve_mem(prom_initrd_start,
30243026
prom_initrd_end - prom_initrd_start);
30253027

3026-
prom_debug("initrd_start=0x%x\n", prom_initrd_start);
3027-
prom_debug("initrd_end=0x%x\n", prom_initrd_end);
3028+
prom_debug("initrd_start=0x%lx\n", prom_initrd_start);
3029+
prom_debug("initrd_end=0x%lx\n", prom_initrd_end);
30283030
}
30293031
#endif /* CONFIG_BLK_DEV_INITRD */
30303032
}
@@ -3277,7 +3279,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
32773279
/* Don't print anything after quiesce under OPAL, it crashes OFW */
32783280
if (of_platform != PLATFORM_OPAL) {
32793281
prom_printf("Booting Linux via __start() @ 0x%lx ...\n", kbase);
3280-
prom_debug("->dt_header_start=0x%x\n", hdr);
3282+
prom_debug("->dt_header_start=0x%lx\n", hdr);
32813283
}
32823284

32833285
#ifdef CONFIG_PPC32

0 commit comments

Comments
 (0)