Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Al Viro
On Sun, Nov 26, 2006 at 02:20:10PM -0800, Linus Torvalds wrote: > So arguably, the result is _more_ like a normal C operation this way. > Type-wise, the "ALIGN()" macro acts like any other C operation (ie if you > feed it an "unsigned char", the end result is an "int" due to the normal C > type

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Linus Torvalds
On Sun, 26 Nov 2006, Roland Dreier wrote: > > > +#define ALIGN(x,a)__ALIGN_MASK(x,(typeof(x))(a)-1) > > +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) > > Fine by me, but it loses the extra (typeof(x)) cast that Al wanted to > make sure that the result of ALIGN() is

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Jörn Engel
On Sun, 26 November 2006 12:26:08 -0800, Roland Dreier wrote: > > > +#define ALIGN(x,a)__ALIGN_MASK(x,(typeof(x))(a)-1) > > +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) > > Fine by me, but it loses the extra (typeof(x)) cast that Al wanted to > make sure that the re

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Roland Dreier
> +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) > +#define __ALIGN_MASK(x,mask)(((x)+(mask))&~(mask)) Fine by me, but it loses the extra (typeof(x)) cast that Al wanted to make sure that the result of ALIGN() is not wider than x. - R. - To unsubscribe from this list: se

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Linus Torvalds
On Sun, 26 Nov 2006, Andrew Morton wrote: > > I'd be inclined to merge it for 2.6.19. Is everyone OK with it? I'd _much_ rather make it more readable while at it. Something like this instead, which has just _one_ "typeof" cast, and at least to me makes it a lot more obvious what is going on

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Roland Dreier
> I'd be inclined to merge it for 2.6.19. Is everyone OK with it? I'm OK with that -- your previous email made me thing you didn't want to, but I think the risks are rather low, and there's a least a chance that we'll fix some obscure regression. - To unsubscribe from this list: send the line "u

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Andrew Morton
On Sun, 26 Nov 2006 11:10:23 -0800 Roland Dreier <[EMAIL PROTECTED]> wrote: > Commit 4c8bd7ee ("Do not truncate to 'int' in ALIGN() macro.") was > merged to fix the case of code like the following: > > unsigned long addr; > unsigned int alignment; > addr = ALIGN(addr, alignment)

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Roland Dreier
> Changes this late in the piece rather hurt. Fair enough. This was a really close call to me but let's leave it for 2.6.19. I'll ask Linus to merge the patch below to fix amso1100. I'm a little worried that other such uses might be lurking in the tree but I guess no one has complained... > Y

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-26 Thread Roland Dreier
Commit 4c8bd7ee ("Do not truncate to 'int' in ALIGN() macro.") was merged to fix the case of code like the following: unsigned long addr; unsigned int alignment; addr = ALIGN(addr, alignment); The original ALIGN macro calculated a mask as ~(alignment - 1), and when alignme

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-25 Thread Al Viro
On Sat, Nov 25, 2006 at 05:17:08PM -0800, Roland Dreier wrote: > >(typeof(x))((x + a - 1) & ~(a - 1ULL)) > > Yes I was being stupid thinking I needed a temporary variable to use > typeof. But what does the cast to typeof(x) accomplish if we write > things the way you suggested above? It see

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-25 Thread Roland Dreier
> (typeof(x))((x + a - 1) & ~(a - 1ULL)) Yes I was being stupid thinking I needed a temporary variable to use typeof. But what does the cast to typeof(x) accomplish if we write things the way you suggested above? It seems that the right things is really just (((x) + (a) - 1) & ~((

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-25 Thread Al Viro
On Sat, Nov 25, 2006 at 03:05:00PM -0800, David Miller wrote: > From: Roland Dreier <[EMAIL PROTECTED]> > Date: Sat, 25 Nov 2006 14:56:22 -0800 > > > > Perhaps a better way to fix this is to use > > > typeof() like other similar macros do. > > > > I tried doing > > > > #define ALIGN(x,a)

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-25 Thread Andrew Morton
On Sat, 25 Nov 2006 15:09:38 -0800 Roland Dreier <[EMAIL PROTECTED]> wrote: > > But yes, given the array sizing case in the neighbour code, > > perhaps we can use your original patch for now. Feel free > > to push that to Linus. > > akpm is CC'ed on this thread. Andrew, are you going to pick

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-25 Thread Roland Dreier
> You would need to also cast the constants with typeof() to. Why? I'm not much of a C language lawyer, but I would have thought that in something like (x) + _a - 1 the "1" will be promoted to the type of the rest of the expression without any explicit cast. I tested the unsigned long

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-25 Thread David Miller
From: Roland Dreier <[EMAIL PROTECTED]> Date: Sat, 25 Nov 2006 14:56:22 -0800 > > Perhaps a better way to fix this is to use > > typeof() like other similar macros do. > > I tried doing > > #define ALIGN(x,a)\ > ({ \ >

Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

2006-11-25 Thread Roland Dreier
> Perhaps a better way to fix this is to use > typeof() like other similar macros do. I tried doing #define ALIGN(x,a) \ ({ \ typeof(x) _a = (a); \ ((x) + _a - 1) & ~(_a - 1);