public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: ojeda@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
	bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org,
	lossin@kernel.org, tmgross@umich.edu,
	rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2] rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option
Date: Thu, 8 Jan 2026 12:42:40 +0000	[thread overview]
Message-ID: <20260108124240.239a5338.gary@garyguo.net> (raw)
In-Reply-To: <20260108013350.2880613-1-fujita.tomonori@gmail.com>

On Thu,  8 Jan 2026 10:33:50 +0900
FUJITA Tomonori <fujita.tomonori@gmail.com> wrote:

> Make warn_on() support DEBUG_BUGVERBOSE_DETAILED option, which was
> introduced by the commit aec58b48517c ("bugs/core: Extend
> __WARN_FLAGS() with the 'cond_str' parameter").
> 
> When the option is enabled, WARN splats now show the evaluated
> warn_on() condition alongside the file path, e.g.:
> 
> ------------[ cut here ]------------
> WARNING: [val == 1] linux/samples/rust/rust_minimal.rs:27 at _RNvXCsk7t4azzUqHP_12rust_minimalNtB2_11RustMinimalNtCs8pcx3n4
> Modules linked in: rust_minimal(+)
> 
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
> v2:
> - make warn_flags! convert the passed file string to bytes
> v1: https://lore.kernel.org/rust-for-linux/20251204223405.454920-1-fujita.tomonori@gmail.com/
> 
>  rust/kernel/bug.rs | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/rust/kernel/bug.rs b/rust/kernel/bug.rs
> index 36aef43e5ebe..ed943960f851 100644
> --- a/rust/kernel/bug.rs
> +++ b/rust/kernel/bug.rs
> @@ -11,9 +11,9 @@
>  #[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
>  #[cfg(CONFIG_DEBUG_BUGVERBOSE)]
>  macro_rules! warn_flags {
> -    ($flags:expr) => {
> +    ($file:expr, $flags:expr) => {
>          const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
> -        const _FILE: &[u8] = file!().as_bytes();
> +        const _FILE: &[u8] = $file.as_bytes();
>          // Plus one for null-terminator.
>          static FILE: [u8; _FILE.len() + 1] = {
>              let mut bytes = [0; _FILE.len() + 1];
> @@ -50,7 +50,7 @@ macro_rules! warn_flags {
>  #[cfg(all(CONFIG_BUG, not(CONFIG_UML), not(CONFIG_LOONGARCH), not(CONFIG_ARM)))]
>  #[cfg(not(CONFIG_DEBUG_BUGVERBOSE))]
>  macro_rules! warn_flags {
> -    ($flags:expr) => {
> +    ($file:expr, $flags:expr) => {
>          const FLAGS: u32 = $crate::bindings::BUGFLAG_WARNING | $flags;
>  
>          // SAFETY:
> @@ -75,7 +75,7 @@ macro_rules! warn_flags {
>  #[doc(hidden)]
>  #[cfg(all(CONFIG_BUG, CONFIG_UML))]
>  macro_rules! warn_flags {
> -    ($flags:expr) => {
> +    ($file:expr, $flags:expr) => {
>          // SAFETY: It is always safe to call `warn_slowpath_fmt()`
>          // with a valid null-terminated string.
>          unsafe {
> @@ -93,7 +93,7 @@ macro_rules! warn_flags {
>  #[doc(hidden)]
>  #[cfg(all(CONFIG_BUG, any(CONFIG_LOONGARCH, CONFIG_ARM)))]
>  macro_rules! warn_flags {
> -    ($flags:expr) => {
> +    ($file:expr, $flags:expr) => {
>          // SAFETY: It is always safe to call `WARN_ON()`.
>          unsafe { $crate::bindings::WARN_ON(true) }
>      };
> @@ -103,7 +103,7 @@ macro_rules! warn_flags {
>  #[doc(hidden)]
>  #[cfg(not(CONFIG_BUG))]
>  macro_rules! warn_flags {
> -    ($flags:expr) => {};
> +    ($file:expr, $flags:expr) => {};
>  }
>  
>  #[doc(hidden)]
> @@ -116,10 +116,16 @@ pub const fn bugflag_taint(value: u32) -> u32 {
>  macro_rules! warn_on {
>      ($cond:expr) => {{
>          let cond = $cond;
> +
> +        #[cfg(CONFIG_DEBUG_BUGVERBOSE_DETAILED)]
> +        const _COND_STR: &str = concat!("[", stringify!($cond), "] ", file!());
> +        #[cfg(not(CONFIG_DEBUG_BUGVERBOSE_DETAILED))]
> +        const _COND_STR: &str = file!();
> +
>          if cond {
>              const WARN_ON_FLAGS: u32 = $crate::bug::bugflag_taint($crate::bindings::TAINT_WARN);
>  
> -            $crate::warn_flags!(WARN_ON_FLAGS);
> +            $crate::warn_flags!(_COND_STR, WARN_ON_FLAGS);
>          }
>          cond
>      }};
> 
> base-commit: 9ace4753a5202b02191d54e9fdf7f9e3d02b85eb


  reply	other threads:[~2026-01-08 12:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08  1:33 [PATCH v2] rust: bug: Support DEBUG_BUGVERBOSE_DETAILED option FUJITA Tomonori
2026-01-08 12:42 ` Gary Guo [this message]
2026-01-29 23:10   ` FUJITA Tomonori
2026-01-30  4:45     ` Miguel Ojeda
2026-01-30  4:45 ` Miguel Ojeda

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=20260108124240.239a5338.gary@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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