Commit 3b83f5d5 authored by Tamir Duberstein's avatar Tamir Duberstein Committed by Miguel Ojeda
Browse files

rust: replace `CStr` with `core::ffi::CStr`

`kernel::ffi::CStr` was introduced in commit d126d238 ("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.

Add `CStr` to `ffi` and the kernel prelude.

Link: https://github.com/Rust-for-Linux/linux/commit/faa3cbcca03d0dec8f8e43f1d8d5c0860d98a23f

 [0]
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
Acked-by: default avatarDanilo Krummrich <dakr@kernel.org>
Reviewed-by: default avatarBenno Lossin <lossin@kernel.org>
Signed-off-by: default avatarTamir Duberstein <tamird@gmail.com>
Link: https://patch.msgid.link/20251018-cstr-core-v18-16-9378a54385f8@gmail.com


[ Removed assert that would now depend on the Rust version. - Miguel ]
Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent c5cf01ba
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ pub(crate) fn debug_print(&self, prefix: &str, m: &SeqFile) {

mod strings {
    use core::str::from_utf8_unchecked;
    use kernel::str::CStr;
    use kernel::str::{CStr, CStrExt as _};

    extern "C" {
        static binder_command_strings: [*const u8; super::BC_COUNT];
+2 −0
Original line number Diff line number Diff line
@@ -46,3 +46,5 @@ macro_rules! alias {
}

pub use core::ffi::c_void;

pub use core::ffi::CStr;
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@

use crate::debugfs::file_ops::FileOps;
use crate::ffi::c_void;
use crate::str::CStr;
use crate::str::{CStr, CStrExt as _};
use crate::sync::Arc;
use core::marker::PhantomData;

+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@

#[cfg(CONFIG_PRINTK)]
use crate::c_str;
use crate::str::CStrExt as _;

pub mod property;

+3 −1
Original line number Diff line number Diff line
@@ -156,7 +156,9 @@ macro_rules! declare_drm_ioctls {
                        Some($cmd)
                    },
                    flags: $flags,
                    name: $crate::c_str!(::core::stringify!($cmd)).as_char_ptr(),
                    name: $crate::str::as_char_ptr_in_const_context(
                        $crate::c_str!(::core::stringify!($cmd)),
                    ),
                }
            ),*];
            ioctls
Loading