Re: dyndbg: pr_fmt(fmt) with additional arguments?

From: Philipp Hahn

Date: Fri Mar 13 2026 - 08:56:35 EST


Hello,

Am Fri, Feb 27, 2026 at 12:33:18PM +0100 schrieb Philipp Hahn:
> I've been using the following in my modules to prefix all messages with
> the module and function name:
> #define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__

<https://docs.kernel.org/core-api/printk-basics.html> itself has the
following example:

> #define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__

This breaks pr_debug_ratelimited().

> This could be fixed easily by adding an additional '...' to
> `DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)` to slurp any
> additional argument which `pr_fmt` might add.
>
> Would this be okay or do I miss something?
>
> For testing I have recompiled current 7.0.0-rc1 for x86_64 with no
> compile failures.

Ping?

Philipp Hahn

> From 545173a75e3928ec000b1127bfc99439b7fa2f8b Mon Sep 17 00:00:00 2001
> Message-ID: <545173a75e3928ec000b1127bfc99439b7fa2f8b.1772186702.git.p.hahn@xxxxxx>
> From: Philipp Hahn <phahn-oss@xxxxxx>
> Date: Fri, 27 Feb 2026 10:53:04 +0100
> Subject: [PATCH] dyndbg: Ignore additional arguments from pr_fmt
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> Organization: FRITZ! Technology GmbH, Berlin, Germany
>
> pr_fmt can be used to add a common prefix to any output from a module:
> #define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
>
> But adding additional arguments breaks dynamic debug:
> > error: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" passed 4 arguments, but takes just 3
> > | pr_debug_ratelimited("%s", "Hello world!");
> > | ^
> > note: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" defined here
> > | #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
> > |
> > error: ‘DEFINE_DYNAMIC_DEBUG_METADATA_CLS’ undeclared (first use in this function)
> > | DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt)
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > note: in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_METADATA’
> > | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > note: in expansion of macro ‘pr_debug_ratelimited’
> > | pr_debug_ratelimited("%s", "Hello world!");
> > | ^~~~~~~~~~~~~~~~~~~~
>
> Add an additional ', ...' to DEFINE_DYNAMIC_DEBUG_METADATA_CLS to slurp
> any additional argument, which `pr_fmt` might add.
>
> Signed-off-by: Philipp Hahn <phahn-oss@xxxxxx>
> ---
> include/linux/dynamic_debug.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index 05743900a1169..0ac0df04bac00 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -167,7 +167,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
> dump_stack(); \
> }
>
> -#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
> +#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt, ...) \
> static struct _ddebug __aligned(8) \
> __section("__dyndbg") name = { \
> .modname = KBUILD_MODNAME, \
> --
> 2.43.0
>