mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 01:24:47 +01:00
samples: rust: debugfs: replace kernel::c_str! with C-Strings
C-String literals were added in Rust 1.77. Replace instances of `kernel::c_str!` with C-String literals where possible. Signed-off-by: Tamir Duberstein <tamird@gmail.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Link: https://patch.msgid.link/20251222-cstr-driver-core-v1-7-1142a177d0fd@gmail.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
parent
f47a8f595a
commit
652ff12476
2 changed files with 15 additions and 21 deletions
|
|
@ -34,7 +34,6 @@
|
|||
use core::str::FromStr;
|
||||
use kernel::{
|
||||
acpi,
|
||||
c_str,
|
||||
debugfs::{
|
||||
Dir,
|
||||
File, //
|
||||
|
|
@ -113,7 +112,7 @@ kernel::acpi_device_table!(
|
|||
ACPI_TABLE,
|
||||
MODULE_ACPI_TABLE,
|
||||
<RustDebugFs as platform::Driver>::IdInfo,
|
||||
[(acpi::DeviceId::new(c_str!("LNUXBEEF")), ())]
|
||||
[(acpi::DeviceId::new(c"LNUXBEEF"), ())]
|
||||
);
|
||||
|
||||
impl platform::Driver for RustDebugFs {
|
||||
|
|
@ -140,34 +139,34 @@ impl platform::Driver for RustDebugFs {
|
|||
|
||||
impl RustDebugFs {
|
||||
fn build_counter(dir: &Dir) -> impl PinInit<File<Atomic<usize>>> + '_ {
|
||||
dir.read_write_file(c_str!("counter"), Atomic::<usize>::new(0))
|
||||
dir.read_write_file(c"counter", Atomic::<usize>::new(0))
|
||||
}
|
||||
|
||||
fn build_inner(dir: &Dir) -> impl PinInit<File<Mutex<Inner>>> + '_ {
|
||||
dir.read_write_file(c_str!("pair"), new_mutex!(Inner { x: 3, y: 10 }))
|
||||
dir.read_write_file(c"pair", new_mutex!(Inner { x: 3, y: 10 }))
|
||||
}
|
||||
|
||||
fn new(pdev: &platform::Device<Core>) -> impl PinInit<Self, Error> + '_ {
|
||||
let debugfs = Dir::new(c_str!("sample_debugfs"));
|
||||
let debugfs = Dir::new(c"sample_debugfs");
|
||||
let dev = pdev.as_ref();
|
||||
|
||||
try_pin_init! {
|
||||
Self {
|
||||
_compatible <- debugfs.read_only_file(
|
||||
c_str!("compatible"),
|
||||
c"compatible",
|
||||
dev.fwnode()
|
||||
.ok_or(ENOENT)?
|
||||
.property_read::<CString>(c_str!("compatible"))
|
||||
.property_read::<CString>(c"compatible")
|
||||
.required_by(dev)?,
|
||||
),
|
||||
counter <- Self::build_counter(&debugfs),
|
||||
inner <- Self::build_inner(&debugfs),
|
||||
array_blob <- debugfs.read_write_binary_file(
|
||||
c_str!("array_blob"),
|
||||
c"array_blob",
|
||||
new_mutex!([0x62, 0x6c, 0x6f, 0x62]),
|
||||
),
|
||||
vector_blob <- debugfs.read_write_binary_file(
|
||||
c_str!("vector_blob"),
|
||||
c"vector_blob",
|
||||
new_mutex!(kernel::kvec!(0x42; SZ_4K)?),
|
||||
),
|
||||
_debugfs: debugfs,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
//! track them all.
|
||||
|
||||
use kernel::{
|
||||
c_str,
|
||||
debugfs::{
|
||||
Dir,
|
||||
Scope, //
|
||||
|
|
@ -89,7 +88,7 @@ fn create_file_write(
|
|||
};
|
||||
dir.read_write_file(&name, val);
|
||||
}
|
||||
dir.read_write_binary_file(c_str!("blob"), &dev_data.blob);
|
||||
dir.read_write_binary_file(c"blob", &dev_data.blob);
|
||||
},
|
||||
),
|
||||
GFP_KERNEL,
|
||||
|
|
@ -128,20 +127,16 @@ struct DeviceData {
|
|||
}
|
||||
|
||||
fn init_control(base_dir: &Dir, dyn_dirs: Dir) -> impl PinInit<Scope<ModuleData>> + '_ {
|
||||
base_dir.scope(
|
||||
ModuleData::init(dyn_dirs),
|
||||
c_str!("control"),
|
||||
|data, dir| {
|
||||
dir.write_only_callback_file(c_str!("create"), data, &create_file_write);
|
||||
dir.write_only_callback_file(c_str!("remove"), data, &remove_file_write);
|
||||
},
|
||||
)
|
||||
base_dir.scope(ModuleData::init(dyn_dirs), c"control", |data, dir| {
|
||||
dir.write_only_callback_file(c"create", data, &create_file_write);
|
||||
dir.write_only_callback_file(c"remove", data, &remove_file_write);
|
||||
})
|
||||
}
|
||||
|
||||
impl kernel::Module for RustScopedDebugFs {
|
||||
fn init(_module: &'static kernel::ThisModule) -> Result<Self> {
|
||||
let base_dir = Dir::new(c_str!("rust_scoped_debugfs"));
|
||||
let dyn_dirs = base_dir.subdir(c_str!("dynamic"));
|
||||
let base_dir = Dir::new(c"rust_scoped_debugfs");
|
||||
let dyn_dirs = base_dir.subdir(c"dynamic");
|
||||
Ok(Self {
|
||||
_data: KBox::pin_init(init_control(&base_dir, dyn_dirs), GFP_KERNEL)?,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue