• R
    kernel.h: add BUILD_BUG_ON_NOT_POWER_OF_2() · cc8ef6eb
    Roland Dreier 提交于
    Add BUILD_BUG_ON_NOT_POWER_OF_2()
    
    When code relies on a constant being a power of 2:
    
    	#define FOO	512	/* must be a power of 2 */
    
    it would be nice to be able to do:
    
    	BUILD_BUG_ON(!is_power_of_2(FOO));
    
    However applying an inline function does not result in a compile-time
    constant that can be used with BUILD_BUG_ON(), so trying that gives
    results in:
    
    	error: bit-field '<anonymous>' width not an integer constant
    
    As suggested by akpm, rather than monkeying around with is_power_of_2()
    and risking gcc warts about constant expressions, just create a macro
    BUILD_BUG_ON_NOT_POWER_OF_2() to encapsulate this common requirement.
    Signed-off-by: NRoland Dreier <rolandd@cisco.com>
    Cc: Bart Van Assche <bvanassche@acm.org>
    Cc: David Dillow <dave@thedillows.org>
    Cc: "Robert P. J. Day" <rpjday@crashcourse.ca>
    Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
    cc8ef6eb
kernel.h 23.8 KB