Wire up dynamic debug to also work for the dev_dbg!() macro.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
 rust/kernel/device.rs | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index 2d49063f4f7c..db2c9adc5410 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -896,7 +896,7 @@ macro_rules! dev_info {
 ///
 /// This level should be used for debug messages.
 ///
-/// Equivalent to the kernel's `dev_dbg` macro, except that it doesn't support 
dynamic debug yet.
+/// Equivalent to the kernel's `dev_dbg` macro.
 ///
 /// Mimics the interface of [`std::print!`]. More information about the syntax 
is available from
 /// [`core::fmt`] and [`std::format!`].
@@ -918,6 +918,15 @@ macro_rules! dev_dbg {
     ($dev:expr, $($f:tt)*) => {
         match (&$dev, $crate::prelude::fmt!($($f)*)) {
             (dev, args) => {
+                // 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!($($f)*), 
|| {
+                    // SAFETY: `klevel` is null-terminated, uses one of the 
kernel constants.
+                    unsafe { $crate::dev_printk!($crate::bindings::KERN_DEBUG, 
dev, args) }
+                });
+
+                #[cfg(not(any(CONFIG_DYNAMIC_DEBUG,
+                          all(CONFIG_DYNAMIC_DEBUG_CORE, debug_assertions))))]
                 if cfg!(debug_assertions) {
                     // SAFETY: `klevel` is null-terminated, uses one of the 
kernel constants.
                     unsafe { $crate::dev_printk!($crate::bindings::KERN_DEBUG, 
dev, args) }

-- 
2.56.0


Reply via email to