Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rust: configfs: use `core::ffi::CStr` method names

Prepare for `core::ffi::CStr` taking the place of `kernel::str::CStr` by
avoid methods that only exist on the latter.

Also avoid `Deref<Target=BStr> for CStr` as that impl doesn't exist on
`core::ffi::CStr`.

Link: https://github.com/Rust-for-Linux/linux/issues/1075
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Acked-by: Andreas Hindborg <a.hindborg@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

authored by

Tamir Duberstein and committed by
Miguel Ojeda
a3a7d09a 7ad635c9

+3 -3
+2 -2
rust/kernel/configfs.rs
··· 263 263 try_pin_init!(Self { 264 264 group <- pin_init::init_zeroed().chain(|v: &mut Opaque<bindings::config_group>| { 265 265 let place = v.get(); 266 - let name = name.as_bytes_with_nul().as_ptr(); 266 + let name = name.to_bytes_with_nul().as_ptr(); 267 267 // SAFETY: It is safe to initialize a group once it has been zeroed. 268 268 unsafe { 269 269 bindings::config_group_init_type_name(place, name.cast(), item_type.as_ptr()) ··· 613 613 pub const fn new(name: &'static CStr) -> Self { 614 614 Self { 615 615 attribute: Opaque::new(bindings::configfs_attribute { 616 - ca_name: name.as_char_ptr(), 616 + ca_name: crate::str::as_char_ptr_in_const_context(name), 617 617 ca_owner: core::ptr::null_mut(), 618 618 ca_mode: 0o660, 619 619 show: Some(Self::show),
+1 -1
samples/rust/rust_configfs.rs
··· 94 94 95 95 fn show(container: &Configuration, page: &mut [u8; PAGE_SIZE]) -> Result<usize> { 96 96 pr_info!("Show message\n"); 97 - let data = container.message; 97 + let data = container.message.to_bytes(); 98 98 page[0..data.len()].copy_from_slice(data); 99 99 Ok(data.len()) 100 100 }