lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20110412141040.a5706346.akpm@linux-foundation.org>
Date:	Tue, 12 Apr 2011 14:10:40 -0700
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Randy Dunlap <rdunlap@...otime.net>
Cc:	Alexey Dobriyan <adobriyan@...il.com>,
	linux-kernel@...r.kernel.org, behlendorf1@...l.gov, oleg@...hat.com
Subject: Re: [PATCH] remove abs64()

On Tue, 12 Apr 2011 14:07:26 -0700
Randy Dunlap <rdunlap@...otime.net> wrote:

> > --- a/include/linux/kernel.h
> > +++ b/include/linux/kernel.h
> > @@ -143,28 +143,27 @@ extern int _cond_resched(void);
> >  
> >  #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
> >  
> > -/*
> > - * abs() handles unsigned and signed longs, ints, shorts and chars.  For all
> > - * input types abs() returns a signed long.
> > - * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
> > - * for those.
> > - */
> > -#define abs(x) ({						\
> > -		long ret;					\
> > -		if (sizeof(x) == sizeof(long)) {		\
> > -			long __x = (x);				\
> > -			ret = (__x < 0) ? -__x : __x;		\
> > -		} else {					\
> > -			int __x = (x);				\
> > -			ret = (__x < 0) ? -__x : __x;		\
> > -		}						\
> > -		ret;						\
> > -	})
> > -
> > -#define abs64(x) ({				\
> > -		s64 __x = (x);			\
> > -		(__x < 0) ? -__x : __x;		\
> > -	})
> > +#define abs(x)								\
> > +({									\
> > +	typeof(x) _x = (x);						\
> > +									\
> > +	__builtin_choose_expr(						\
> > +		__builtin_types_compatible_p(typeof(_x), signed char),	\
> > +		(unsigned char)({ _x < 0 ? -_x : _x; }),		\
> > +	__builtin_choose_expr(						\
> > +		__builtin_types_compatible_p(typeof(_x), short),	\
> > +		(unsigned short)({ _x < 0 ? -_x : _x; }),		\
> > +	__builtin_choose_expr(						\
> > +		__builtin_types_compatible_p(typeof(_x), int),		\
> > +		(unsigned int)({ _x < 0 ? -_x : _x; }),			\
> > +	__builtin_choose_expr(						\
> > +		__builtin_types_compatible_p(typeof(_x), long),		\
> > +		(unsigned long)({ _x < 0 ? -_x : _x; }),		\
> > +	__builtin_choose_expr(						\
> > +		__builtin_types_compatible_p(typeof(_x), long long),	\
> > +		(unsigned long long)({ _x < 0 ? -_x : _x; }),		\
> > +	_x)))));							\
> > +})
> 
> that is better?

I think so.

It's a bit concerning that it changes the return type of abs().
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ