Re: [PATCH] fs: O_* bit numbers uniqueness check

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

 



Roland Dreier wrote:
> 
>  > +	/* please add new bits here to ensure allocation uniqueness */
>  > +	BUG_ON(20 != hweight32(
>  > +		O_RDONLY	| O_WRONLY	| O_RDWR	|
> 
> I wonder if there's a way to make this BUILD_BUG_ON(), so the problem is
> caught at compile time (a change like adding an O_ flag is often compile
> tested only for obscure archs).  One could create a compile-time
> macro-ized version of hweight32() and use that, I guess, although I'm
> not sure it's worth the ugliness.

Not ugly at all:

#define hweight32(x) __builtin_popcount(x)

Checked GCC 3.4.3 / 4.1 / 4.4: It expands as a compile-time constant
if the argument is a compile-time constant, so can be used in
BUILD_BUG_ON() and even for array sizes etc.

If GCC's __builtin_popcount() isn't good enough for non-constant
values, the macro would be more involved:

#define hweight32(x) (__builtin_constant_p(x) ? __builtin_popcount(x) \
                      : hweight32_nonconstant(x))

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

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux