dm: fix printk errors about whether %lu/%Lu is right for sector_t - revised
PATCH 1/1 dm: fix printk errors about whether %lu/%Lu is right for sector_t - revised
The Device Manager code barfs when sector_t is 64bit wide (i.e. an u64) and CONFIG_LBD is off. This happens on printk(), resulting in wrong memory accesses, but also on sscanf(), resulting in overflows (because it uses %lu for a long long in this case). And region_t, chunk_t are typedefs for sector_t, so we have warnings for these, too.
Andrew Morton suggested simply using "%llu" and casting sector_t to unsigned long long; but he missed the sscanf()'s, which cannot be fixed this way.
I've used %llu instead of %Lu for standards conformance, as suggested by
The problem is this code in drivers/md/dm.h:
/*
* FIXME: I think this should be with the definition of sector_t
* in types.h.
*/
#ifdef CONFIG_LBD
#define SECTOR_FORMAT "%Lu"
#else
#define SECTOR_FORMAT "%lu"
#endif
So we must fix the FIXME. However, having sector_t defined by the arch is wrong in all current cases, and we fix these: we can simply decide this in linux/types.h following CONFIG_LBD.
So, I have also removed HAVE_SECTOR_T; you can readd it, but it has no users.
All 64-bit arch use a 64-bit wide long for sector_t; almost all 32-bit archs use a long long only if CONFIG_LBD is on. The only exception is h8300: for that case, we add CONFIG_LBD = y and we are again in the general case. And x86_64 does not need to define sector_t on its own.
Sample warnings (from both 2.6.8.1 and 2.6.9-rc2):drivers/md/dm-raid1.c: In function `get_mirror':drivers/md/dm-raid1.c:930: warning: long unsigned int format, sector_t arg (arg 3) drivers/md/dm-raid1.c: In function `mirror_status':drivers/md/dm-raid1.c:1200: warning: long unsigned int format, region_t arg (arg 4) drivers/md/dm-raid1.c:1200: warning: long unsigned int format, region_t arg (arg 5) drivers/md/dm-raid1.c:1206: warning: long unsigned int format, sector_t arg (arg 5) drivers/md/dm-raid1.c:1212: warning: long unsigned int format, sector_t arg (arg 5)
---
linux-2.6.9-current-paolo/arch/h8300/Kconfig | 4 ++++ linux-2.6.9-current-paolo/drivers/md/dm.h | 10 ---------- linux-2.6.9-current-paolo/include/asm-h8300/types.h | 3 --- linux-2.6.9-current-paolo/include/asm-i386/types.h | 5 ----- linux-2.6.9-current-paolo/include/asm-mips/types.h | 5 ----- linux-2.6.9-current-paolo/include/asm-ppc/types.h | 5 ----- linux-2.6.9-current-paolo/include/asm-s390/types.h | 5 ----- linux-2.6.9-current-paolo/include/asm-sh/types.h | 5 ----- linux-2.6.9-current-paolo/include/asm-x86_64/types.h | 3 --- linux-2.6.9-current-paolo/include/linux/types.h | 17 ++++++++++++++--- 10 files changed, 18 insertions(+), 44 deletions(-)
drivers/md/dm.h renamed from drivers/md/dm.h~fix-dm-warnings +0 -10
@@ -22,16 +22,6 @@ #define DMEMIT(x...) sz += ((sz >= maxlen) ? \ 0 : scnprintf(result + sz, maxlen - sz, x)) -/* -* FIXME: I think this should be with the definition of sector_t -* in types.h. -*/ -#ifdef CONFIG_LBD -#define SECTOR_FORMAT "%Lu" -#else -#define SECTOR_FORMAT "%lu" -#endif -#define SECTOR_SHIFT 9/*
include/asm-h8300/types.h renamed from include/asm-h8300/types.h~fix-dm-warnings +0 -3
@@ -55,9 +55,6 @@ typedef unsigned long long u64;typedef u32 dma_addr_t ; -#define HAVE_SECTOR_T -typedef u64 sector_t ; -typedef unsigned int kmem_bufctl_t ;#endif /* __KERNEL__ */
include/asm-i386/types.h renamed from include/asm-i386/types.h~fix-dm-warnings +0 -5
@@ -58,11 +58,6 @@ typedef u32 dma_addr_t;#endif typedef u64 dma64_addr_t ; -#ifdef CONFIG_LBD -typedef u64 sector_t ; -#define HAVE_SECTOR_T -#endif -typedef unsigned short kmem_bufctl_t ;#endif /* __ASSEMBLY__ */
include/asm-mips/types.h renamed from include/asm-mips/types.h~fix-dm-warnings +0 -5
@@ -94,11 +94,6 @@ typedef unsigned long long phys_t;typedef unsigned long phys_t ;#endif -#ifdef CONFIG_LBD -typedef u64 sector_t ; -#define HAVE_SECTOR_T -#endif -typedef unsigned short kmem_bufctl_t ;#endif /* __ASSEMBLY__ */
include/asm-ppc/types.h renamed from include/asm-ppc/types.h~fix-dm-warnings +0 -5
@@ -57,11 +57,6 @@ typedef __vector128 vector128;typedef u32 dma_addr_t ;typedef u64 dma64_addr_t ; -#ifdef CONFIG_LBD -typedef u64 sector_t ; -#define HAVE_SECTOR_T -#endif -typedef unsigned int kmem_bufctl_t ;#endif /* __ASSEMBLY__ */
include/asm-s390/types.h renamed from include/asm-s390/types.h~fix-dm-warnings +0 -5
@@ -90,11 +90,6 @@ typedef union { } subreg; } register_pair; -#ifdef CONFIG_LBD -typedef u64 sector_t ; -#define HAVE_SECTOR_T -#endif -#endif /* ! __s390x__ */ #endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */
include/asm-sh/types.h renamed from include/asm-sh/types.h~fix-dm-warnings +0 -5
@@ -53,11 +53,6 @@ typedef unsigned long long u64;typedef u32 dma_addr_t ; -#ifdef CONFIG_LBD -typedef u64 sector_t ; -#define HAVE_SECTOR_T -#endif -typedef unsigned int kmem_bufctl_t ;#endif /* __ASSEMBLY__ */
include/asm-x86_64/types.h renamed from include/asm-x86_64/types.h~fix-dm-warnings +0 -3
@@ -48,9 +48,6 @@ typedef unsigned long long u64;typedef u64 dma64_addr_t ;typedef u64 dma_addr_t ; -typedef u64 sector_t ; -#define HAVE_SECTOR_T -typedef unsigned short kmem_bufctl_t ;#endif /* __ASSEMBLY__ */
include/linux/types.h renamed from include/linux/types.h~fix-dm-warnings +14 -3
@@ -125,12 +125,23 @@ typedef __s64 int64_t;/* * The type used for indexing onto a disc or disc partition. -* If required, asm/types.h can override it and define -* HAVE_SECTOR_T +* You cannot override it any more in asm- includes; define CONFIG_LBD +* to turn it inside a long long (only on 32-bit archs). +* The DM code must also scanf sector_t's, so here we define SECTOR_FORMAT +* for them. */ -#ifndef HAVE_SECTOR_T + +#ifndef CONFIG_LBD typedef unsigned long sector_t ; +#define SECTOR_FORMAT "%lu" +#else /* CONFIG_LBD */ +#if BITS_PER_LONG ==64 +#error Cannot define CONFIG_LBD on 64-bit archs. +#else +typedef unsigned long long sector_t ; +#define SECTOR_FORMAT "%llu"#endif +#endif /* CONFIG_LBD */ /* * The type of an index into the pagecache. Use a #define so asm/types.h
arch/h8300/Kconfig renamed from arch/h8300/Kconfig~fix-dm-warnings +4 -0
@@ -25,6 +25,10 @@ config UID16 bool default y +config LBD + bool + default y + config RWSEM_GENERIC_SPINLOCK bool default y
_