Check the printk format string against the matching arguments. We have
this type of checking in the v3 code since ages, but v2 will happily
compile any code with bogus printk format strings and/or parameters.
This can cause real bugs and at least needs to emit a warning, if not an
error. Go with a warning for now since most of the flagged format
strings are wrong but harmless in a 32-bit x86 environment.

The following warnings are triggered in my dbm690t build:

src/southbridge/amd/sb600/sb600_hda.c:284: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 3 has type ‘u8 *’
src/mainboard/amd/dbm690t/mainboard.c:200: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘device_t’
src/mainboard/amd/dbm690t/mainboard.c:236: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/mainboard/amd/dbm690t/mainboard.c:236: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 4 has type ‘long unsigned int’
src/mainboard/amd/dbm690t/mainboard.c:256: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/mainboard/amd/dbm690t/mainboard.c:256: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 4 has type ‘long unsigned int’
src/southbridge/amd/rs690/rs690_gfx.c:124: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘device_t’
src/southbridge/amd/rs690/rs690_gfx.c:124: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 4 has type ‘device_t’
src/southbridge/amd/rs690/rs690_gfx.c:420: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘device_t’
src/southbridge/amd/rs690/rs690_gfx.c:420: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 4 has type ‘device_t’
src/southbridge/amd/rs690/rs690.c:132: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘device_t’
src/southbridge/amd/sb600/sb600_usb.c:97: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘u8 *’
src/cpu/amd/model_fxx/model_fxx_init.c:234: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/cpu/amd/model_fxx/model_fxx_init.c:315: warning: format ‘%u’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/cpu/amd/model_fxx/model_fxx_init.c:315: warning: format ‘%u’ expects type 
‘unsigned int’, but argument 4 has type ‘long unsigned int’
src/southbridge/amd/rs690/rs690_pcie.c:206: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘device_t’
src/southbridge/amd/rs690/rs690_pcie.c:206: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 4 has type ‘device_t’
src/cpu/x86/lapic/lapic.c:58: warning: format ‘%02x’ expects type ‘unsigned 
int’, but argument 3 has type ‘long unsigned int’
src/cpu/x86/lapic/lapic_cpu_init.c:88: warning: format ‘%d’ expects type ‘int’, 
but argument 3 has type ‘long unsigned int’
src/cpu/x86/lapic/lapic_cpu_init.c:91: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/cpu/x86/lapic/lapic_cpu_init.c:95: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/cpu/x86/lapic/lapic_cpu_init.c:117: warning: format ‘%d’ expects type 
‘int’, but argument 3 has type ‘long unsigned int’
src/cpu/x86/lapic/lapic_cpu_init.c:242: warning: format ‘%d’ expects type 
‘int’, but argument 3 has type ‘long unsigned int’
src/arch/i386/boot/tables.c:95: warning: format ‘%0x’ expects type ‘unsigned 
int’, but argument 3 has type ‘long unsigned int’
src/mainboard/amd/dbm690t/acpi_tables.c:721: warning: format ‘%08x’ expects 
type ‘unsigned int’, but argument 3 has type ‘struct acpi_header_t *’
src/devices/pnp_device.c:106: warning: format ‘%02x’ expects type ‘unsigned 
int’, but argument 4 has type ‘long unsigned int’
src/devices/pnp_device.c:124: warning: format ‘%02x’ expects type ‘unsigned 
int’, but argument 4 has type ‘long unsigned int’
src/mainboard/amd/dbm690t/irq_tables.c:76: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/devices/pci_device.c:209: warning: format ‘%02x’ expects type ‘unsigned 
int’, but argument 4 has type ‘long unsigned int’
src/devices/pci_device.c:209: warning: format ‘%08x’ expects type ‘unsigned 
int’, but argument 5 has type ‘long unsigned int’
src/devices/pci_device.c:314: warning: format ‘%02x’ expects type ‘unsigned 
int’, but argument 4 has type ‘long unsigned int’
src/devices/pci_device.c:314: warning: format ‘%08x’ expects type ‘unsigned 
int’, but argument 5 has type ‘long unsigned int’
src/devices/pci_device.c:462: warning: format ‘%02x’ expects type ‘unsigned 
int’, but argument 4 has type ‘long unsigned int’
src/devices/pci_device.c:549: warning: format ‘%x’ expects type ‘unsigned int’, 
but argument 3 has type ‘long unsigned int’
src/boot/elfboot.c:79: warning: format ‘%04x’ expects type ‘unsigned int’, but 
argument 4 has type ‘long unsigned int’
src/boot/elfboot.c:502: warning: format ‘%016lx’ expects type ‘long unsigned 
int’, but argument 4 has type ‘int’
src/boot/elfboot.c:593: warning: format ‘%x’ expects type ‘unsigned int’, but 
argument 3 has type ‘void *’
src/northbridge/amd/amdk8/amdk8_acpi.c:140: warning: format ‘%04x’ expects type 
‘unsigned int’, but argument 4 has type ‘long unsigned int’
src/northbridge/amd/amdk8/amdk8_acpi.c:140: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 5 has type ‘long unsigned int’
src/northbridge/amd/amdk8/amdk8_acpi.c:140: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 6 has type ‘long unsigned int’
src/devices/device_util.c:469: warning: format ‘%02x’ expects type ‘unsigned 
int’, but argument 4 has type ‘long unsigned int’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 5 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 7 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 8 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 9 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 10 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 11 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 12 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 13 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 14 has type ‘uint32_t’
src/arch/i386/lib/exception.c:483: warning: format ‘%08lx’ expects type ‘long 
unsigned int’, but argument 15 has type ‘uint32_t’
src/cpu/x86/mtrr/mtrr.c:244: warning: format ‘%4d’ expects type ‘int’, but 
argument 4 has type ‘long unsigned int’
src/cpu/x86/mtrr/mtrr.c:244: warning: format ‘%4d’ expects type ‘int’, but 
argument 5 has type ‘long unsigned int’
src/arch/i386/boot/pirq_routing.c:69: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/arch/i386/boot/pirq_routing.c:94: warning: format ‘%x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/devices/pci_rom.c:48: warning: format ‘%x’ expects type ‘unsigned int’, but 
argument 4 has type ‘long unsigned int’
src/devices/pci_rom.c:113: warning: format ‘%x’ expects type ‘unsigned int’, 
but argument 3 has type ‘struct rom_header *’
src/devices/pci_rom.c:118: warning: format ‘%x’ expects type ‘unsigned int’, 
but argument 3 has type ‘struct rom_header *’
src/devices/pci_rom.c:118: warning: format ‘%x’ expects type ‘unsigned int’, 
but argument 4 has type ‘void *’
src/arch/i386/boot/coreboot_table.c:254: warning: format ‘%lx’ expects type 
‘long unsigned int’, but argument 5 has type ‘uint32_t’
src/arch/i386/boot/coreboot_table.c:418: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/arch/i386/boot/coreboot_table.c:421: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/arch/i386/boot/coreboot_table.c:424: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/arch/i386/boot/coreboot_table.c:427: warning: format ‘%08x’ expects type 
‘unsigned int’, but argument 3 has type ‘long unsigned int’
src/arch/i386/lib/cpu.c:228: warning: format ‘%d’ expects type ‘int’, but 
argument 3 has type ‘long unsigned int’
src/arch/i386/lib/cpu.c:264: warning: format ‘%d’ expects type ‘int’, but 
argument 3 has type ‘long unsigned int’



Signed-off-by: Carl-Daniel Hailfinger <[email protected]>

Index: LinuxBIOSv2-printk_format/src/include/console/console.h
===================================================================
--- LinuxBIOSv2-printk_format/src/include/console/console.h     (Revision 3845)
+++ LinuxBIOSv2-printk_format/src/include/console/console.h     (Arbeitskopie)
@@ -27,7 +27,7 @@
 extern struct console_driver econsole_drivers[];
 
 extern int console_loglevel;
-int do_printk(int msg_level, const char *fmt, ...);
+int do_printk(int msg_level, const char *fmt, ...) 
__attribute__((format(printf, 2, 3)));
 
 #define printk_emerg(fmt, arg...)   do_printk(BIOS_EMERG   ,fmt, ##arg)
 #define printk_alert(fmt, arg...)   do_printk(BIOS_ALERT   ,fmt, ##arg)


-- 
http://www.hailfinger.org/

Index: LinuxBIOSv2-printk_format/src/include/console/console.h
===================================================================
--- LinuxBIOSv2-printk_format/src/include/console/console.h	(Revision 3845)
+++ LinuxBIOSv2-printk_format/src/include/console/console.h	(Arbeitskopie)
@@ -27,7 +27,7 @@
 extern struct console_driver econsole_drivers[];
 
 extern int console_loglevel;
-int do_printk(int msg_level, const char *fmt, ...);
+int do_printk(int msg_level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
 
 #define printk_emerg(fmt, arg...)   do_printk(BIOS_EMERG   ,fmt, ##arg)
 #define printk_alert(fmt, arg...)   do_printk(BIOS_ALERT   ,fmt, ##arg)
--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to