Skip to contentSkip to conversation

fix 32-bit compile warning from printk()

PATCH In review Dave Hansen 4 participants 5 messages Jan 28, 2013 – Feb 13, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix 32-bit compile warning from printk()

My patch "Fix kvm's use of __pa() on percpu areas" introduced a compile warning:

arch/x86/kernel/kvm.c: In function 'kvm_register_steal_time':
arch/x86/kernel/kvm.c:302:3: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'phys_addr_t' [-Wformat]

According to: Documentation/printk-formats.txt

If <type> is dependent on a config option for its size (e.g., phys_addr_t) ... use a format specifier of its largest possible type and explicitly cast to it.

So, we'll do just that. We will consider it an unsigned long long, and cast to it explicitly.

---

 linux-2.6.git-dave/arch/x86/kernel/kvm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/kvm.c renamed from arch/x86/kernel/kvm.c~fix-32-bit-compile-warning +2 -2
diff -puN arch/x86/kernel/kvm.c~fix-32-bit-compile-warning arch/x86/kernel/kvm.c
@@ -298,8 +298,8 @@ static void kvm_register_steal_time(void
 	memset(st, 0, sizeof(*st));
 
 	wrmsrl(MSR_KVM_STEAL_TIME, (slow_virt_to_phys(st) | KVM_MSR_ENABLED));
-	printk(KERN_INFO "kvm-stealtime: cpu %d, msr %lx\n",
-		cpu, slow_virt_to_phys(st));
+	printk(KERN_INFO "kvm-stealtime: cpu %d, msr %llx\n",
+		cpu, (unsigned long long)slow_virt_to_phys(st));
 }
 
 static DEFINE_PER_CPU(unsigned long, kvm_apic_eoi) = KVM_PV_EOI_DISABLED;

_

#1 lore raw
Quoted 6 lines · On Mon, 28 Jan 2013 11:19:39 -0800 Dave Hansen <[email protected]> wrote:

My patch "Fix kvm's use of __pa() on percpu areas" introduced a compile warning:

arch/x86/kernel/kvm.c: In function 'kvm_register_steal_time':
arch/x86/kernel/kvm.c:302:3: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'phys_addr_t' [-Wformat]

Quoted 8 lines

According to: Documentation/printk-formats.txt

If <type> is dependent on a config option for its size (e.g., phys_addr_t) ... use a format specifier of its largest possible type and explicitly cast to it.

So, we'll do just that. We will consider it an unsigned long long, and cast to it explicitly.

Please note that I have
http://ozlabs.org/~akpm/mmots/broken-out/lib-vsprintf-add-%25pa-format-specifier-for-phys_addr_t-types.patch
queued for 3.8.

#2 lore raw
Quoted 14 lines · On Tue, 29 Jan 2013 02:54:28 -0800 Andrew Morton <[email protected]>…
Quoted 12 lines · On Mon, 28 Jan 2013 11:19:39 -0800 Dave Hansen <[email protected]> wrote:

My patch "Fix kvm's use of __pa() on percpu areas" introduced a compile warning:

arch/x86/kernel/kvm.c: In function 'kvm_register_steal_time':
arch/x86/kernel/kvm.c:302:3: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'phys_addr_t' [-Wformat]

According to: Documentation/printk-formats.txt

If <type> is dependent on a config option for its size (e.g., phys_addr_t) ... use a format specifier of its largest possible type and explicitly cast to it.

Quoted 7 lines
Quoted 2 lines

So, we'll do just that. We will consider it an unsigned long long, and cast to it explicitly.

Please note that I have
http://ozlabs.org/~akpm/mmots/broken-out/lib-vsprintf-add-%25pa-format-specifier-for-phys_addr_t-types.patch
queued for 3.8.

err, I meant 3.9.

Acked-by on v1 1/1
#3 lore raw
In reply to Dave Hansen
Quoted 8 lines · Dave Hansen

My patch "Fix kvm's use of __pa() on percpu areas" introduced a compile warning:

arch/x86/kernel/kvm.c: In function 'kvm_register_steal_time':
arch/x86/kernel/kvm.c:302:3: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'phys_addr_t' [-Wformat]

According to: Documentation/printk-formats.txt

Quoted 8 lines

If <type> is dependent on a config option for its size (e.g., phys_addr_t) ... use a format specifier of its largest possible type and explicitly cast to it.

So, we'll do just that. We will consider it an unsigned long long, and cast to it explicitly.

This warning is still present in linux-next (20130213).

Thanks.

Someone please merge... (kvm@ cc added)

Quoted 20 lines

---

 linux-2.6.git-dave/arch/x86/kernel/kvm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN arch/x86/kernel/kvm.c~fix-32-bit-compile-warning arch/x86/kernel/kvm.c

arch/x86/kernel/kvm.c renamed from arch/x86/kernel/kvm.c~fix-32-bit-compile-warning +2 -2
@@ -298,8 +298,8 @@ static void kvm_register_steal_time(void
 	memset(st, 0, sizeof(*st));
 
 	wrmsrl(MSR_KVM_STEAL_TIME, (slow_virt_to_phys(st) | KVM_MSR_ENABLED));
-	printk(KERN_INFO "kvm-stealtime: cpu %d, msr %lx\n",
-		cpu, slow_virt_to_phys(st));
+	printk(KERN_INFO "kvm-stealtime: cpu %d, msr %llx\n",
+		cpu, (unsigned long long)slow_virt_to_phys(st));
 }
 
 static DEFINE_PER_CPU(unsigned long, kvm_apic_eoi) = KVM_PV_EOI_DISABLED;

_

Signature · 1 line
~Randy
maintainer
#4 lore raw
Quoted 7 lines · Randy Dunlap

This warning is still present in linux-next (20130213).

Thanks.

Someone please merge... (kvm@ cc added)

There's a fix already in tip for this:

http://git.kernel.org/tip/136867f517cbc3f8a91f035677911a6b503c3323

which needs to change again once the %pa printk stuff get merged.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--