Re: [PATCH] linux/bits.h: fix unsigned less than zero warnings
From: Joe Perches
Date: Thu Jun 04 2020 - 12:49:57 EST
On Thu, 2020-06-04 at 09:41 +0300, Andy Shevchenko wrote:
> I think there is still a possibility to improve (as I mentioned there
> are test cases that are absent right now).
> What if we will have unsigned long value 0x100000001? Would it be 1
> after casting?
>
> Maybe cast to (long) or (long long) more appropriate?
Another good mechanism would be to compile-time check the use
of constants in BITS and BITS_ULL and verify that:
range of BITS is:
>= 0 && < (BITS_PER_BYTE * sizeof(unsigned int))
range of BITS_ULL is:
>= 0 && < (BITS_PER_BYTE * sizeof(unsigned long long))
There would be duplication similar to the GENMASK_INPUT_CHECK
macros.