Re: [PATCH] bitfield: use BUILD_BUG_ON_ZERO()

From: kbuild test robot
Date: Fri Oct 12 2018 - 21:23:52 EST


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

Attachment: .config.gz
Description: application/gzip