[PATCH v3 0/9] rust: use `kernel::{fmt,prelude::fmt!}`

0 views
Skip to first unread message

Tamir Duberstein

unread,
Aug 13, 2025, 11:39:56 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
This is series 2a/5 of the migration to `core::ffi::CStr`[0].
20250704-core-cstr-pre...@gmail.com.

This series depends on the prior series[0] and is intended to go through
the rust tree to reduce the number of release cycles required to
complete the work.

Subsystem maintainers: I would appreciate your `Acked-by`s so that this
can be taken through Miguel's tree (where the other series must go).

[0] https://lore.kernel.org/all/20250704-core-cstr-pre...@gmail.com/

Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
Changes in v3:
- Add a patch to address new code in device.rs.
- Drop incorrectly applied Acked-by tags from Danilo.
- Link to v2: https://lore.kernel.org/r/20250719-core-cstr-fan...@gmail.com

Changes in v2:
- Rebase on rust-next.
- Drop pin-init patch, which is no longer needed.
- Link to v1: https://lore.kernel.org/r/20250709-core-cstr-fan...@gmail.com

---
Tamir Duberstein (9):
gpu: nova-core: use `kernel::{fmt,prelude::fmt!}`
rust: alloc: use `kernel::{fmt,prelude::fmt!}`
rust: block: use `kernel::{fmt,prelude::fmt!}`
rust: device: use `kernel::{fmt,prelude::fmt!}`
rust: file: use `kernel::{fmt,prelude::fmt!}`
rust: kunit: use `kernel::{fmt,prelude::fmt!}`
rust: seq_file: use `kernel::{fmt,prelude::fmt!}`
rust: sync: use `kernel::{fmt,prelude::fmt!}`
rust: device: use `kernel::{fmt,prelude::fmt!}`

drivers/block/rnull.rs | 2 +-
drivers/gpu/nova-core/gpu.rs | 3 +--
drivers/gpu/nova-core/regs/macros.rs | 6 +++---
rust/kernel/alloc/kbox.rs | 2 +-
rust/kernel/alloc/kvec.rs | 2 +-
rust/kernel/alloc/kvec/errors.rs | 2 +-
rust/kernel/block/mq.rs | 2 +-
rust/kernel/block/mq/gen_disk.rs | 2 +-
rust/kernel/block/mq/raw_writer.rs | 3 +--
rust/kernel/device.rs | 6 +++---
rust/kernel/device/property.rs | 23 ++++++++++++-----------
rust/kernel/fs/file.rs | 5 +++--
rust/kernel/kunit.rs | 8 ++++----
rust/kernel/seq_file.rs | 6 +++---
rust/kernel/sync/arc.rs | 2 +-
scripts/rustdoc_test_gen.rs | 2 +-
16 files changed, 38 insertions(+), 38 deletions(-)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250709-core-cstr-fanout-1-f20611832272

Best regards,
--
Tamir Duberstein <tam...@gmail.com>

Tamir Duberstein

unread,
Aug 13, 2025, 11:39:58 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Acked-by: Danilo Krummrich <da...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
drivers/gpu/nova-core/gpu.rs | 3 +--
drivers/gpu/nova-core/regs/macros.rs | 6 +++---
2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index b5c9786619a9..600cc90b5fab 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0

-use kernel::{device, devres::Devres, error::code::*, pci, prelude::*, sync::Arc};
+use kernel::{device, devres::Devres, error::code::*, fmt, pci, prelude::*, sync::Arc};

use crate::driver::Bar0;
use crate::falcon::{gsp::Gsp, sec2::Sec2, Falcon};
@@ -12,7 +12,6 @@
use crate::regs;
use crate::util;
use crate::vbios::Vbios;
-use core::fmt;

macro_rules! define_chipset {
({ $($variant:ident = $value:expr),* $(,)* }) =>
diff --git a/drivers/gpu/nova-core/regs/macros.rs b/drivers/gpu/nova-core/regs/macros.rs
index a3e6de1779d4..6b9df4205f46 100644
--- a/drivers/gpu/nova-core/regs/macros.rs
+++ b/drivers/gpu/nova-core/regs/macros.rs
@@ -149,10 +149,10 @@ impl $name {

// TODO[REGA]: display the raw hex value, then the value of all the fields. This requires
// matching the fields, which will complexify the syntax considerably...
- impl ::core::fmt::Debug for $name {
- fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
+ impl ::kernel::fmt::Debug for $name {
+ fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kernel::fmt::Result {
f.debug_tuple(stringify!($name))
- .field(&format_args!("0x{0:x}", &self.0))
+ .field(&::kernel::prelude::fmt!("0x{0:x}", &self.0))
.finish()
}
}

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:39:59 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Acked-by: Danilo Krummrich <da...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
rust/kernel/alloc/kbox.rs | 2 +-
rust/kernel/alloc/kvec.rs | 2 +-
rust/kernel/alloc/kvec/errors.rs | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs
index 856d05aa60f1..563187d09a8e 100644
--- a/rust/kernel/alloc/kbox.rs
+++ b/rust/kernel/alloc/kbox.rs
@@ -7,7 +7,6 @@
use super::{AllocError, Allocator, Flags};
use core::alloc::Layout;
use core::borrow::{Borrow, BorrowMut};
-use core::fmt;
use core::marker::PhantomData;
use core::mem::ManuallyDrop;
use core::mem::MaybeUninit;
@@ -17,6 +16,7 @@
use core::result::Result;

use crate::ffi::c_void;
+use crate::fmt;
use crate::init::InPlaceInit;
use crate::types::ForeignOwnable;
use pin_init::{InPlaceWrite, Init, PinInit, ZeroableOption};
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index 3c72e0bdddb8..4a1b2c26209a 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -7,9 +7,9 @@
layout::ArrayLayout,
AllocError, Allocator, Box, Flags,
};
+use crate::fmt;
use core::{
borrow::{Borrow, BorrowMut},
- fmt,
marker::PhantomData,
mem::{ManuallyDrop, MaybeUninit},
ops::Deref,
diff --git a/rust/kernel/alloc/kvec/errors.rs b/rust/kernel/alloc/kvec/errors.rs
index 348b8d27e102..21a920a4b09b 100644
--- a/rust/kernel/alloc/kvec/errors.rs
+++ b/rust/kernel/alloc/kvec/errors.rs
@@ -2,7 +2,7 @@

//! Errors for the [`Vec`] type.

-use core::fmt::{self, Debug, Formatter};
+use kernel::fmt::{self, Debug, Formatter};
use kernel::prelude::*;

/// Error type for [`Vec::push_within_capacity`].

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:40:01 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Suggested-by: Alice Ryhl <alic...@google.com>
Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Custom.20formatting/with/516476467
Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
Acked-by: Andreas Hindborg <a.hin...@kernel.org>
---
drivers/block/rnull.rs | 2 +-
rust/kernel/block/mq.rs | 2 +-
rust/kernel/block/mq/gen_disk.rs | 2 +-
rust/kernel/block/mq/raw_writer.rs | 3 +--
4 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/block/rnull.rs b/drivers/block/rnull.rs
index d07e76ae2c13..6366da12c5a5 100644
--- a/drivers/block/rnull.rs
+++ b/drivers/block/rnull.rs
@@ -51,7 +51,7 @@ fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
.logical_block_size(4096)?
.physical_block_size(4096)?
.rotational(false)
- .build(format_args!("rnullb{}", 0), tagset)
+ .build(fmt!("rnullb{}", 0), tagset)
})();

try_pin_init!(Self {
diff --git a/rust/kernel/block/mq.rs b/rust/kernel/block/mq.rs
index 831445d37181..61ea35bba7d5 100644
--- a/rust/kernel/block/mq.rs
+++ b/rust/kernel/block/mq.rs
@@ -82,7 +82,7 @@
//! Arc::pin_init(TagSet::new(1, 256, 1), flags::GFP_KERNEL)?;
//! let mut disk = gen_disk::GenDiskBuilder::new()
//! .capacity_sectors(4096)
-//! .build(format_args!("myblk"), tagset)?;
+//! .build(fmt!("myblk"), tagset)?;
//!
//! # Ok::<(), kernel::error::Error>(())
//! ```
diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
index cd54cd64ea88..494c95623b97 100644
--- a/rust/kernel/block/mq/gen_disk.rs
+++ b/rust/kernel/block/mq/gen_disk.rs
@@ -6,9 +6,9 @@
//! C header: [`include/linux/blk_mq.h`](srctree/include/linux/blk_mq.h)

use crate::block::mq::{raw_writer::RawWriter, Operations, TagSet};
+use crate::fmt::{self, Write};
use crate::{bindings, error::from_err_ptr, error::Result, sync::Arc};
use crate::{error, static_lock_class};
-use core::fmt::{self, Write};

/// A builder for [`GenDisk`].
///
diff --git a/rust/kernel/block/mq/raw_writer.rs b/rust/kernel/block/mq/raw_writer.rs
index 7e2159e4f6a6..d311e24e2595 100644
--- a/rust/kernel/block/mq/raw_writer.rs
+++ b/rust/kernel/block/mq/raw_writer.rs
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0

-use core::fmt::{self, Write};
-
use crate::error::Result;
+use crate::fmt::{self, Write};
use crate::prelude::EINVAL;

/// A mutable reference to a byte buffer where a string can be written into.

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:40:04 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Acked-by: Danilo Krummrich <da...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
rust/kernel/device.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index b8613289de8e..65306e77d97d 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -5,10 +5,10 @@
//! C header: [`include/linux/device.h`](srctree/include/linux/device.h)

use crate::{
- bindings,
+ bindings, fmt,
types::{ARef, ForeignOwnable, Opaque},
};
-use core::{fmt, marker::PhantomData, ptr};
+use core::{marker::PhantomData, ptr};

#[cfg(CONFIG_PRINTK)]
use crate::c_str;
@@ -435,7 +435,7 @@ macro_rules! impl_device_context_into_aref {
macro_rules! dev_printk {
($method:ident, $dev:expr, $($f:tt)*) => {
{
- ($dev).$method(::core::format_args!($($f)*));
+ ($dev).$method($crate::prelude::fmt!($($f)*));
}
}
}

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:40:06 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
rust/kernel/fs/file.rs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs
index 35fd5db35c46..67a3654f0fd3 100644
--- a/rust/kernel/fs/file.rs
+++ b/rust/kernel/fs/file.rs
@@ -11,6 +11,7 @@
bindings,
cred::Credential,
error::{code::*, Error, Result},
+ fmt,
types::{ARef, AlwaysRefCounted, NotThreadSafe, Opaque},
};
use core::ptr;
@@ -460,8 +461,8 @@ fn from(_: BadFdError) -> Error {
}
}

-impl core::fmt::Debug for BadFdError {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+impl fmt::Debug for BadFdError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("EBADF")
}
}

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:40:07 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
rust/kernel/kunit.rs | 8 ++++----
scripts/rustdoc_test_gen.rs | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
index 41efd87595d6..cf58a204b222 100644
--- a/rust/kernel/kunit.rs
+++ b/rust/kernel/kunit.rs
@@ -6,8 +6,8 @@
//!
//! Reference: <https://docs.kernel.org/dev-tools/kunit/index.html>

+use crate::fmt;
use crate::prelude::*;
-use core::fmt;

#[cfg(CONFIG_PRINTK)]
use crate::c_str;
@@ -74,14 +74,14 @@ macro_rules! kunit_assert {
// mistake (it is hidden to prevent that).
//
// This mimics KUnit's failed assertion format.
- $crate::kunit::err(format_args!(
+ $crate::kunit::err($crate::prelude::fmt!(
" # {}: ASSERTION FAILED at {FILE}:{LINE}\n",
$name
));
- $crate::kunit::err(format_args!(
+ $crate::kunit::err($crate::prelude::fmt!(
" Expected {CONDITION} to be true, but is false\n"
));
- $crate::kunit::err(format_args!(
+ $crate::kunit::err($crate::prelude::fmt!(
" Failure not reported to KUnit since this is a non-KUnit task\n"
));
break 'out;
diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs
index abb34ada2508..c8f9dc2ab976 100644
--- a/scripts/rustdoc_test_gen.rs
+++ b/scripts/rustdoc_test_gen.rs
@@ -202,7 +202,7 @@ macro_rules! assert_eq {{
// This follows the syntax for declaring test metadata in the proposed KTAP v2 spec, which may
// be used for the proposed KUnit test attributes API. Thus hopefully this will make migration
// easier later on.
- ::kernel::kunit::info(format_args!(" # {kunit_name}.location: {real_path}:{line}\n"));
+ ::kernel::kunit::info(fmt!(" # {kunit_name}.location: {real_path}:{line}\n"));

/// The anchor where the test code body starts.
#[allow(unused)]

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:40:10 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
rust/kernel/seq_file.rs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/rust/kernel/seq_file.rs b/rust/kernel/seq_file.rs
index 8f199b1a3bb1..59fbfc2473f8 100644
--- a/rust/kernel/seq_file.rs
+++ b/rust/kernel/seq_file.rs
@@ -4,7 +4,7 @@
//!
//! C header: [`include/linux/seq_file.h`](srctree/include/linux/seq_file.h)

-use crate::{bindings, c_str, types::NotThreadSafe, types::Opaque};
+use crate::{bindings, c_str, fmt, types::NotThreadSafe, types::Opaque};

/// A utility for generating the contents of a seq file.
#[repr(transparent)]
@@ -31,7 +31,7 @@ pub unsafe fn from_raw<'a>(ptr: *mut bindings::seq_file) -> &'a SeqFile {

/// Used by the [`seq_print`] macro.
#[inline]
- pub fn call_printf(&self, args: core::fmt::Arguments<'_>) {
+ pub fn call_printf(&self, args: fmt::Arguments<'_>) {
// SAFETY: Passing a void pointer to `Arguments` is valid for `%pA`.
unsafe {
bindings::seq_printf(
@@ -47,7 +47,7 @@ pub fn call_printf(&self, args: core::fmt::Arguments<'_>) {
#[macro_export]
macro_rules! seq_print {
($m:expr, $($arg:tt)+) => (
- $m.call_printf(format_args!($($arg)+))
+ $m.call_printf($crate::prelude::fmt!($($arg)+))
);
}
pub use seq_print;

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:40:11 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Acked-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Alice Ryhl <alic...@google.com>
Reviewed-by: Benno Lossin <los...@kernel.org>
Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
rust/kernel/sync/arc.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
index 63a66761d0c7..4f3c1c2ff05e 100644
--- a/rust/kernel/sync/arc.rs
+++ b/rust/kernel/sync/arc.rs
@@ -20,6 +20,7 @@
alloc::{AllocError, Flags, KBox},
bindings,
ffi::c_void,
+ fmt,
init::InPlaceInit,
try_init,
types::{ForeignOwnable, Opaque},
@@ -27,7 +28,6 @@
use core::{
alloc::Layout,
borrow::{Borrow, BorrowMut},
- fmt,
marker::PhantomData,
mem::{ManuallyDrop, MaybeUninit},
ops::{Deref, DerefMut},

--
2.50.1

Tamir Duberstein

unread,
Aug 13, 2025, 11:40:13 AMAug 13
to Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org, Tamir Duberstein
Reduce coupling to implementation details of the formatting machinery by
avoiding direct use for `core`'s formatting traits and macros.

Signed-off-by: Tamir Duberstein <tam...@gmail.com>
---
rust/kernel/device/property.rs | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 49ee12a906db..3a332a8c53a9 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -11,6 +11,7 @@
alloc::KVec,
bindings,
error::{to_result, Result},
+ fmt,
prelude::*,
str::{CStr, CString},
types::{ARef, Opaque},
@@ -68,16 +69,16 @@ pub fn is_of_node(&self) -> bool {
unsafe { bindings::is_of_node(self.as_raw()) }
}

- /// Returns an object that implements [`Display`](core::fmt::Display) for
+ /// Returns an object that implements [`Display`](fmt::Display) for
/// printing the name of a node.
///
/// This is an alternative to the default `Display` implementation, which
/// prints the full path.
- pub fn display_name(&self) -> impl core::fmt::Display + '_ {
+ pub fn display_name(&self) -> impl fmt::Display + '_ {
struct FwNodeDisplayName<'a>(&'a FwNode);

- impl core::fmt::Display for FwNodeDisplayName<'_> {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ impl fmt::Display for FwNodeDisplayName<'_> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// SAFETY: `self` is valid by its type invariant.
let name = unsafe { bindings::fwnode_get_name(self.0.as_raw()) };
if name.is_null() {
@@ -87,7 +88,7 @@ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
// - `fwnode_get_name` returns null or a valid C string.
// - `name` was checked to be non-null.
let name = unsafe { CStr::from_char_ptr(name) };
- write!(f, "{name}")
+ fmt::Display::fmt(name, f)
}
}

@@ -351,8 +352,8 @@ pub fn is_empty(&self) -> bool {
}
}

-impl core::fmt::Debug for FwNodeReferenceArgs {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+impl fmt::Debug for FwNodeReferenceArgs {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.as_slice())
}
}
@@ -377,8 +378,8 @@ enum Node<'a> {
Owned(ARef<FwNode>),
}

-impl core::fmt::Display for FwNode {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+impl fmt::Display for FwNode {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// The logic here is the same as the one in lib/vsprintf.c
// (fwnode_full_name_string).

@@ -413,9 +414,9 @@ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
// SAFETY: `fwnode_get_name_prefix` returns null or a
// valid C string.
let prefix = unsafe { CStr::from_char_ptr(prefix) };
- write!(f, "{prefix}")?;
+ fmt::Display::fmt(prefix, f)?;
}
- write!(f, "{}", fwnode.display_name())?;
+ fmt::Display::fmt(&fwnode.display_name(), f)?;
}

Ok(())

--
2.50.1

Benno Lossin

unread,
Aug 14, 2025, 3:54:20 AMAug 14
to Tamir Duberstein, Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
On Wed Aug 13, 2025 at 5:39 PM CEST, Tamir Duberstein wrote:
> Reduce coupling to implementation details of the formatting machinery by
> avoiding direct use for `core`'s formatting traits and macros.
>
> Signed-off-by: Tamir Duberstein <tam...@gmail.com>

Reviewed-by: Benno Lossin <los...@kernel.org>

> ---
> rust/kernel/device/property.rs | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)

> @@ -413,9 +414,9 @@ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
> // SAFETY: `fwnode_get_name_prefix` returns null or a
> // valid C string.
> let prefix = unsafe { CStr::from_char_ptr(prefix) };
> - write!(f, "{prefix}")?;
> + fmt::Display::fmt(prefix, f)?;
> }
> - write!(f, "{}", fwnode.display_name())?;

So we're not able to use `write!` with our `Display` or did you also
write a `FmtAdapter` wrapper for that? (don't think we need it now, just
wanted to know if we have this issue possibly in the future)

---
Cheers,
Benno

Miguel Ojeda

unread,
Sep 16, 2025, 5:25:51 AM (8 days ago) Sep 16
to Tamir Duberstein, Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
On Wed, Aug 13, 2025 at 5:39 PM Tamir Duberstein <tam...@gmail.com> wrote:
>
> This is series 2a/5 of the migration to `core::ffi::CStr`[0].
> 20250704-core-cstr-pre...@gmail.com.
>
> This series depends on the prior series[0] and is intended to go through
> the rust tree to reduce the number of release cycles required to
> complete the work.
>
> Subsystem maintainers: I would appreciate your `Acked-by`s so that this
> can be taken through Miguel's tree (where the other series must go).
>
> [0] https://lore.kernel.org/all/20250704-core-cstr-pre...@gmail.com/
>
> Signed-off-by: Tamir Duberstein <tam...@gmail.com>

Applied to `rust-next` -- thanks everyone!

If any maintainer has a problem with this, please shout.

Cheers,
Miguel

Tamir Duberstein

unread,
Sep 23, 2025, 9:09:33 PM (11 hours ago) Sep 23
to Benno Lossin, Danilo Krummrich, David Airlie, Simona Vetter, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg, Alice Ryhl, Trevor Gross, Jens Axboe, Greg Kroah-Hartman, Rafael J. Wysocki, Brendan Higgins, David Gow, Rae Moar, Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Alexandre Courbot, Alexander Viro, Christian Brauner, Jan Kara, nou...@lists.freedesktop.org, dri-...@lists.freedesktop.org, linux-...@vger.kernel.org, rust-fo...@vger.kernel.org, linux...@vger.kernel.org, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-...@vger.kernel.org
Correct; we cannot use `write!` with our `Display`.

Apologies for the late reply - I had sent this back in August but was
still being throttled by gmail :(
Reply all
Reply to author
Forward
0 new messages