kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* how to properly use BUILD_BUG_ON_MSG ?
@ 2021-08-30 20:40 jim.cromie
  2021-08-30 21:17 ` jim.cromie
  0 siblings, 1 reply; 2+ messages in thread
From: jim.cromie @ 2021-08-30 20:40 UTC (permalink / raw)
  To: kernelnewbies

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, &param_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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: how to properly use BUILD_BUG_ON_MSG ?
  2021-08-30 20:40 how to properly use BUILD_BUG_ON_MSG ? jim.cromie
@ 2021-08-30 21:17 ` jim.cromie
  0 siblings, 0 replies; 2+ messages in thread
From: jim.cromie @ 2021-08-30 21:17 UTC (permalink / raw)
  To: kernelnewbies

trimming out the "noise", Im left with

>    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,
>       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>


So, following that advice, I added

--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -20,6 +20,9 @@ drm-y       :=        drm_aperture.o drm_auth.o drm_cache.o \
                drm_client_modeset.o drm_atomic_uapi.o drm_hdcp.o \
                drm_managed.o drm_vblank_work.o

+#ifdef CONFIG_DRM_USE_DYNAMIC_DEBUG
+ccflags-y += -DDYNAMIC_DEBUG_MODULE
+#endif
 drm-$(CONFIG_DRM_LEGACY) += drm_agpsupport.o drm_bufs.o drm_context.o
drm_dma.o \


that fixed the error, and makes the BUILD_BUG usage look good.

so I withdraw the question

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-30 21:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30 20:40 how to properly use BUILD_BUG_ON_MSG ? jim.cromie
2021-08-30 21:17 ` jim.cromie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).