[PATCH v2 14/19] rust: platform: replace `kernel::c_str!` with C-Strings

Tamir Duberstein
2025-09-25T13:55:44Z

Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
rust/kernel/platform.rs | 6 +++---
samples/rust/rust_driver_faux.rs | 4 ++--
samples/rust/rust_driver_platform.rs | 30 ++++++++++++++----------------
3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 8f028c76f9fa..d1cc5cee1cf5 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -135,7 +135,7 @@ macro_rules! module_platform_driver {
/// # Examples
///
///```
-/// # use kernel::{acpi, bindings, c_str, device::Core, of, platform};
+/// # use kernel::{acpi, bindings, device::Core, of, platform};
///
/// struct MyDriver;
///
@@ -144,7 +144,7 @@ macro_rules! module_platform_driver {
/// MODULE_OF_TABLE,
/// <MyDriver as platform::Driver>::IdInfo,
/// [
-/// (of::DeviceId::new(c_str!("test,device")), ())
+/// (of::DeviceId::new(c"test,device"), ())
/// ]
/// );
///
@@ -153,7 +153,7 @@ macro_rules! module_platform_driver {
/// MODULE_ACPI_TABLE,
/// <MyDriver as platform::Driver>::IdInfo,
/// [
-/// (acpi::DeviceId::new(c_str!("LNUXBEEF")), ())
+/// (acpi::DeviceId::new(c"LNUXBEEF"), ())
/// ]
/// );
///
diff --git a/samples/rust/rust_driver_faux.rs b/samples/rust/rust_driver_faux.rs
index ecc9fd378cbd..23add3160693 100644
--- a/samples/rust/rust_driver_faux.rs
+++ b/samples/rust/rust_driver_faux.rs
@@ -2,7 +2,7 @@

//! Rust faux device sample.

-use kernel::{c_str, faux, prelude::*, Module};
+use kernel::{faux, prelude::*, Module};

module! {
type: SampleModule,
@@ -20,7 +20,7 @@ impl Module for SampleModule {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Initialising Rust Faux Device Sample\n");

- let reg = faux::Registration::new(c_str!("rust-faux-sample-device"), None)?;
+ let reg = faux::Registration::new(c"rust-faux-sample-device", None)?;

dev_info!(reg.as_ref(), "Hello from faux device!\n");

diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index ad08df0d73f0..b3fe45a43043 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -63,7 +63,7 @@
//!

use kernel::{
- acpi, c_str,
+ acpi,
device::{
self,
property::{FwNodeReferenceArgs, NArgs},
@@ -85,14 +85,14 @@ struct SampleDriver {
OF_TABLE,
MODULE_OF_TABLE,
<SampleDriver as platform::Driver>::IdInfo,
- [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
+ [(of::DeviceId::new(c"test,rust-device"), Info(42))]
);

kernel::acpi_device_table!(
ACPI_TABLE,
MODULE_ACPI_TABLE,
<SampleDriver as platform::Driver>::IdInfo,
- [(acpi::DeviceId::new(c_str!("LNUXBEEF")), Info(0))]
+ [(acpi::DeviceId::new(c"LNUXBEEF"), Info(0))]
);

impl platform::Driver for SampleDriver {
@@ -126,49 +126,47 @@ impl SampleDriver {
fn properties_parse(dev: &device::Device) -> Result {
let fwnode = dev.fwnode().ok_or(ENOENT)?;

- if let Ok(idx) =
- fwnode.property_match_string(c_str!("compatible"), c_str!("test,rust-device"))
- {
+ if let Ok(idx) = fwnode.property_match_string(c"compatible", c"test,rust-device") {
dev_info!(dev, "matched compatible string idx = {}\n", idx);
}

- let name = c_str!("compatible");
+ let name = c"compatible";
let prop = fwnode.property_read::<CString>(name).required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:?}'\n");

- let name = c_str!("test,bool-prop");
- let prop = fwnode.property_read_bool(c_str!("test,bool-prop"));
+ let name = c"test,bool-prop";
+ let prop = fwnode.property_read_bool(c"test,bool-prop");
dev_info!(dev, "'{name}'='{prop}'\n");

- if fwnode.property_present(c_str!("test,u32-prop")) {
+ if fwnode.property_present(c"test,u32-prop") {
dev_info!(dev, "'test,u32-prop' is present\n");
}

- let name = c_str!("test,u32-optional-prop");
+ let name = c"test,u32-optional-prop";
let prop = fwnode.property_read::<u32>(name).or(0x12);
dev_info!(dev, "'{name}'='{prop:#x}' (default = 0x12)\n");

// A missing required property will print an error. Discard the error to
// prevent properties_parse from failing in that case.
- let name = c_str!("test,u32-required-prop");
+ let name = c"test,u32-required-prop";
let _ = fwnode.property_read::<u32>(name).required_by(dev);

- let name = c_str!("test,u32-prop");
+ let name = c"test,u32-prop";
let prop: u32 = fwnode.property_read(name).required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:#x}'\n");

- let name = c_str!("test,i16-array");
+ let name = c"test,i16-array";
let prop: [i16; 4] = fwnode.property_read(name).required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:?}'\n");
let len = fwnode.property_count_elem::<u16>(name)?;
dev_info!(dev, "'{name}' length is {len}\n");

- let name = c_str!("test,i16-array");
+ let name = c"test,i16-array";
let prop: KVec<i16> = fwnode.property_read_array_vec(name, 4)?.required_by(dev)?;
dev_info!(dev, "'{name}'='{prop:?}' (KVec)\n");

for child in fwnode.children() {
- let name = c_str!("test,ref-arg");
+ let name = c"test,ref-arg";
let nargs = NArgs::N(2);
let prop: FwNodeReferenceArgs = child.property_get_reference_args(name, nargs, 0)?;
dev_info!(dev, "'{name}'='{prop:?}'\n");

--
2.51.0