public inbox for driver-core@lists.linux.dev
 help / color / mirror / Atom feed
* Re: [PATCH 0/5] rust: extend I2C functionality
       [not found] <20260131-i2c-adapter-v1-0-5a436e34cd1a@gmail.com>
@ 2026-01-31 14:26 ` Danilo Krummrich
  2026-02-08 12:34   ` Igor Korotin
  2026-02-09 11:31   ` Bartosz Golaszewski
  0 siblings, 2 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-01-31 14:26 UTC (permalink / raw)
  To: Igor Korotin via B4 Relay
  Cc: igor.korotin.linux, Daniel Almeida, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Wolfram Sang, linux-kernel,
	rust-for-linux, linux-i2c, markus.probst, brgl, gregkh, rafael,
	driver-core

(Cc: Bartosz, Greg, Rafael, driver-core)

On Sat Jan 31, 2026 at 3:12 PM CET, Igor Korotin via B4 Relay wrote:
> This patch series extend the existing I2C functionality with:
> - Abstractions allowing to implement I2C algorithms used by I2C adapters;
> - Abstractions allowing to create and add new I2C adapters;
> - Safe wrappers upon I2C and SMbus transferring C API: read/write
>   bytes/words/byte arrays.
>
> The patch series contains additional new sample driver `rust_i2c_adapter`
> presenting the new functionality. 

The i2c_adapter code on the C side has some lifetime issues, Bartosz looks into
resolving.

My biggest concern is that struct i2c_adapter is a bus device implementation,
but does not use the reference count of the embedded struct device.

Instead, I2C bus drivers embedd the i2c_adapter in their driver specific
structure, which is typically freed in the I2C bus driver's remove() callback.

This violates struct device reference counts.

Until this is fixed, the Rust abstractions should probably work around this, to
subsequent painful rework.

> Patch series depend on 
> message-id: <20260107103511.570525-1-dakr@kernel.org>
>
> Signed-off-by: Igor Korotin <igor.korotin.linux@gmail.com>
> ---
> Igor Korotin (5):
>       rust: i2c: split client and adapter code into separate files
>       rust: bits: add define_flags macro
>       rust: i2c: Add I2C Adapter registration abstractions
>       rust: i2c: add I2C wrappers
>       samples: rust: add Rust I2C adapter registration sample
>
>  MAINTAINERS                      |   4 +-
>  include/linux/i2c.h              |   6 +
>  rust/helpers/helpers.c           |   1 +
>  rust/helpers/i2c.c               |  15 ++
>  rust/kernel/bits.rs              |  57 ++++++++
>  rust/kernel/i2c.rs               | 254 ++-------------------------------
>  rust/kernel/i2c/adapter.rs       | 200 ++++++++++++++++++++++++++
>  rust/kernel/i2c/algo.rs          | 300 +++++++++++++++++++++++++++++++++++++++
>  rust/kernel/i2c/client.rs        | 284 ++++++++++++++++++++++++++++++++++++
>  samples/rust/Kconfig             |  12 ++
>  samples/rust/Makefile            |   1 +
>  samples/rust/rust_driver_i2c.rs  |  10 +-
>  samples/rust/rust_i2c_adapter.rs | 170 ++++++++++++++++++++++
>  samples/rust/rust_i2c_client.rs  |  15 +-
>  14 files changed, 1069 insertions(+), 260 deletions(-)
> ---
> base-commit: a7c013f779530190d0c1e1aa5e7c8a61f0bd479e
> change-id: 20260131-i2c-adapter-d38d330c4c25
> prerequisite-message-id: <20260107103511.570525-1-dakr@kernel.org>
> prerequisite-patch-id: 6e4d28a06d842ddfc7db82f410532a35b8fe317d
> prerequisite-patch-id: 9739295d85b688257fca29be1e1217a05a69c9e7
> prerequisite-patch-id: 78eaed3746a40713f44f13508fcf43653b0a4528
> prerequisite-patch-id: 99f1881bc896896297a903affcfa4f62cab1a307
> prerequisite-patch-id: ea8baa9d648f1178d6f39d140b98bddf3c183f6f
> prerequisite-patch-id: f8a9e049d204bde04e80151a67dfff5ec2633e7a
>
> Best regards,
> -- 
> Igor Korotin <igor.korotin.linux@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/5] rust: extend I2C functionality
  2026-01-31 14:26 ` [PATCH 0/5] rust: extend I2C functionality Danilo Krummrich
@ 2026-02-08 12:34   ` Igor Korotin
  2026-02-08 17:07     ` Danilo Krummrich
  2026-02-09 11:31   ` Bartosz Golaszewski
  1 sibling, 1 reply; 4+ messages in thread
From: Igor Korotin @ 2026-02-08 12:34 UTC (permalink / raw)
  To: Danilo Krummrich, Igor Korotin via B4 Relay
  Cc: igor.korotin.linux, Daniel Almeida, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Wolfram Sang, linux-kernel,
	rust-for-linux, linux-i2c, markus.probst, brgl, gregkh, rafael,
	driver-core

Hello Danilo

On 1/31/2026 2:26 PM, Danilo Krummrich wrote:
> (Cc: Bartosz, Greg, Rafael, driver-core)
> 
> On Sat Jan 31, 2026 at 3:12 PM CET, Igor Korotin via B4 Relay wrote:
>> This patch series extend the existing I2C functionality with:
>> - Abstractions allowing to implement I2C algorithms used by I2C adapters;
>> - Abstractions allowing to create and add new I2C adapters;
>> - Safe wrappers upon I2C and SMbus transferring C API: read/write
>>    bytes/words/byte arrays.
>>
>> The patch series contains additional new sample driver `rust_i2c_adapter`
>> presenting the new functionality.
> 
> The i2c_adapter code on the C side has some lifetime issues, Bartosz looks into
> resolving.
> 
> My biggest concern is that struct i2c_adapter is a bus device implementation,
> but does not use the reference count of the embedded struct device.
> 
> Instead, I2C bus drivers embedd the i2c_adapter in their driver specific
> structure, which is typically freed in the I2C bus driver's remove() callback.
> 
> This violates struct device reference counts.
> 
> Until this is fixed, the Rust abstractions should probably work around this, to
> subsequent painful rework.

just to clarify what is currently implemented on the Rust side.

The Rust I2cAdapter is required to be bound to a parent Device<Bound>. 
The implementation keeps a reference to the embedded struct device 
inside struct i2c_adapter for the entire lifetime of the Rust adapter, 
so its lifetime is tied to the device model.

I am not entirely sure which specific lifetime or refcounting scenario 
you are referring to. If you have a concrete case in mind where this 
would still be problematic, could you please point it out?

Cheers
Igor




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/5] rust: extend I2C functionality
  2026-02-08 12:34   ` Igor Korotin
@ 2026-02-08 17:07     ` Danilo Krummrich
  0 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-02-08 17:07 UTC (permalink / raw)
  To: Igor Korotin
  Cc: Igor Korotin via B4 Relay, igor.korotin.linux, Daniel Almeida,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Wolfram Sang, linux-kernel, rust-for-linux, linux-i2c,
	markus.probst, brgl, gregkh, rafael, driver-core

On Sun Feb 8, 2026 at 1:34 PM CET, Igor Korotin wrote:
> Hello Danilo
>
> On 1/31/2026 2:26 PM, Danilo Krummrich wrote:
>> (Cc: Bartosz, Greg, Rafael, driver-core)
>> 
>> On Sat Jan 31, 2026 at 3:12 PM CET, Igor Korotin via B4 Relay wrote:
>>> This patch series extend the existing I2C functionality with:
>>> - Abstractions allowing to implement I2C algorithms used by I2C adapters;
>>> - Abstractions allowing to create and add new I2C adapters;
>>> - Safe wrappers upon I2C and SMbus transferring C API: read/write
>>>    bytes/words/byte arrays.
>>>
>>> The patch series contains additional new sample driver `rust_i2c_adapter`
>>> presenting the new functionality.
>> 
>> The i2c_adapter code on the C side has some lifetime issues, Bartosz looks into
>> resolving.
>> 
>> My biggest concern is that struct i2c_adapter is a bus device implementation,
>> but does not use the reference count of the embedded struct device.
>> 
>> Instead, I2C bus drivers embedd the i2c_adapter in their driver specific
>> structure, which is typically freed in the I2C bus driver's remove() callback.
>> 
>> This violates struct device reference counts.
>> 
>> Until this is fixed, the Rust abstractions should probably work around this, to
>> subsequent painful rework.
>
> just to clarify what is currently implemented on the Rust side.
>
> The Rust I2cAdapter is required to be bound to a parent Device<Bound>. 
> The implementation keeps a reference to the embedded struct device 
> inside struct i2c_adapter for the entire lifetime of the Rust adapter, 
> so its lifetime is tied to the device model.
>
> I am not entirely sure which specific lifetime or refcounting scenario 
> you are referring to. If you have a concrete case in mind where this 
> would still be problematic, could you please point it out?

The implementation on the C side does not consider the reference count of the
embedded struct device, which is not correct.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/5] rust: extend I2C functionality
  2026-01-31 14:26 ` [PATCH 0/5] rust: extend I2C functionality Danilo Krummrich
  2026-02-08 12:34   ` Igor Korotin
@ 2026-02-09 11:31   ` Bartosz Golaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-02-09 11:31 UTC (permalink / raw)
  To: Danilo Krummrich
  Cc: igor.korotin.linux, Daniel Almeida, Miguel Ojeda, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Wolfram Sang, linux-kernel,
	rust-for-linux, linux-i2c, markus.probst, brgl, gregkh, rafael,
	driver-core, Igor Korotin via B4 Relay

On Sat, 31 Jan 2026 15:26:22 +0100, Danilo Krummrich <dakr@kernel.org> said:
> (Cc: Bartosz, Greg, Rafael, driver-core)
>
> On Sat Jan 31, 2026 at 3:12 PM CET, Igor Korotin via B4 Relay wrote:
>> This patch series extend the existing I2C functionality with:
>> - Abstractions allowing to implement I2C algorithms used by I2C adapters;
>> - Abstractions allowing to create and add new I2C adapters;
>> - Safe wrappers upon I2C and SMbus transferring C API: read/write
>>   bytes/words/byte arrays.
>>
>> The patch series contains additional new sample driver `rust_i2c_adapter`
>> presenting the new functionality.
>
> The i2c_adapter code on the C side has some lifetime issues, Bartosz looks into
> resolving.
>
> My biggest concern is that struct i2c_adapter is a bus device implementation,
> but does not use the reference count of the embedded struct device.
>
> Instead, I2C bus drivers embedd the i2c_adapter in their driver specific
> structure, which is typically freed in the I2C bus driver's remove() callback.
>

Correct.

> This violates struct device reference counts.
>

What's currently done in order to not crash is: we wait forever until all users
release their references[1].

> Until this is fixed, the Rust abstractions should probably work around this, to
> subsequent painful rework.
>

The rework of the C part will be long an painful already. I estimated the work
will take at least a year. More info here[2].

Bart

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/i2c/i2c-core-base.c#n1814
[2] https://lore.kernel.org/all/aWYYZEPX-_1GfQtL@ninjato/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-09 11:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260131-i2c-adapter-v1-0-5a436e34cd1a@gmail.com>
2026-01-31 14:26 ` [PATCH 0/5] rust: extend I2C functionality Danilo Krummrich
2026-02-08 12:34   ` Igor Korotin
2026-02-08 17:07     ` Danilo Krummrich
2026-02-09 11:31   ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox