powerpc: Fix _ALIGN_* errors due to type difference.
PATCH 1/1 powerpc: Fix _ALIGN_* errors due to type difference.
This avoid errors like
unsigned int usize = 1 << 30;
int size = 1 << 30;
unsigned long addr = 64UL << 30 ;
value = _ALIGN_DOWN(addr, usize); -> 0
value = _ALIGN_DOWN(addr, size); -> 0x1000000000--- arch/powerpc/boot/page.h | 4 ++-- arch/powerpc/include/asm/page.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/boot/page.h +2 -2
@@ -22,8 +22,8 @@#define PAGE_MASK (~(PAGE_SIZE-1))/* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))/* align addr on a size boundary - adjust address up if needed */ #define _ALIGN (addr,size) _ALIGN_UP(addr,size)
arch/powerpc/include/asm/page.h +2 -2
@@ -240,8 +240,8 @@ extern long long virt_phys_offset;#endif /* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))/* align addr on a size boundary - adjust address up if needed */ #define _ALIGN (addr,size) _ALIGN_UP(addr,size)
Signature · 1 line
2.5.0
Michael Ellerman
reviewerQuoted 8 lines · Aneesh Kumar K.V
This avoid errors like
unsigned int usize = 1 << 30; int size = 1 << 30; unsigned long addr = 64UL << 30 ; value = _ALIGN_DOWN(addr, usize); -> 0 value = _ALIGN_DOWN(addr, size); -> 0x1000000000
Are you actually seeing that anywhere? I assume not.
Quoted 20 lines
arch/powerpc/boot/page.h +2
-2@@ -22,8 +22,8 @@#define PAGE_MASK (~(PAGE_SIZE-1))/* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))/* align addr on a size boundary - adjust address up if needed */ #define _ALIGN (addr,size) _ALIGN_UP(addr,size)arch/powerpc/include/asm/page.h +0
-0
arch/powerpc/include/asm/page.h extern long long virt_phys_offset; · line 244
Quoted 7 lines
arch/powerpc/include/asm/page.h +2
-2@@ -240,8 +240,8 @@ extern long long virt_phys_offset;#endif /* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))
It looks like ALIGN() in kernel.h already does this right, so can we just use that instead for _ALIGN_UP() at least.
cheers
Quoted 11 lines · Michael Ellerman
Quoted 8 lines · Aneesh Kumar K.V
This avoid errors like
unsigned int usize = 1 << 30; int size = 1 << 30; unsigned long addr = 64UL << 30 ; value = _ALIGN_DOWN(addr, usize); -> 0 value = _ALIGN_DOWN(addr, size); -> 0x1000000000Are you actually seeing that anywhere? I assume not.
I hit that in new development. So not in the current kernel.
Quoted 23 lines
Quoted 23 lines
arch/powerpc/boot/page.h +2
-2@@ -22,8 +22,8 @@#define PAGE_MASK (~(PAGE_SIZE-1))/* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))/* align addr on a size boundary - adjust address up if needed */ #define _ALIGN (addr,size) _ALIGN_UP(addr,size)arch/powerpc/include/asm/page.h +0
-0@@ -240,8 +240,8 @@ extern long long virt_phys_offset;#endif
Quoted 10 lines
arch/powerpc/include/asm/page.h extern long long virt_phys_offset; · line 244
Quoted 5 lines
arch/powerpc/include/asm/page.h +2
-2/* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))It looks like
ALIGN()inkernel.halready does this right, so can we just use that instead for_ALIGN_UP()at least.
But we still can't get rid of _ALIGN_UP, because that is used in other parts of the kernel and if you are suggesting use
#define _ALIGN_UP __ALIGN_KERNEL, IMHO that is unnecessary indirection for no real benefit.
-aneesh
Michael Ellerman
reviewerQuoted 9 lines · Aneesh Kumar K.V
Quoted 7 lines · Michael Ellerman
Quoted 6 lines · Aneesh Kumar K.V
This avoid errors like
unsigned int usize = 1 << 30; int size = 1 << 30; unsigned long addr = 64UL << 30 ;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
value = _ALIGN_DOWN(addr, usize); -> 0 value = _ALIGN_DOWN(addr, size); -> 0x1000000000Are you actually seeing that anywhere? I assume not.
I hit that in new development. So not in the current kernel.
OK.
Quoted 33 lines
Quoted 22 lines
Quoted 22 lines
arch/powerpc/boot/page.h +2
-2@@ -22,8 +22,8 @@#define PAGE_MASK (~(PAGE_SIZE-1))/* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))/* align addr on a size boundary - adjust address up if needed */ #define _ALIGN (addr,size) _ALIGN_UP(addr,size)arch/powerpc/include/asm/page.h +0
-0@@ -240,8 +240,8 @@ extern long long virt_phys_offset;#endif Quoted 10 lines
arch/powerpc/include/asm/page.h extern long long virt_phys_offset; · line 244
Quoted 5 lines
arch/powerpc/include/asm/page.h +2
-2/* align addr on a size boundary - adjust address up/down if needed */ -#define _ALIGN_UP (addr,size) (((addr)+((size)-1))&(~((size)-1))) -#define _ALIGN_DOWN (addr,size) ((addr)&(~((size)-1))) +#define _ALIGN_UP (addr, size) (((addr)+((size)-1))&(~((typeof(addr))(size)-1))) +#define _ALIGN_DOWN (addr, size) ((addr)&(~((typeof(addr))(size)-1)))It looks like
ALIGN()inkernel.halready does this right, so can we just use that instead for_ALIGN_UP()at least.
Quoted 5 lines
But we still can't get rid of
_ALIGN_UP, because that is used in other parts of the kernel and if you are suggesting use#define
_ALIGN_UP__ALIGN_KERNEL, IMHO that is unnecessary indirection for no real benefit.
Huh? The benefit is not having to define the same macro twice, that seems like a pretty clear win.
_ALIGN_UP is ALIGN, just with this bug unfixed.
In other words if _ALIGN_UP was already an alias for ALIGN then you would have not seen the bug (except in _ALIGN_DOWN()).
cheers