From: sashiko-bot@kernel.org
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: linux-modules@vger.kernel.org, gary@garyguo.net,
"Petr Pavlu" <petr.pavlu@suse.com>,
ojeda@kernel.org
Subject: Re: [PATCH RFC 09/11] rust: print: enable dynamic debug for pr_debug!()
Date: Sun, 11 Oct 2026 13:01:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-167238@kernel.org> (raw)
In-Reply-To: <20261011-rust-dyndbg-v1-9-832e4039b71f@weissschuh.net>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] rust: print: pr_debug() expands to multiple statements without a block
- [High] rust: print: pr_debug() argument evaluation inside closure breaks control flow
- [Medium] rust: dynamic_debug: __format_string() rejects macro-generated format strings
--
commit 0f009656f0da58d6ed039063d8a722503a6cbfbf
Author: Thomas Weißschuh <linux@weissschuh.net>
rust: print: enable dynamic debug for pr_debug!()
This commit wires up dynamic debug support for the pr_debug!() macro.
> diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
> index 9ce52b9fa69f0..9a0870c2df940 100644
> --- a/rust/kernel/print.rs
> +++ b/rust/kernel/print.rs
[ ... ]
> @@ -392,6 +391,13 @@ macro_rules! pr_info (
> #[doc(alias = "print")]
> macro_rules! pr_debug (
> ($($arg:tt)*) => (
[Severity: High]
Does this expansion cause syntax errors when pr_debug!() is used in an
expression context?
The pr_debug!() macro is documented to mimic std::print!(), which evaluates to
() and can be used in expression positions like match arms or tail expressions.
Because this macro expands using ( ... ) instead of a { ... } block, it
exposes multiple #[cfg(...)] gated items and a trailing semicolon directly to
the call site's AST.
If a driver calls let _ = pr_debug!(...);, won't the Rust parser fail
expecting a single expression, returning an error about ignoring the semicolon
and following tokens?
> + // TODO: Switch to cfg_select!() when that is usable.
> + #[cfg(any(CONFIG_DYNAMIC_DEBUG, all(CONFIG_DYNAMIC_DEBUG_CORE, debug_assertions)))]
> + $crate::dynamic_func_call!($crate::__format_string!($($arg)+), || {
[Severity: Medium]
Will this break if the format string is generated by another macro?
The user-provided arguments are passed to __format_string!():
rust/kernel/dynamic_debug.rs:
macro_rules! __format_string {
($fmt:literal) => {
$fmt
};
...
Because __format_string!() strictly expects a literal token, if a driver
calls pr_debug!(concat!("a", "b")), won't it fail to match the literal pattern
and cause a compile error? Standard Rust formatting macros typically allow
macro-generated format strings.
[Severity: High]
Can evaluating the arguments inside this closure silently break control flow?
The user-provided arguments $($arg)* are expanded inside the || { ... }
closure.
If a caller uses a control-flow operator in their arguments, such as
pr_debug!("Result: {}", do_something()?);, won't the ? operator attempt to
return from the closure instead of the caller's function?
This would either cause a type mismatch error because the closure returns (),
or silently return from the print closure while the outer function continues
executing unexpectedly.
> + $crate::print_macro!($crate::print::format_strings::DEBUG, false, $($arg)*)
> + });
> +
> + #[cfg(not(any(CONFIG_DYNAMIC_DEBUG, all(CONFIG_DYNAMIC_DEBUG_CORE, debug_assertions))))]
> if cfg!(debug_assertions) {
> $crate::print_macro!($crate::print::format_strings::DEBUG, false, $($arg)*)
> }
> )
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261011-rust-dyndbg-v1-0-832e4039b71f@weissschuh.net?part=9
next prev parent reply other threads:[~2026-10-11 13:01 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 12:52 [PATCH RFC 00/11] rust: add support for dynamic debug Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 01/11] rust: print: use CStr for __LOG_PREFIX Thomas Weißschuh
2026-10-11 13:01 ` Gary Guo
2026-10-11 14:43 ` Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 02/11] rust: sync: atomic: Add Atomic<u{8,16}> Thomas Weißschuh
2026-10-11 13:00 ` sashiko-bot
2026-10-11 13:04 ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 03/11] rust: num: Add Bounded::USABLE_BITS Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 04/11] samples: rust_print: add debug messages Thomas Weißschuh
2026-10-11 13:53 ` Miguel Ojeda
2026-10-11 14:48 ` Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 05/11] dyndbg: use u32 for struct _ddebug bitfields Thomas Weißschuh
2026-10-11 12:52 ` [PATCH RFC 06/11] dyndbg: make _ddebug::flags its own field Thomas Weißschuh
2026-10-11 13:23 ` Gary Guo
2026-10-11 14:47 ` Thomas Weißschuh
2026-10-11 15:44 ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 07/11] dyndbg: use READ_ONCE()/WRITE_ONCE() to access descriptor flags Thomas Weißschuh
2026-10-11 13:16 ` Gary Guo
2026-10-11 12:52 ` [PATCH RFC 08/11] rust: add support for dynamic debug Thomas Weißschuh
2026-10-11 13:08 ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 09/11] rust: print: enable dynamic debug for pr_debug!() Thomas Weißschuh
2026-10-11 13:01 ` sashiko-bot [this message]
2026-10-11 12:52 ` [PATCH RFC 10/11] rust: device: remove logging methods Thomas Weißschuh
2026-10-11 13:01 ` sashiko-bot
2026-10-11 12:52 ` [PATCH RFC 11/11] rust: device: enable dynamic debug for dev_dbg!() Thomas Weißschuh
2026-10-11 13:01 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-167238@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-modules@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=ojeda@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox