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

Stephen Rothwell posted 1 patch 1 week, 4 days ago
rust/kernel/i2c.rs | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
linux-next: manual merge of the rust tree with the driver-core tree
Posted by Stephen Rothwell 1 week, 4 days ago
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 <sfr@canb.auug.org.au>
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 <sfr@canb.auug.org.au>
---
 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
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Miguel Ojeda 1 week, 4 days ago
On Thu, Nov 20, 2025 at 8:11 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> I have applied the following (hack) merge resolution for today.

Thanks a lot Stephen for taking the time to do that instead of dropping it.

We should be able to do the same as Tamir did in commit 657403637f7d
("rust: acpi: use `core::ffi::CStr` method names"), i.e. move the
build assert below to then be able to use `len()` instead:

diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
index aea1b44d189b..f67c355c988e 100644
--- a/rust/kernel/i2c.rs
+++ b/rust/kernel/i2c.rs
@@ -43,11 +43,8 @@ impl DeviceId {
     /// 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();
+        let src = id.to_bytes_with_nul();
+        build_assert!(src.len() <= Self::I2C_NAME_SIZE, "ID exceeds 20 bytes");
         let mut i2c: bindings::i2c_device_id = pin_init::zeroed();
         let mut i = 0;
         while i < src.len() {
@@ -433,11 +430,8 @@ impl I2cBoardInfo {
     /// 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();
+        let src = type_.to_bytes_with_nul();
+        build_assert!(src.len() <= Self::I2C_TYPE_SIZE, "Type exceeds
20 bytes");
         let mut i2c_board_info: bindings::i2c_board_info = pin_init::zeroed();
         let mut i: usize = 0;
         while i < src.len() {

Igor/Tamir?

Cheers,
Miguel
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Tamir Duberstein 1 week, 4 days ago
On Thu, Nov 20, 2025 at 4:15 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Nov 20, 2025 at 8:11 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> >
> > I have applied the following (hack) merge resolution for today.
>
> Thanks a lot Stephen for taking the time to do that instead of dropping it.
>
> We should be able to do the same as Tamir did in commit 657403637f7d
> ("rust: acpi: use `core::ffi::CStr` method names"), i.e. move the
> build assert below to then be able to use `len()` instead:
>
> diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
> index aea1b44d189b..f67c355c988e 100644
> --- a/rust/kernel/i2c.rs
> +++ b/rust/kernel/i2c.rs
> @@ -43,11 +43,8 @@ impl DeviceId {
>      /// 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();
> +        let src = id.to_bytes_with_nul();
> +        build_assert!(src.len() <= Self::I2C_NAME_SIZE, "ID exceeds 20 bytes");
>          let mut i2c: bindings::i2c_device_id = pin_init::zeroed();
>          let mut i = 0;
>          while i < src.len() {
> @@ -433,11 +430,8 @@ impl I2cBoardInfo {
>      /// 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();
> +        let src = type_.to_bytes_with_nul();
> +        build_assert!(src.len() <= Self::I2C_TYPE_SIZE, "Type exceeds
> 20 bytes");
>          let mut i2c_board_info: bindings::i2c_board_info = pin_init::zeroed();
>          let mut i: usize = 0;
>          while i < src.len() {
>
> Igor/Tamir?

Yep, looks correct to me!
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Stephen Rothwell 1 week, 3 days ago
Hi all,

On Thu, 20 Nov 2025 06:27:13 -0500 Tamir Duberstein <tamird@gmail.com> wrote:
>
> On Thu, Nov 20, 2025 at 4:15 AM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
> >
> > On Thu, Nov 20, 2025 at 8:11 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:  
> > >
> > > I have applied the following (hack) merge resolution for today.  
> >
> > Thanks a lot Stephen for taking the time to do that instead of dropping it.
> >
> > We should be able to do the same as Tamir did in commit 657403637f7d
> > ("rust: acpi: use `core::ffi::CStr` method names"), i.e. move the
> > build assert below to then be able to use `len()` instead:
> >
> > diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
> > index aea1b44d189b..f67c355c988e 100644
> > --- a/rust/kernel/i2c.rs
> > +++ b/rust/kernel/i2c.rs
> > @@ -43,11 +43,8 @@ impl DeviceId {
> >      /// 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();
> > +        let src = id.to_bytes_with_nul();
> > +        build_assert!(src.len() <= Self::I2C_NAME_SIZE, "ID exceeds 20 bytes");
> >          let mut i2c: bindings::i2c_device_id = pin_init::zeroed();
> >          let mut i = 0;
> >          while i < src.len() {
> > @@ -433,11 +430,8 @@ impl I2cBoardInfo {
> >      /// 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();
> > +        let src = type_.to_bytes_with_nul();
> > +        build_assert!(src.len() <= Self::I2C_TYPE_SIZE, "Type exceeds
> > 20 bytes");
> >          let mut i2c_board_info: bindings::i2c_board_info = pin_init::zeroed();
> >          let mut i: usize = 0;
> >          while i < src.len() {
> >
> > Igor/Tamir?  
> 
> Yep, looks correct to me!

OK, I have used that from today.

Could that fix just be applied to the driver-core tree now?  Or does it
depend on changes in the rust tree?

-- 
Cheers,
Stephen Rothwell
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Tamir Duberstein 1 week, 3 days ago
On Thu, Nov 20, 2025 at 11:39 PM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
>
> Hi all,
>
> On Thu, 20 Nov 2025 06:27:13 -0500 Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > On Thu, Nov 20, 2025 at 4:15 AM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
> > >
> > > On Thu, Nov 20, 2025 at 8:11 AM Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> > > >
> > > > I have applied the following (hack) merge resolution for today.
> > >
> > > Thanks a lot Stephen for taking the time to do that instead of dropping it.
> > >
> > > We should be able to do the same as Tamir did in commit 657403637f7d
> > > ("rust: acpi: use `core::ffi::CStr` method names"), i.e. move the
> > > build assert below to then be able to use `len()` instead:
> > >
> > > diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
> > > index aea1b44d189b..f67c355c988e 100644
> > > --- a/rust/kernel/i2c.rs
> > > +++ b/rust/kernel/i2c.rs
> > > @@ -43,11 +43,8 @@ impl DeviceId {
> > >      /// 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();
> > > +        let src = id.to_bytes_with_nul();
> > > +        build_assert!(src.len() <= Self::I2C_NAME_SIZE, "ID exceeds 20 bytes");
> > >          let mut i2c: bindings::i2c_device_id = pin_init::zeroed();
> > >          let mut i = 0;
> > >          while i < src.len() {
> > > @@ -433,11 +430,8 @@ impl I2cBoardInfo {
> > >      /// 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();
> > > +        let src = type_.to_bytes_with_nul();
> > > +        build_assert!(src.len() <= Self::I2C_TYPE_SIZE, "Type exceeds
> > > 20 bytes");
> > >          let mut i2c_board_info: bindings::i2c_board_info = pin_init::zeroed();
> > >          let mut i: usize = 0;
> > >          while i < src.len() {
> > >
> > > Igor/Tamir?
> >
> > Yep, looks correct to me!
>
> OK, I have used that from today.
>
> Could that fix just be applied to the driver-core tree now?  Or does it
> depend on changes in the rust tree?

I don't see why not. It does not depend on changes in the rust tree.
@Danilo Krummrich?
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Miguel Ojeda 1 week, 3 days ago
On Fri, Nov 21, 2025 at 1:17 PM Tamir Duberstein <tamird@gmail.com> wrote:
>
> I don't see why not. It does not depend on changes in the rust tree.
> @Danilo Krummrich?

I think Danilo may not be near a computer at the moment -- Greg, I can
send you a patch to apply (or we could just leave this as a conflict
resolution to be applied by Linus too).

Cheers,
Miguel
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Danilo Krummrich 1 week, 3 days ago
On Sat Nov 22, 2025 at 4:56 AM NZDT, Miguel Ojeda wrote:
> On Fri, Nov 21, 2025 at 1:17 PM Tamir Duberstein <tamird@gmail.com> wrote:
>>
>> I don't see why not. It does not depend on changes in the rust tree.
>> @Danilo Krummrich?
>
> I think Danilo may not be near a computer at the moment -- Greg, I can
> send you a patch to apply (or we could just leave this as a conflict
> resolution to be applied by Linus too).

Yes, a patch would be great -- thanks for providing the conflict resolution!

- Danilo
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Greg KH 1 week, 3 days ago
On Fri, Nov 21, 2025 at 04:56:37PM +0100, Miguel Ojeda wrote:
> On Fri, Nov 21, 2025 at 1:17 PM Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > I don't see why not. It does not depend on changes in the rust tree.
> > @Danilo Krummrich?
> 
> I think Danilo may not be near a computer at the moment -- Greg, I can
> send you a patch to apply (or we could just leave this as a conflict
> resolution to be applied by Linus too).

I'll take a patch, thanks!
Re: linux-next: manual merge of the rust tree with the driver-core tree
Posted by Miguel Ojeda 1 week, 1 day ago
On Fri, Nov 21, 2025 at 5:07 PM Greg KH <greg@kroah.com> wrote:
>
> I'll take a patch, thanks!

and

On Fri, Nov 21, 2025 at 8:21 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
> Yes, a patch would be great -- thanks for providing the conflict resolution!

Done:

    https://lore.kernel.org/rust-for-linux/20251123163536.1771801-1-ojeda@kernel.org/

I noticed Stephen's resolution can remove an import too.

Cheers,
Miguel