Thread (33 messages) 33 messages, 4 authors, 2025-07-05

Re: [PATCH v13 3/5] rust: replace `CStr` with `core::ffi::CStr`

From: "Benno Lossin" <lossin@kernel.org>
Date: 2025-07-04 13:00:40
Also in: dri-devel, linux-block, linux-clk, linux-devicetree, linux-kselftest, linux-pci, linux-pm, lkml, llvm, nouveau, rust-for-linux

On Tue Jul 1, 2025 at 6:49 PM CEST, Tamir Duberstein wrote:
`kernel::ffi::CStr` was introduced in commit d126d2380131 ("rust: str:
add `CStr` type") in November 2022 as an upstreaming of earlier work
that was done in May 2021[0]. That earlier work, having predated the
inclusion of `CStr` in `core`, largely duplicated the implementation of
`std::ffi::CStr`.

`std::ffi::CStr` was moved to `core::ffi::CStr` in Rust 1.64 in
September 2022. Hence replace `kernel::str::CStr` with `core::ffi::CStr`
to reduce our custom code footprint, and retain needed custom
functionality through an extension trait.

C-String literals were added in Rust 1.77, while our MSRV is 1.78. Thus
opportunistically replace instances of `kernel::c_str!` with C-String
literals where other code changes were already necessary or where
existing code triggered clippy lints; the rest will be done in a later
commit.

Link: https://github.com/Rust-for-Linux/linux/commit/faa3cbcca03d0dec8f8e43f1d8d5c0860d98a23f [0]
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Tamir Duberstein <redacted>
---
 drivers/gpu/drm/drm_panic_qr.rs |   2 +-
 rust/kernel/auxiliary.rs        |   4 +-
 rust/kernel/configfs.rs         |   4 +-
 rust/kernel/cpufreq.rs          |   2 +-
 rust/kernel/device.rs           |   4 +-
 rust/kernel/drm/device.rs       |   4 +-
 rust/kernel/error.rs            |   4 +-
 rust/kernel/firmware.rs         |  11 +-
 rust/kernel/kunit.rs            |   6 +-
 rust/kernel/miscdevice.rs       |   2 +-
 rust/kernel/net/phy.rs          |   2 +-
 rust/kernel/of.rs               |   2 +-
 rust/kernel/prelude.rs          |   5 +-
 rust/kernel/seq_file.rs         |   4 +-
 rust/kernel/str.rs              | 394 +++++++++++-----------------------------
 rust/kernel/sync/condvar.rs     |   2 +-
 rust/kernel/sync/lock.rs        |   2 +-
 rust/kernel/sync/lock/global.rs |   2 +-
 samples/rust/rust_configfs.rs   |   2 +-
 19 files changed, 140 insertions(+), 318 deletions(-)
Is it also possible to split this? First rename the existing functions
on our CStr to match upstream & then you don't need to do the rename &
removal of our CStr in the same patch?

---
Cheers,
Benno
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help