Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-07 Thread Rikard Falkeborn
On Tue, Aug 06, 2019 at 02:15:54PM -0700, Joe Perches wrote: > On Tue, 2019-08-06 at 21:27 +0200, Rikard Falkeborn wrote: > > On Wed, Aug 07, 2019 at 12:19:36AM +0900, Masahiro Yamada wrote: > > > How about this? > > > #define GENMASK_INPUT_CHECK(high, low) \ > > >

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-06 Thread Joe Perches
On Tue, 2019-08-06 at 21:27 +0200, Rikard Falkeborn wrote: > On Wed, Aug 07, 2019 at 12:19:36AM +0900, Masahiro Yamada wrote: > > How about this? > > #define GENMASK_INPUT_CHECK(high, low) \ > >BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ > > __builtin_constant_p((low) >

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-06 Thread Rikard Falkeborn
Hi Masahiro, On Wed, Aug 07, 2019 at 12:19:36AM +0900, Masahiro Yamada wrote: > Hi Rikard, > > > On Tue, Aug 6, 2019 at 4:55 AM Rikard Falkeborn > wrote: > > > > On Sun, Aug 04, 2019 at 03:45:16PM +0900, Masahiro Yamada wrote: > > > On Sun, Aug 4, 2019 at 3:36 AM Rikard Falkeborn > > > wrote:

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-06 Thread Masahiro Yamada
Hi Rikard, On Tue, Aug 6, 2019 at 4:55 AM Rikard Falkeborn wrote: > > On Sun, Aug 04, 2019 at 03:45:16PM +0900, Masahiro Yamada wrote: > > On Sun, Aug 4, 2019 at 3:36 AM Rikard Falkeborn > > wrote: > > > > > > On Sat, Aug 03, 2019 at 12:12:46PM +0900, Masahiro Yamada wrote: > > > > On Sat, Aug

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-05 Thread Rikard Falkeborn
On Sun, Aug 04, 2019 at 03:45:16PM +0900, Masahiro Yamada wrote: > On Sun, Aug 4, 2019 at 3:36 AM Rikard Falkeborn > wrote: > > > > On Sat, Aug 03, 2019 at 12:12:46PM +0900, Masahiro Yamada wrote: > > > On Sat, Aug 3, 2019 at 12:03 PM Masahiro Yamada > > > wrote: > > > > > > > > > > > BTW, v2 is

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-04 Thread Masahiro Yamada
On Sun, Aug 4, 2019 at 3:36 AM Rikard Falkeborn wrote: > > On Sat, Aug 03, 2019 at 12:12:46PM +0900, Masahiro Yamada wrote: > > On Sat, Aug 3, 2019 at 12:03 PM Masahiro Yamada > > wrote: > > > > > > > > BTW, v2 is already inconsistent. > > > If you wanted GENMASK_INPUT_CHECK() to return

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-03 Thread Rikard Falkeborn
On Sat, Aug 03, 2019 at 12:12:46PM +0900, Masahiro Yamada wrote: > On Sat, Aug 3, 2019 at 12:03 PM Masahiro Yamada > wrote: > > > > > BTW, v2 is already inconsistent. > > If you wanted GENMASK_INPUT_CHECK() to return 'unsigned long',, > > you would have to cast (low) > (high) as well: > > > >

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-02 Thread Masahiro Yamada
On Sat, Aug 3, 2019 at 12:03 PM Masahiro Yamada wrote: > > BTW, v2 is already inconsistent. > If you wanted GENMASK_INPUT_CHECK() to return 'unsigned long',, > you would have to cast (low) > (high) as well: > >(unsigned long)((low) > (high)), UL(0 > > This is totally

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-02 Thread Masahiro Yamada
On Sat, Aug 3, 2019 at 3:19 AM Rikard Falkeborn wrote: > > On Fri, Aug 02, 2019 at 12:25:06PM +0900, Masahiro Yamada wrote: > > On Fri, Aug 2, 2019 at 12:14 PM Joe Perches wrote: > > > > > > On Fri, 2019-08-02 at 10:40 +0900, Masahiro Yamada wrote: > > > > On Thu, Aug 1, 2019 at 4:27 AM Joe

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-02 Thread Rikard Falkeborn
On Fri, Aug 02, 2019 at 12:25:06PM +0900, Masahiro Yamada wrote: > On Fri, Aug 2, 2019 at 12:14 PM Joe Perches wrote: > > > > On Fri, 2019-08-02 at 10:40 +0900, Masahiro Yamada wrote: > > > On Thu, Aug 1, 2019 at 4:27 AM Joe Perches wrote: > > > > On Wed, 2019-07-31 at 21:03 +0200, Rikard

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-01 Thread Masahiro Yamada
On Fri, Aug 2, 2019 at 12:14 PM Joe Perches wrote: > > On Fri, 2019-08-02 at 10:40 +0900, Masahiro Yamada wrote: > > On Thu, Aug 1, 2019 at 4:27 AM Joe Perches wrote: > > > On Wed, 2019-07-31 at 21:03 +0200, Rikard Falkeborn wrote: > > > > GENMASK() and GENMASK_ULL() are supposed to be called

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-01 Thread Joe Perches
On Fri, 2019-08-02 at 10:40 +0900, Masahiro Yamada wrote: > On Thu, Aug 1, 2019 at 4:27 AM Joe Perches wrote: > > On Wed, 2019-07-31 at 21:03 +0200, Rikard Falkeborn wrote: > > > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > > > as the first argument and the low bit as

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-01 Thread Masahiro Yamada
On Thu, Aug 1, 2019 at 4:27 AM Joe Perches wrote: > > On Wed, 2019-07-31 at 21:03 +0200, Rikard Falkeborn wrote: > > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > > as the first argument and the low bit as the second argument. Mixing > > them will return a mask with

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-01 Thread Rikard Falkeborn
On Wed, Jul 31, 2019 at 07:57:48PM -0700, Joe Perches wrote: > On Thu, 2019-08-01 at 11:50 +0900, Masahiro Yamada wrote: > > On Thu, Aug 1, 2019 at 4:04 AM Rikard Falkeborn > > wrote: > > > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > > > as the first argument and the

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-08-01 Thread Rikard Falkeborn
On Wed, Jul 31, 2019 at 12:27:38PM -0700, Joe Perches wrote: > On Wed, 2019-07-31 at 21:03 +0200, Rikard Falkeborn wrote: > > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > > as the first argument and the low bit as the second argument. Mixing > > them will return a mask

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-07-31 Thread Joe Perches
On Thu, 2019-08-01 at 11:50 +0900, Masahiro Yamada wrote: > On Thu, Aug 1, 2019 at 4:04 AM Rikard Falkeborn > wrote: > > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > > as the first argument and the low bit as the second argument. Mixing > > them will return a mask

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-07-31 Thread Masahiro Yamada
On Thu, Aug 1, 2019 at 4:04 AM Rikard Falkeborn wrote: > > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > as the first argument and the low bit as the second argument. Mixing > them will return a mask with zero bits set. > > Recent commits show getting this wrong is not

Re: [PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-07-31 Thread Joe Perches
On Wed, 2019-07-31 at 21:03 +0200, Rikard Falkeborn wrote: > GENMASK() and GENMASK_ULL() are supposed to be called with the high bit > as the first argument and the low bit as the second argument. Mixing > them will return a mask with zero bits set. > > Recent commits show getting this wrong is

[PATCH] linux/bits.h: Add compile time sanity check of GENMASK inputs

2019-07-31 Thread Rikard Falkeborn
GENMASK() and GENMASK_ULL() are supposed to be called with the high bit as the first argument and the low bit as the second argument. Mixing them will return a mask with zero bits set. Recent commits show getting this wrong is not uncommon, see e.g. commit aa4c0c9091b0 ("net: stmmac: Fix misuses