Message ID | 20181012092104.2361-1-johannes@sipsolutions.net (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Johannes Berg |
Headers | show |
Series | bitfield: use BUILD_BUG_ON_ZERO() | expand |
Umm, I really should've tested this :-) As John points out, it can't possibly compile, e.g. because > +#define __BF_FIELD_CHECK(_mask, _reg, _val) \ > + BUILD_BUG_ON_ZERO(!__builtin_constant_p(_mask)) + \ this isn't actually a constant expression. This would be harmless, since e.g. > + BUILD_BUG_ON_ZERO((_mask) == 0) + \ this already forces _mask to be a constant, but > + BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ > + ~((_mask) >> __bf_shf(_mask)) & (_val) : 0) + \ we can't actually replicate this check. We could just remove this as well, at the expense of not getting any warnings if you write something like FIELD_PREP(0xf, 32); Realistically, FIELD_PREP() is the only one that makes sense in a pure constant context though, so we could just add __FIELD_PREP for that, *with* all the checks. I'll send out a patch in a second that has this and also adds __{u,le,be}{16,32,64}encode_bits(). johannes
Hi Johannes, I love your patch! Perhaps something to improve: [auto build test WARNING on linus/master] [also build test WARNING on v4.19-rc7 next-20181012] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Johannes-Berg/bitfield-use-BUILD_BUG_ON_ZERO/20181013-081047 config: x86_64-randconfig-s2-10130838 (attached as .config) compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026 reproduce: # save the attached .config to linux build tree make ARCH=x86_64 All warnings (new ones prefixed by >>): In file included from include/linux/kernel.h:15:0, from include/linux/list.h:9, from include/linux/resource_ext.h:17, from include/linux/acpi.h:26, from drivers/iio/chemical/bme680_core.c:11: drivers/iio/chemical/bme680_core.c: In function 'bme680_chip_config': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ >> drivers/iio/chemical/bme680_core.c:525:12: note: in expansion of macro 'FIELD_PREP' u8 osrs = FIELD_PREP(BME680_OSRS_HUMIDITY_MASK, ^~~~~~~~~~ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio/chemical/bme680_core.c:547:9: note: in expansion of macro 'FIELD_PREP' osrs = FIELD_PREP(BME680_OSRS_TEMP_MASK, data->oversampling_temp + 1) | ^~~~~~~~~~ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio/chemical/bme680_core.c:548:9: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(BME680_OSRS_PRESS_MASK, data->oversampling_press + 1); ^~~~~~~~~~ -- In file included from drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:33:0: drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c: In function 'st_lsm6dsx_set_fifo_mode': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/regmap.h:77:42: note: in definition of macro 'regmap_update_bits' regmap_update_bits_base(map, reg, mask, val, NULL, false, false) ^~~ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ >> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:166:6: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(ST_LSM6DSX_FIFO_MODE_MASK, ^~~~~~~~~~ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c: In function 'st_lsm6dsx_set_fifo_odr': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/regmap.h:77:42: note: in definition of macro 'regmap_update_bits' regmap_update_bits_base(map, reg, mask, val, NULL, false, false) ^~~ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:185:6: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(ST_LSM6DSX_FIFO_ODR_MASK, data)); ^~~~~~~~~~ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c: In function 'st_lsm6dsx_fifo_setup': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/regmap.h:77:42: note: in definition of macro 'regmap_update_bits' regmap_update_bits_base(map, reg, mask, val, NULL, false, false) ^~~ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:529:6: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(ST_LSM6DSX_REG_HLACTIVE_MASK, ^~~~~~~~~~ -- In file included from include/linux/kernel.h:15:0, from include/linux/list.h:9, from include/linux/resource_ext.h:17, from include/linux/acpi.h:26, from drivers/iio//chemical/bme680_core.c:11: drivers/iio//chemical/bme680_core.c: In function 'bme680_chip_config': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio//chemical/bme680_core.c:525:12: note: in expansion of macro 'FIELD_PREP' u8 osrs = FIELD_PREP(BME680_OSRS_HUMIDITY_MASK, ^~~~~~~~~~ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio//chemical/bme680_core.c:547:9: note: in expansion of macro 'FIELD_PREP' osrs = FIELD_PREP(BME680_OSRS_TEMP_MASK, data->oversampling_temp + 1) | ^~~~~~~~~~ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio//chemical/bme680_core.c:548:9: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(BME680_OSRS_PRESS_MASK, data->oversampling_press + 1); ^~~~~~~~~~ -- In file included from drivers/iio//imu/st_lsm6dsx/st_lsm6dsx_buffer.c:33:0: drivers/iio//imu/st_lsm6dsx/st_lsm6dsx_buffer.c: In function 'st_lsm6dsx_set_fifo_mode': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/regmap.h:77:42: note: in definition of macro 'regmap_update_bits' regmap_update_bits_base(map, reg, mask, val, NULL, false, false) ^~~ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio//imu/st_lsm6dsx/st_lsm6dsx_buffer.c:166:6: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(ST_LSM6DSX_FIFO_MODE_MASK, ^~~~~~~~~~ drivers/iio//imu/st_lsm6dsx/st_lsm6dsx_buffer.c: In function 'st_lsm6dsx_set_fifo_odr': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/regmap.h:77:42: note: in definition of macro 'regmap_update_bits' regmap_update_bits_base(map, reg, mask, val, NULL, false, false) ^~~ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio//imu/st_lsm6dsx/st_lsm6dsx_buffer.c:185:6: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(ST_LSM6DSX_FIFO_ODR_MASK, data)); ^~~~~~~~~~ drivers/iio//imu/st_lsm6dsx/st_lsm6dsx_buffer.c: In function 'st_lsm6dsx_fifo_setup': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/regmap.h:77:42: note: in definition of macro 'regmap_update_bits' regmap_update_bits_base(map, reg, mask, val, NULL, false, false) ^~~ >> include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^~~~~~~~~~~~~~~~~ >> include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^~~~~~~~~~~~~~~~ drivers/iio//imu/st_lsm6dsx/st_lsm6dsx_buffer.c:529:6: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(ST_LSM6DSX_REG_HLACTIVE_MASK, ^~~~~~~~~~ vim +/BUILD_BUG_ON_ZERO +57 include/linux/bitfield.h 53 54 #define __BF_FIELD_CHECK(_mask, _reg, _val) \ 55 BUILD_BUG_ON_ZERO(!__builtin_constant_p(_mask)) + \ 56 BUILD_BUG_ON_ZERO((_mask) == 0) + \ > 57 BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ 58 ~((_mask) >> __bf_shf(_mask)) & (_val) : 0) + \ 59 BUILD_BUG_ON_ZERO((_mask) > (typeof(_reg))~0ull) + \ 60 __BF_CHECK_POW2((_mask) + (1ULL << __bf_shf(_mask))) 61 62 /** 63 * FIELD_FIT() - check if value fits in the field 64 * @_mask: shifted mask defining the field's length and position 65 * @_val: value to test against the field 66 * 67 * Return: true if @_val can fit inside @_mask, false if @_val is too big. 68 */ 69 #define FIELD_FIT(_mask, _val) \ 70 (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ 71 !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask))) 72 73 /** 74 * FIELD_PREP() - prepare a bitfield element 75 * @_mask: shifted mask defining the field's length and position 76 * @_val: value to put in the field 77 * 78 * FIELD_PREP() masks and shifts up the value. The result should 79 * be combined with other fields of the bitfield using logical OR. 80 */ 81 #define FIELD_PREP(_mask, _val) \ > 82 (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ 83 (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask))) 84 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
Hi Johannes, I love your patch! Perhaps something to improve: [auto build test WARNING on linus/master] [also build test WARNING on v4.19-rc7 next-20181012] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Johannes-Berg/bitfield-use-BUILD_BUG_ON_ZERO/20181013-081047 config: i386-randconfig-x0-10130855 (attached as .config) compiler: gcc-5 (Debian 5.5.0-3) 5.4.1 20171010 reproduce: # save the attached .config to linux build tree make ARCH=i386 All warnings (new ones prefixed by >>): In file included from include/linux/kernel.h:15:0, from drivers/crypto/ccree/cc_driver.c:4: drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_type': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ >> drivers/crypto/ccree/cc_hw_queue_defs.h:226:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[5] |= FIELD_PREP(WORD5_DIN_ADDR_HIGH, ((u16)(addr >> 32))); ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:228:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[1] |= FIELD_PREP(WORD1_DIN_DMA_MODE, dma_mode) | ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:229:5: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(WORD1_DIN_SIZE, size) | ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:230:5: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(WORD1_NS_BIT, axi_sec); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_no_dma': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:244:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_sram': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:260:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size) | ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_const': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:276:4: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(WORD1_DIN_SIZE, size); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_dout_type': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:304:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[5] |= FIELD_PREP(WORD5_DOUT_ADDR_HIGH, ((u16)(addr >> 32))); ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:306:20: note: in expansion of macro 'FIELD_PREP' -- In file included from include/asm-generic/atomic-instrumented.h:16:0, from arch/x86/include/asm/atomic.h:265, from include/linux/atomic.h:7, from include/linux/crypto.h:20, from include/crypto/aead.h:16, from include/crypto/internal/aead.h:16, from drivers/crypto/ccree/cc_buffer_mgr.c:4: drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_type': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ >> drivers/crypto/ccree/cc_hw_queue_defs.h:226:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[5] |= FIELD_PREP(WORD5_DIN_ADDR_HIGH, ((u16)(addr >> 32))); ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:228:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[1] |= FIELD_PREP(WORD1_DIN_DMA_MODE, dma_mode) | ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:229:5: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(WORD1_DIN_SIZE, size) | ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:230:5: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(WORD1_NS_BIT, axi_sec); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_no_dma': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:244:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_sram': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:260:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size) | ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_din_const': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:276:4: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(WORD1_DIN_SIZE, size); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_dout_type': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:304:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[5] |= FIELD_PREP(WORD5_DOUT_ADDR_HIGH, ((u16)(addr >> 32))); ^ include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:306:20: note: in expansion of macro 'FIELD_PREP' -- include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:455:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_MODE, mode); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_cipher_config0': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:467:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_CONF0, mode); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_cipher_config1': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:479:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_CONF1, config); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_hw_crypto_key': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:493:4: note: in expansion of macro 'FIELD_PREP' FIELD_PREP(WORD4_CIPHER_CONF2, ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_bytes_swap': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:505:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[4] |= FIELD_PREP(WORD4_BYTES_SWAP, config); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_key_size': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:526:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[4] |= FIELD_PREP(WORD4_KEY_SIZE, size); ^ drivers/crypto/ccree/cc_hw_queue_defs.h: In function 'set_setup_mode': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_hw_queue_defs.h:560:20: note: in expansion of macro 'FIELD_PREP' pdesc->word[4] |= FIELD_PREP(WORD4_SETUP_OPERATION, mode); ^ drivers/crypto/ccree/cc_lli_defs.h: In function 'cc_lli_set_addr': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ >> drivers/crypto/ccree/cc_lli_defs.h:49:29: note: in expansion of macro 'FIELD_PREP' lli_p[LLI_WORD1_OFFSET] |= FIELD_PREP(LLI_HADDR_MASK, (addr >> 32)); ^ drivers/crypto/ccree/cc_lli_defs.h: In function 'cc_lli_set_size': include/linux/build_bug.h:29:45: error: bit-field '<anonymous>' width not an integer constant #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) ^ include/linux/bitfield.h:57:2: note: in expansion of macro 'BUILD_BUG_ON_ZERO' BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ ^ include/linux/bitfield.h:82:3: note: in expansion of macro '__BF_FIELD_CHECK' (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ ^ drivers/crypto/ccree/cc_lli_defs.h:56:29: note: in expansion of macro 'FIELD_PREP' lli_p[LLI_WORD1_OFFSET] |= FIELD_PREP(LLI_SIZE_MASK, size); ^ .. vim +/FIELD_PREP +226 drivers/crypto/ccree/cc_hw_queue_defs.h 4c3f9727 Gilad Ben-Yossef 2018-01-22 210 4c3f9727 Gilad Ben-Yossef 2018-01-22 211 /* 4c3f9727 Gilad Ben-Yossef 2018-01-22 212 * Set the DIN field of a HW descriptors 4c3f9727 Gilad Ben-Yossef 2018-01-22 213 * 4c3f9727 Gilad Ben-Yossef 2018-01-22 214 * @pdesc: pointer HW descriptor struct 4c3f9727 Gilad Ben-Yossef 2018-01-22 215 * @dma_mode: dmaMode The DMA mode: NO_DMA, SRAM, DLLI, MLLI, CONSTANT 4c3f9727 Gilad Ben-Yossef 2018-01-22 216 * @addr: dinAdr DIN address 4c3f9727 Gilad Ben-Yossef 2018-01-22 217 * @size: Data size in bytes 4c3f9727 Gilad Ben-Yossef 2018-01-22 218 * @axi_sec: AXI secure bit 4c3f9727 Gilad Ben-Yossef 2018-01-22 219 */ 4c3f9727 Gilad Ben-Yossef 2018-01-22 220 static inline void set_din_type(struct cc_hw_desc *pdesc, 4c3f9727 Gilad Ben-Yossef 2018-01-22 221 enum cc_dma_mode dma_mode, dma_addr_t addr, 4c3f9727 Gilad Ben-Yossef 2018-01-22 222 u32 size, enum cc_axi_sec axi_sec) 4c3f9727 Gilad Ben-Yossef 2018-01-22 223 { 4c3f9727 Gilad Ben-Yossef 2018-01-22 224 pdesc->word[0] = (u32)addr; 4c3f9727 Gilad Ben-Yossef 2018-01-22 225 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT 4c3f9727 Gilad Ben-Yossef 2018-01-22 @226 pdesc->word[5] |= FIELD_PREP(WORD5_DIN_ADDR_HIGH, ((u16)(addr >> 32))); 4c3f9727 Gilad Ben-Yossef 2018-01-22 227 #endif 4c3f9727 Gilad Ben-Yossef 2018-01-22 228 pdesc->word[1] |= FIELD_PREP(WORD1_DIN_DMA_MODE, dma_mode) | 4c3f9727 Gilad Ben-Yossef 2018-01-22 229 FIELD_PREP(WORD1_DIN_SIZE, size) | 4c3f9727 Gilad Ben-Yossef 2018-01-22 230 FIELD_PREP(WORD1_NS_BIT, axi_sec); 4c3f9727 Gilad Ben-Yossef 2018-01-22 231 } 4c3f9727 Gilad Ben-Yossef 2018-01-22 232 :::::: The code at line 226 was first introduced by commit :::::: 4c3f97276e156820a0433bf7b59a4df1100829ae crypto: ccree - introduce CryptoCell driver :::::: TO: Gilad Ben-Yossef <gilad@benyossef.com> :::::: CC: Herbert Xu <herbert@gondor.apana.org.au> --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 3f1ef4450a7c..1840dae6448a 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -49,19 +49,15 @@ #define __bf_shf(x) (__builtin_ffsll(x) - 1) -#define __BF_FIELD_CHECK(_mask, _reg, _val, _pfx) \ - ({ \ - BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \ - _pfx "mask is not constant"); \ - BUILD_BUG_ON_MSG((_mask) == 0, _pfx "mask is zero"); \ - BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \ - ~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \ - _pfx "value too large for the field"); \ - BUILD_BUG_ON_MSG((_mask) > (typeof(_reg))~0ull, \ - _pfx "type of reg too small for mask"); \ - __BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \ - (1ULL << __bf_shf(_mask))); \ - }) +#define __BF_CHECK_POW2(n) BUILD_BUG_ON_ZERO(((n) & ((n) - 1)) != 0) + +#define __BF_FIELD_CHECK(_mask, _reg, _val) \ + BUILD_BUG_ON_ZERO(!__builtin_constant_p(_mask)) + \ + BUILD_BUG_ON_ZERO((_mask) == 0) + \ + BUILD_BUG_ON_ZERO(__builtin_constant_p(_val) ? \ + ~((_mask) >> __bf_shf(_mask)) & (_val) : 0) + \ + BUILD_BUG_ON_ZERO((_mask) > (typeof(_reg))~0ull) + \ + __BF_CHECK_POW2((_mask) + (1ULL << __bf_shf(_mask))) /** * FIELD_FIT() - check if value fits in the field @@ -71,10 +67,8 @@ * Return: true if @_val can fit inside @_mask, false if @_val is too big. */ #define FIELD_FIT(_mask, _val) \ - ({ \ - __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \ - !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \ - }) + (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ + !((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask))) /** * FIELD_PREP() - prepare a bitfield element @@ -85,10 +79,8 @@ * be combined with other fields of the bitfield using logical OR. */ #define FIELD_PREP(_mask, _val) \ - ({ \ - __BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \ - ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \ - }) + (__BF_FIELD_CHECK(_mask, 0ULL, _val) + \ + (((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask))) /** * FIELD_GET() - extract a bitfield element @@ -99,10 +91,8 @@ * bitfield passed in as @_reg by masking and shifting it down. */ #define FIELD_GET(_mask, _reg) \ - ({ \ - __BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \ - (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \ - }) + (__BF_FIELD_CHECK(_mask, _reg, 0U) + \ + ((typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)))) extern void __compiletime_error("value doesn't fit into mask") __field_overflow(void);