Skip to content

Commit a3a7d09

Browse files
tamirdojeda
authored andcommitted
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: #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>
1 parent 7ad635c commit a3a7d09

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

rust/kernel/configfs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<Data> Group<Data> {
263263
try_pin_init!(Self {
264264
group <- pin_init::init_zeroed().chain(|v: &mut Opaque<bindings::config_group>| {
265265
let place = v.get();
266-
let name = name.as_bytes_with_nul().as_ptr();
266+
let name = name.to_bytes_with_nul().as_ptr();
267267
// SAFETY: It is safe to initialize a group once it has been zeroed.
268268
unsafe {
269269
bindings::config_group_init_type_name(place, name.cast(), item_type.as_ptr())
@@ -613,7 +613,7 @@ where
613613
pub const fn new(name: &'static CStr) -> Self {
614614
Self {
615615
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),
617617
ca_owner: core::ptr::null_mut(),
618618
ca_mode: 0o660,
619619
show: Some(Self::show),

samples/rust/rust_configfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl configfs::AttributeOperations<0> for Configuration {
9494

9595
fn show(container: &Configuration, page: &mut [u8; PAGE_SIZE]) -> Result<usize> {
9696
pr_info!("Show message\n");
97-
let data = container.message;
97+
let data = container.message.to_bytes();
9898
page[0..data.len()].copy_from_slice(data);
9999
Ok(data.len())
100100
}

0 commit comments

Comments
 (0)