Linux Modules
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: ojeda@kernel.org, "Petr Pavlu" <petr.pavlu@suse.com>,
	linux-modules@vger.kernel.org, gary@garyguo.net
Subject: Re: [PATCH RFC 10/11] rust: device: remove logging methods
Date: Sun, 11 Oct 2026 13:01:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-167237@kernel.org> (raw)
In-Reply-To: <20261011-rust-dyndbg-v1-10-832e4039b71f@weissschuh.net>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] rust: dev_dbg!: unconditional evaluation of formatting arguments
- [Low] rust: Device::printk missing #[inline] attribute
--

commit b813060ef1de2d7eca47689d919683f6792237c4
Author: Thomas Weißschuh <linux@weissschuh.net>
Subject: rust: device: remove logging methods

This commit removes the logging wrapper methods from the Device struct, moving
the logic into macros that directly call Device::printk. This change allows
the dynamic debug core to statically allocate descriptors at the macro
callsite.

> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> index 2291d85b6849e..2d49063f4f7c8 100644
> --- a/rust/kernel/device.rs
> +++ b/rust/kernel/device.rs

[ ... ]

> @@ -387,7 +305,7 @@ pub fn pr_dbg(&self, args: fmt::Arguments<'_>) {
>      /// Callers must ensure that `klevel` is null-terminated; in particular, one of the
>      /// `KERN_*`constants, for example, `KERN_CRIT`, `KERN_ALERT`, etc.
>      #[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))]
> -    unsafe fn printk(&self, klevel: &[u8], msg: fmt::Arguments<'_>) {
> +    pub unsafe fn printk(&self, klevel: &[u8], msg: fmt::Arguments<'_>) {

[Severity: Low]
Is it intentional to omit the #[inline] attribute on this function? According
to the Rust subsystem guidelines, small abstraction functions that forward to C
bindings should be annotated with #[inline] to ensure optimal inlining.

>          // SAFETY: `klevel` is null-terminated and one of the kernel constants. `self.as_raw`
>          // is valid because `self` is valid. The "%pA" format string expects a pointer to

[ ... ]

> @@ -948,5 +915,14 @@ macro_rules! dev_info {
>  /// ```
>  #[macro_export]
>  macro_rules! dev_dbg {
> -    ($($f:tt)*) => { $crate::dev_printk!(pr_dbg, $($f)*) }
> +    ($dev:expr, $($f:tt)*) => {
> +        match (&$dev, $crate::prelude::fmt!($($f)*)) {
> +            (dev, args) => {
> +                if cfg!(debug_assertions) {

[Severity: Medium]
Does this match block unconditionally evaluate the formatting arguments before
the debug_assertions check is performed?

Because the match scrutinee evaluates fmt!($($f)*) eagerly, any computationally
expensive operations or side effects in the arguments might be executed even in
release builds.

Could the if cfg!(debug_assertions) check wrap the entire match block instead
to ensure zero overhead when debugging is disabled?

> +                    // SAFETY: `klevel` is null-terminated, uses one of the kernel constants.
> +                    unsafe { $crate::dev_printk!($crate::bindings::KERN_DEBUG, dev, args) }
> +                }
> +            }
> +        }
> +    }
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261011-rust-dyndbg-v1-0-832e4039b71f@weissschuh.net?part=10

  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
2026-10-11 12:52 ` [PATCH RFC 10/11] rust: device: remove logging methods Thomas Weißschuh
2026-10-11 13:01   ` sashiko-bot [this message]
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-167237@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