how to properly use BUILD_BUG_ON_MSG ?
jim.cromie at gmail.com
jim.cromie at gmail.com
Mon Aug 30 16:40:30 EDT 2021
so I got this macro which depends upon config choices to work,
Id like to have alt-config versions which throw some obvious error.
like this:
#elif (defined(CONFIG_DYNAMIC_DEBUG_CORE) && !defined(DYNAMIC_DEBUG_MODULE))
#define DEFINE_DYNAMIC_DEBUG_CATEGORIES(fsname, var, bitmap_desc, ...) \
BUILD_BUG_ON_MSG(1, "you need -DDYNAMIC_DEBUG_MODULE in compile")
#else
...
is that more or less the expected usage ?
the error messages seem less clear than Id like,
leading me to suspect poor usage, or a better way to do it.
/home/jimc/projects/lx/wk-next/include/linux/compiler_types.h:310:11:
error: expected identifier or ‘(’ before ‘while’
310 | } while (0)
| ^~~~~
/home/jimc/projects/lx/wk-next/include/linux/compiler_types.h:316:9:
note: in expansion of macro ‘__compiletime_assert’
316 | __compiletime_assert(condition, msg, prefix, suffix)
| ^~~~~~~~~~~~~~~~~~~~
/home/jimc/projects/lx/wk-next/include/linux/compiler_types.h:328:9:
note: in expansion of macro ‘_compiletime_assert’
328 | _compiletime_assert(condition, msg,
__compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
/home/jimc/projects/lx/wk-next/include/linux/build_bug.h:39:37: note:
in expansion of macro ‘compiletime_assert’
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
/home/jimc/projects/lx/wk-next/include/linux/dynamic_debug.h:283:9:
note: in expansion of macro ‘BUILD_BUG_ON_MSG’
283 | BUILD_BUG_ON_MSG(1, "you need -DDYNAMIC_DEBUG_MODULE
in compile")
| ^~~~~~~~~~~~~~~~
/home/jimc/projects/lx/wk-next/drivers/gpu/drm/drm_print.c:60:1: note:
in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_CATEGORIES’
60 | DEFINE_DYNAMIC_DEBUG_CATEGORIES(debug, __drm_debug,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#if defined(CONFIG_DYNAMIC_DEBUG) || \
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
/**
* DEFINE_DYNAMIC_DEBUG_CATEGORIES() - bitmap control of categorized prdbgs
* @fsname: parameter basename under /sys
* @var: C-identifier holding bitmap
* @_desc: string summarizing the controls provided
* @...: list of struct dyndbg_bitdesc initializations
*
* Intended for modules with substantial use of "categorized" prdbgs
* (those with some systematic prefix in the format string), this lets
* modules (using dyndbg) control those prdbg groups according to
* their prefixes, and map them to bits 0-N of a sysfs control point.
* The @bits... identifies the prefixes to be used by dyndbg to
* select and alter those categorized prdbgs, order defines bitpos.
*/
#define DEFINE_DYNAMIC_DEBUG_CATEGORIES(fsname, _var, _desc, ...) \
MODULE_PARM_DESC(fsname, _desc); \
static struct dyndbg_bitmap_param ddcats_##_var = \
{ .bits = &_var, .map = { __VA_ARGS__, { .prefix = NULL }}}; \
module_param_cb(fsname, ¶m_ops_dyndbg, &ddcats_##_var, 0644)
#define _DD_cat_(pfx) { .prefix = pfx, .help = "help for " pfx }
#define _DD_cat_help_(pfx) "\t " pfx "\t- help for " pfx "\n"
extern const struct kernel_param_ops param_ops_dyndbg;
#elif (defined(CONFIG_DYNAMIC_DEBUG_CORE) && !defined(DYNAMIC_DEBUG_MODULE))
#define DEFINE_DYNAMIC_DEBUG_CATEGORIES(fsname, var, bitmap_desc, ...) \
BUILD_BUG_ON_MSG(1, "you need -DDYNAMIC_DEBUG_MODULE in compile")
#else
#define DEFINE_DYNAMIC_DEBUG_CATEGORIES(fsname, var, bitmap_desc, ...) \
BUILD_BUG_ON_MSG(1, "DYNAMIC_DEBUG support required to use this macro: " #var)
#define _DD_cat_(pfx)
#define _DD_cat_help_(pfx)
#endif
#endif
More information about the Kernelnewbies
mailing list