Skip to contentSkip to conversation

rust: error: use pr_warn_once! in from_errno

PATCH In review alessioMaroni0 3 participants 3 messages Jul 11 Rust

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: error: use pr_warn_once! in from_errno

Replace crate::pr_warn! with crate::pr_warn_once! in Error::from_errno to prevent logging noise if an invalid errno is repeatedly passed. This resolves a pending TODO in the file.

---
 rust/kernel/error.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
rust/kernel/error.rs +1 -2
index a56ba6309..2d3e31aff 100644
@@ -123,8 +123,7 @@ pub fn from_errno(errno: crate::ffi::c_int) -> Error {
         if let Some(error) = Self::try_from_errno(errno) {
             error
         } else {
-            // TODO: Make it a `WARN_ONCE` once available.
-            crate::pr_warn!(
+            crate::pr_warn_once!(
                 "attempted to create `Error` with out of range `errno`: {}\n",
                 errno
             );
Signature · 1 line
2.55.0
#1 lore raw
Quoted 14 lines · On Sat, 11 Jul 2026 23:09:19 +0200 alessioMaroni0 <[email protected]>…

Replace crate::pr_warn! with crate::pr_warn_once! in Error::from_errno to prevent logging noise if an invalid errno is repeatedly passed. This resolves a pending TODO in the file.

---
 rust/kernel/error.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
rust/kernel/error.rs +0 -0
index a56ba6309..2d3e31aff 100644

rust/kernel/error.rs pub fn from_errno(errno: crate::ffi::c_int) -> Error { · line 128

Quoted 8 lines
rust/kernel/error.rs +1 -2
@@ -123,8 +123,7 @@ pub fn from_errno(errno: crate::ffi::c_int) -> Error {
         if let Some(error) = Self::try_from_errno(errno) {
             error
         } else {
-            // TODO: Make it a `WARN_ONCE` once available.
-            crate::pr_warn!(
+            crate::pr_warn_once!(
                 "attempted to create `Error` with out of range `errno`: {}\n",
                 errno

WARN_ONCE and pr_warn_once are not the same thing.

WARN_ONCE prints a full stack trace and register dump.

pr_warn_once is just sorta of printk.

I'll add warn_once macro after the patch to add bug macro [1] is merged.

[1] https://lore.kernel.org/rust-for-linux/[email protected]/

#2 lore raw
In reply to alessioMaroni0
Quoted 6 lines · On Sat, Jul 11, 2026 at 11:09 PM alessioMaroni0 <[email protected]>…

Replace crate::pr_warn! with crate::pr_warn_once! in Error::from_errno to prevent logging noise if an invalid errno is repeatedly passed. This resolves a pending TODO in the file.

Thanks for the patch!

There were already others:

https://lore.kernel.org/rust-for-linux/[email protected]/
https://lore.kernel.org/rust-for-linux/[email protected]/

Also, is the Signed-off-by name a "known identity"?

https://docs.kernel.org/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin

Cheers,
Miguel