macro arg reuse warnings, howto fix ?

jim.cromie at gmail.com jim.cromie at gmail.com
Mon Feb 28 13:20:59 EST 2022


so, in this patchset :
https://patchwork.freedesktop.org/series/100289/

I get a macro warning I cannot solve with the usual local/auto
variable declaration
(the 2nd line in this macro)

#define DEFINE_DYNAMIC_DEBUG_CLASSBITS(_fsname, _var, _flgs, desc, ...) \
    __typeof__ (_fsname) fsname = _fsname; \
   MODULE_PARM_DESC(fsname, desc); \
   static struct dyndbg_classbits_param ddcats_##_var = { \
        .bits = &(_var), \
        .flags = _flgs, \
        .classes = { __VA_ARGS__, _DPRINTK_SITE_UNCLASSED } \
   }; \
   module_param_cb(fsname, &param_ops_dyndbg_classbits, \
                                  &ddcats_##_var, 0644)


without that 2nd line, patchwork's checker gives me this:

-:164: CHECK:MACRO_ARG_REUSE: Macro argument reuse 'fsname' - possible
side-effects?
#164: FILE: include/linux/dynamic_debug.h:291:
+#define DEFINE_DYNAMIC_DEBUG_CLASSBITS(fsname, _var, _flgs, desc, ...) \
+ MODULE_PARM_DESC(fsname, desc); \
+ static struct dyndbg_classbits_param ddcats_##_var = { \
+ .bits = &(_var), \
+ .flags = _flgs, \
+ .classes = { __VA_ARGS__, _DPRINTK_SITE_UNCLASSED } \
+ }; \
+ module_param_cb(fsname, &param_ops_dyndbg_classbits, \
+ &ddcats_##_var, 0644)

with it I get compile err - suggesting this was a terrible guess at a fix.

                 from
/home/jimc/projects/lx/wk-next/drivers/gpu/drm/drm_print.c:28:
/home/jimc/projects/lx/wk-next/drivers/gpu/drm/drm_print.c:57:32:
error: ‘debug’ undeclared here (not in a function); did you mean
‘_ddebug’?
   57 | DEFINE_DYNAMIC_DEBUG_CLASSBITS(debug, __drm_debug, "p",
      |                                ^~~~~
/home/jimc/projects/lx/wk-next/include/linux/dynamic_debug.h:283:21:
note: in definition of macro ‘DEFINE_DYNAMIC_DEBUG_CLASSBITS’
  283 |         __typeof__ (_fsname) fsname = _fsname;
         \
      |                     ^~~~~~~
make[3]: *** [/home/jimc/projects/lx/wk-next/scripts/Makefile.build:288:
drivers/gpu/drm/drm_print.o]




that patchset has another case, similarly confusing:

#define __dynamic_func_call_cls(id, cls, fmt, func, ...) do { \
     DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt); \
     if (DYNAMIC_DEBUG_BRANCH(id)) \
          func(&id, ##__VA_ARGS__); \
     } while (0)

that macro is a simple extension of an existing macro,
which also would suffer this warning.

if I insert this at line 2:

__typeof__ (id) __id = (id); \

I get this:

      |                 ^~~~~~~~
/home/jimc/projects/lx/linux.git/include/linux/dynamic_debug.h:230:25:
note: previous definition of ‘__id’ with type ‘int’
  230 |         __typeof__ (id) __id = (id);                            \
      |                         ^~~~
/home/jimc/projects/lx/linux.git/include/linux/dynamic_debug.h:260:9:
note: in expansion of macro ‘__dynamic_func_call_cls’
  260 |         __dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt,
func, ##__VA_ARGS__)
      |         ^~~~~~~~~~~~~~~~~~~~~~~


one side thinks its an int, other side sees a struct _ddebug * pointer


any hints on how to fix these so patchset it submittable ?


thanks
jimc



More information about the Kernelnewbies mailing list