[PATCH v11 3/5] rust: replace `CStr` with `core::ffi::CStr`
Tamir Duberstein
tamird at gmail.com
Mon Jun 2 10:49:16 UTC 2025
On Mon, Jun 2, 2025 at 4:46 AM Alice Ryhl <aliceryhl at google.com> wrote:
>
> On Fri, May 30, 2025 at 08:27:44AM -0400, 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]
> > Signed-off-by: Tamir Duberstein <tamird at gmail.com>
>
> > diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs
> > index 2494c96e105f..582ab648b14c 100644
> > --- a/rust/kernel/firmware.rs
> > +++ b/rust/kernel/firmware.rs
> > @@ -4,7 +4,14 @@
> > //!
> > //! C header: [`include/linux/firmware.h`](srctree/include/linux/firmware.h)
> >
> > -use crate::{bindings, device::Device, error::Error, error::Result, ffi, str::CStr};
> > +use crate::{
> > + bindings,
> > + device::Device,
> > + error::Error,
> > + error::Result,
> > + ffi,
> > + str::{CStr, CStrExt as _},
> > +};
>
> Did you not add CStrExt to the prelude?
I did, but I didn't add the prelude to all files I had to update. This
one, like others, doesn't import the prelude.
More information about the dri-devel
mailing list