Re: [PATCHv2 1/8] kernel: add common infrastructure for unaligned access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2008-04-11 at 19:09 +0100, Russell King wrote:
> On Thu, Apr 10, 2008 at 05:06:34PM -0700, Harvey Harrison wrote:
> > +#define __get_unaligned_cpu(ptr) ({			\
> > +	const void *__gu_p = (ptr);			\
> > +	typeof(*(ptr)) __val;				\
> > +	switch (sizeof(*(ptr))) {			\
> > +	case 1:						\
> > +		__val = *(const u8 *)__gu_p;		\
> > +		break;					\
> > +	case 2:						\
> > +		__val = __get_unaligned_cpu16(__gu_p);	\
> > +		break;					\
> > +	case 4:						\
> > +		__val = __get_unaligned_cpu32(__gu_p);	\
> > +		break;					\
> > +	case 8:						\
> > +		__val = __get_unaligned_cpu64(__gu_p);	\
> > +		break;					\
> > +	default:					\
> > +		BUILD_BUG_ON(1);			\
> > +		break;					\
> > +	};						\
> > +	__val; })
> 
> This won't work - on ARM we used to use this style, but it fails in
> some corner case, so we ended up switching to using GCC's
> __builtin_choose_expr() instead.
> 
> Such a corner case:
> 
> static unsigned long foo(const unsigned long *ptr)
> {
> 	return __get_unaligned_cpu(ptr);
> }
> 
> This results in '__val' being declared as const, and therefore the
> compiler errors out in the switch statement since the code tries to
> assign to a const '__val'.

OK, will respin the set, I think I have a better way of doing it anyway.

Not that it matters, but wouldn't that be a gcc bug, for it to preserve
const on __val, wouldn't that have to be:

const unsigned long * const ptr

Just curious.

Thanks.

Harvey


--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux