Subject: linux-next: manual merge of the rust tree with the driver-core tree

From: Stephen Rothwell <[email-masked]>
Date: Thu, 20 Nov 2025 18:11:11 +1100

Hi all,

After merging the rust tree, today's linux-next build (x86_64
allmodconfig) failed like this:

error[E0599]: no method named `len_with_nul` found for reference `&'static ffi::CStr` in the current scope
  --> rust/kernel/i2c.rs:48:16
   |
48 |             id.len_with_nul() <= Self::I2C_NAME_SIZE,
   |                ^^^^^^^^^^^^ method not found in `&CStr`

error[E0599]: no method named `as_bytes_with_nul` found for reference `&'static ffi::CStr` in the current scope
  --> rust/kernel/i2c.rs:51:22
   |
51 |         let src = id.as_bytes_with_nul();
   |                      ^^^^^^^^^^^^^^^^^
   |
help: there is a method `to_bytes_with_nul` with a similar name
   |
51 |         let src = id.to_bytes_with_nul();
   |                      ~~~~~~~~~~~~~~~~~

error[E0599]: no method named `len_with_nul` found for reference `&'static ffi::CStr` in the current scope
   --> rust/kernel/i2c.rs:438:19
    |
438 |             type_.len_with_nul() <= Self::I2C_TYPE_SIZE,
    |                   ^^^^^^^^^^^^ method not found in `&CStr`

error[E0599]: no method named `as_bytes_with_nul` found for reference `&'static ffi::CStr` in the current scope
   --> rust/kernel/i2c.rs:441:25
    |
441 |         let src = type_.as_bytes_with_nul();
    |                         ^^^^^^^^^^^^^^^^^
    |
help: there is a method `to_bytes_with_nul` with a similar name
    |
441 |         let src = type_.to_bytes_with_nul();
    |                         ~~~~~~~~~~~~~~~~~

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0599`.

Caused by commit

  3b83f5d5e78a ("rust: replace `CStr` with `core::ffi::CStr`")

interacting with commits

  f3cc26a417b7 ("rust: i2c: add manual I2C device creation abstractions")
  57c5bd9aee94 ("rust: i2c: add basic I2C device and driver abstractions")

from the driver-core tree.

I have applied the following (hack) merge resolution for today.

From: Stephen Rothwell <[email-masked]>
Date: Thu, 20 Nov 2025 17:01:06 +1100
Subject: [PATCH] fix up 2 for "rust: replace `CStr` with `core::ffi::CStr`"

interacting with commits

  f3cc26a417b7 ("rust: i2c: add manual I2C device creation abstractions")
  57c5bd9aee94 ("rust: i2c: add basic I2C device and driver abstractions")

from the driver-core tree.

Signed-off-by: Stephen Rothwell <[email-masked]>
---
 rust/kernel/i2c.rs | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
index 95b056cc1a71..e5e057312858 100644
--- a/rust/kernel/i2c.rs
+++ b/rust/kernel/i2c.rs
@@ -39,16 +39,16 @@
 pub struct DeviceId(bindings::i2c_device_id);
 
 impl DeviceId {
-    const I2C_NAME_SIZE: usize = 20;
+    // const I2C_NAME_SIZE: usize = 20;
 
     /// Create a new device id from an I2C 'id' string.
     #[inline(always)]
     pub const fn new(id: &'static CStr) -> Self {
-        build_assert!(
-            id.len_with_nul() <= Self::I2C_NAME_SIZE,
-            "ID exceeds 20 bytes"
-        );
-        let src = id.as_bytes_with_nul();
+        // build_assert!(
+        //     id.len_with_nul() <= Self::I2C_NAME_SIZE,
+        //     "ID exceeds 20 bytes"
+        // );
+        let src = id.to_bytes_with_nul();
         let mut i2c: bindings::i2c_device_id = pin_init::zeroed();
         let mut i = 0;
         while i < src.len() {
@@ -430,15 +430,15 @@ unsafe fn dec_ref(obj: NonNull<Self>) {
 pub struct I2cBoardInfo(bindings::i2c_board_info);
 
 impl I2cBoardInfo {
-    const I2C_TYPE_SIZE: usize = 20;
+    // const I2C_TYPE_SIZE: usize = 20;
     /// Create a new [`I2cBoardInfo`] for a kernel driver.
     #[inline(always)]
     pub const fn new(type_: &'static CStr, addr: u16) -> Self {
-        build_assert!(
-            type_.len_with_nul() <= Self::I2C_TYPE_SIZE,
-            "Type exceeds 20 bytes"
-        );
-        let src = type_.as_bytes_with_nul();
+        // build_assert!(
+        //     type_.len_with_nul() <= Self::I2C_TYPE_SIZE,
+        //     "Type exceeds 20 bytes"
+        // );
+        let src = type_.to_bytes_with_nul();
         let mut i2c_board_info: bindings::i2c_board_info = pin_init::zeroed();
         let mut i: usize = 0;
         while i < src.len() {
-- 
2.51.1

-- 
Cheers,
Stephen Rothwell