Skip to contentSkip to conversation

rust: add missing newlines in printing calls

PATCH In review Mehmet Koseoglu 2 participants 6 messages Aug 28 – Sep 1

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover rust: add missing newlines in printing calls

This patch series adds missing trailing newlines (\n) in Rust pr_*! and dev_*! calls across sample drivers and documentation examples.

Missing newlines cause kernel log lines to not be properly terminated, leading to unexpected concatenation of consecutive log messages.

Mehmet Koseoglu (3):
rust: samples: add missing newlines in rust_print_main
dma-mapping: rust: samples: add missing newline in rust_dma
rust: io: register: add missing newline in doc example

 rust/kernel/io/register.rs      | 2 +-
 samples/rust/rust_dma.rs        | 2 +-
 samples/rust/rust_print_main.rs | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/3 rust: samples: add missing newlines in rust_print_main

Calls to pr_info! in arc_print are missing trailing newlines, which causes consecutive messages to not be properly line-terminated.

Add the missing \n to all four formatting strings.

Fixes f431c5c581fa ("samples: rust: print: Add sample code for Arc printing")
Fixes 47cb6bf7860c ("rust: use derive(CoercePointee) on rustc >= 1.84.0")
---
 samples/rust/rust_print_main.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
samples/rust/rust_print_main.rs +4 -4
index 682207c81fc2..01729e87d6b5 100644
@@ -23,10 +23,10 @@ fn arc_print() -> Result {
     let b = UniqueArc::new("hello, world", GFP_KERNEL)?;
 
     // Prints the value of data in `a`.
-    pr_info!("{}", a);
+    pr_info!("{}\n", a);
 
     // Uses ":?" to print debug fmt of `b`.
-    pr_info!("{:?}", b);
+    pr_info!("{:?}\n", b);
 
     let a: Arc<&str> = b.into();
     let c = a.clone();
@@ -42,7 +42,7 @@ fn arc_print() -> Result {
 
         use kernel::fmt::Display;
         fn arc_dyn_print(arc: &Arc<dyn Display>) {
-            pr_info!("Arc<dyn Display> says {arc}");
+            pr_info!("Arc<dyn Display> says {arc}\n");
         }
 
         let a_i32_display: Arc<dyn Display> = Arc::new(42i32, GFP_KERNEL)?;
@@ -53,7 +53,7 @@ fn arc_dyn_print(arc: &Arc<dyn Display>) {
     }
 
     // Pretty-prints the debug formatting with lower-case hexadecimal integers.
-    pr_info!("{:#x?}", a);
+    pr_info!("{:#x?}\n", a);
 
     Ok(())
 }
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v1 1/3] rust: samples: add missing newlines in rust_print_main

Quoted 3 lines · Mehmet Koseoglu
Fixes f431c5c581fa ("samples: rust: print: Add sample code for Arc printing")
Fixes 47cb6bf7860c ("rust: use derive(CoercePointee) on rustc >= 1.84.0")

Thanks!

These Fixes tags point to different set of stable releases, but we probably don't care about backporting this, so it is not a big deal (otherwise; we would have needed to split the patch).

Cheers,
Miguel

#3 lore raw

Re: [PATCH v1 1/3] rust: samples: add missing newlines in rust_print_main

In reply to Mehmet Koseoglu
Quoted 11 lines · Mehmet Koseoglu

Calls to pr_info! in arc_print are missing trailing newlines, which causes consecutive messages to not be properly line-terminated.

Add the missing \n to all four formatting strings.

Fixes f431c5c581fa ("samples: rust: print: Add sample code for Arc printing")
Fixes 47cb6bf7860c ("rust: use derive(CoercePointee) on rustc >= 1.84.0")

Applied (this one) to rust-fixes -- thanks!

[ Reworded to fix the description of the missing-newline behavior.
- Miguel ]

Cheers,
Miguel

#4 lore raw

PATCH 2/3 dma-mapping: rust: samples: add missing newline in rust_dma

In reply to Mehmet Koseoglu

The dev_info! call iterating over scatter-gather table entries in DmaSampleDriver::drop is missing a trailing newline, causing the printed message to not be properly line-terminated.

Add the missing \n to the format string.

Fixes 5444799d701c ("samples: rust: dma: add sample code for SGTable")
---
 samples/rust/rust_dma.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/rust/rust_dma.rs +1 -1
index bd60034ded23..aa454e4841a7 100644
@@ -125,7 +125,7 @@ fn drop(self: Pin<&mut Self>) {
         for (i, entry) in self.sgt.iter().enumerate() {
             dev_info!(
                 self.pdev,
-                "Entry[{}]: DMA address: {:#x}",
+                "Entry[{}]: DMA address: {:#x}\n",
                 i,
                 entry.dma_address(),
             );
Signature · 1 line
2.55.0
#5 lore raw

PATCH 3/3 rust: io: register: add missing newline in doc example

In reply to Mehmet Koseoglu

The pr_info! call in the register module documentation code example is missing a trailing newline.

Add the missing \n to the format string.

Fixes 20ba6a1dbcb9 ("rust: io: add `register!` macro")
---
 rust/kernel/io/register.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/io/register.rs +1 -1
index 03dfd2ff48c7..31e084a4aa9f 100644
@@ -71,7 +71,7 @@
 //!
 //! // Read from the register's defined offset (0x100).
 //! let boot0 = io.read(BOOT_0);
-//! pr_info!("chip revision: {}.{}", boot0.major_revision().get(), boot0.minor_revision().get());
+//! pr_info!("chip revision: {}.{}\n", boot0.major_revision().get(), boot0.minor_revision().get());
 //!
 //! // Update some fields and write the new value back.
 //! let new_boot0 = boot0
Signature · 1 line
2.55.0