Skip to contentSkip to conversation

rust: i2c: replace `kernel::c_str!` with C-Strings

PATCH Applied Tamir Duberstein 4 participants 7 messages Dec 22, 2025 – Jan 19

Subsystems (2)
lore
Share & tools
lore

Tamir Duberstein

author reviewer
#0 lore raw

cover rust: i2c: 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.

---
Tamir Duberstein (2):
rust: i2c: replace kernel::c_str! with C-Strings
samples: rust: i2c: replace kernel::c_str! with C-Strings

 rust/kernel/i2c.rs              | 8 ++++----
 samples/rust/rust_driver_i2c.rs | 7 +++----
 samples/rust/rust_i2c_client.rs | 7 +++----
 3 files changed, 10 insertions(+), 12 deletions(-)

---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cstr-i2c-fce258eb7e5d

Best regards,

Signature · 1 line
Tamir Duberstein <[email protected]>
author reviewer
#1 lore raw

PATCH 1/2 rust: i2c: replace `kernel::c_str!` with C-Strings

From: Tamir Duberstein <[email protected]>

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
 rust/kernel/i2c.rs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
rust/kernel/i2c.rs +4 -4
index 491e6cc25cf4..792a71b15463 100644
@@ -253,7 +253,7 @@ macro_rules! module_i2c_driver {
 /// # Example
 ///
 ///```
-/// # use kernel::{acpi, bindings, c_str, device::Core, i2c, of};
+/// # use kernel::{acpi, bindings, device::Core, i2c, of};
 ///
 /// struct MyDriver;
 ///
@@ -262,7 +262,7 @@ macro_rules! module_i2c_driver {
 ///     MODULE_ACPI_TABLE,
 ///     <MyDriver as i2c::Driver>::IdInfo,
 ///     [
-///         (acpi::DeviceId::new(c_str!("LNUXBEEF")), ())
+///         (acpi::DeviceId::new(c"LNUXBEEF"), ())
 ///     ]
 /// );
 ///
@@ -271,7 +271,7 @@ macro_rules! module_i2c_driver {
 ///     MODULE_I2C_TABLE,
 ///     <MyDriver as i2c::Driver>::IdInfo,
 ///     [
-///          (i2c::DeviceId::new(c_str!("rust_driver_i2c")), ())
+///          (i2c::DeviceId::new(c"rust_driver_i2c"), ())
 ///     ]
 /// );
 ///
@@ -280,7 +280,7 @@ macro_rules! module_i2c_driver {
 ///     MODULE_OF_TABLE,
 ///     <MyDriver as i2c::Driver>::IdInfo,
 ///     [
-///         (of::DeviceId::new(c_str!("test,device")), ())
+///         (of::DeviceId::new(c"test,device"), ())
 ///     ]
 /// );
 ///
Signature · 1 line
2.52.0
author reviewer
#2 lore raw

PATCH 2/2 samples: rust: i2c: replace `kernel::c_str!` with C-Strings

In reply to Tamir Duberstein

From: Tamir Duberstein <[email protected]>

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
 samples/rust/rust_driver_i2c.rs | 7 +++----
 samples/rust/rust_i2c_client.rs | 7 +++----
 2 files changed, 6 insertions(+), 8 deletions(-)
samples/rust/rust_driver_i2c.rs +3 -4
index ecefeca3e22f..6be79f9e9fb5 100644
@@ -4,7 +4,6 @@
 
 use kernel::{
     acpi,
-    c_str,
     device::Core,
     i2c,
     of,
@@ -17,21 +16,21 @@
     ACPI_TABLE,
     MODULE_ACPI_TABLE,
     <SampleDriver as i2c::Driver>::IdInfo,
-    [(acpi::DeviceId::new(c_str!("LNUXBEEF")), 0)]
+    [(acpi::DeviceId::new(c"LNUXBEEF"), 0)]
 }
 
 kernel::i2c_device_table! {
     I2C_TABLE,
     MODULE_I2C_TABLE,
     <SampleDriver as i2c::Driver>::IdInfo,
-    [(i2c::DeviceId::new(c_str!("rust_driver_i2c")), 0)]
+    [(i2c::DeviceId::new(c"rust_driver_i2c"), 0)]
 }
 
 kernel::of_device_table! {
     OF_TABLE,
     MODULE_OF_TABLE,
     <SampleDriver as i2c::Driver>::IdInfo,
-    [(of::DeviceId::new(c_str!("test,rust_driver_i2c")), 0)]
+    [(of::DeviceId::new(c"test,rust_driver_i2c"), 0)]
 }
 
 impl i2c::Driver for SampleDriver {
samples/rust/rust_i2c_client.rs +3 -4
index f67938396dce..8d2c12e535b0 100644
@@ -69,7 +69,6 @@
 
 use kernel::{
     acpi,
-    c_str,
     device,
     devres::Devres,
     i2c,
@@ -90,20 +89,20 @@ struct SampleDriver {
     OF_TABLE,
     MODULE_OF_TABLE,
     <SampleDriver as platform::Driver>::IdInfo,
-    [(of::DeviceId::new(c_str!("test,rust-device")), ())]
+    [(of::DeviceId::new(c"test,rust-device"), ())]
 );
 
 kernel::acpi_device_table!(
     ACPI_TABLE,
     MODULE_ACPI_TABLE,
     <SampleDriver as platform::Driver>::IdInfo,
-    [(acpi::DeviceId::new(c_str!("LNUXBEEF")), ())]
+    [(acpi::DeviceId::new(c"LNUXBEEF"), ())]
 );
 
 const SAMPLE_I2C_CLIENT_ADDR: u16 = 0x30;
 const SAMPLE_I2C_ADAPTER_INDEX: i32 = 0;
 const BOARD_INFO: i2c::I2cBoardInfo =
-    i2c::I2cBoardInfo::new(c_str!("rust_driver_i2c"), SAMPLE_I2C_CLIENT_ADDR);
+    i2c::I2cBoardInfo::new(c"rust_driver_i2c", SAMPLE_I2C_CLIENT_ADDR);
 
 impl platform::Driver for SampleDriver {
     type IdInfo = ();
Signature · 1 line
2.52.0
reviewer Reviewed-by on the v1 series
#3 lore raw
In reply to Tamir Duberstein
Quoted 17 lines · Tamir Duberstein

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
Tamir Duberstein (2):
rust: i2c: replace kernel::c_str! with C-Strings
samples: rust: i2c: replace kernel::c_str! with C-Strings

rust/kernel/i2c.rs              | 8 ++++----
samples/rust/rust_driver_i2c.rs | 7 +++----
samples/rust/rust_i2c_client.rs | 7 +++----
3 files changed, 10 insertions(+), 12 deletions(-)
Quoted 8 lines

---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cstr-i2c-fce258eb7e5d

Best regards,

Signature · 1 line
Tamir Duberstein <[email protected]>
Acked-by on the v1 series
#4 lore raw
In reply to Tamir Duberstein
Quoted 13 lines · Tamir Duberstein

C-String literals were added in Rust 1.77. Replace instances of kernel::c_str! with C-String literals where possible.

---
Tamir Duberstein (2):
rust: i2c: replace kernel::c_str! with C-Strings
samples: rust: i2c: replace kernel::c_str! with C-Strings

  rust/kernel/i2c.rs              | 8 ++++----
  samples/rust/rust_driver_i2c.rs | 7 +++----
  samples/rust/rust_i2c_client.rs | 7 +++----
  3 files changed, 10 insertions(+), 12 deletions(-)
Quoted 8 lines

---
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8
change-id: 20251222-cstr-i2c-fce258eb7e5d

Best regards,
--
Tamir Duberstein <[email protected]>

Since I don’t yet have a public kernel tree, I’d appreciate it if someone could pick this up through their tree.

Thanks
Igor