Re: [PATCH 0/5] rust: extend I2C functionality
From: Igor Korotin
Date: Sun Feb 08 2026 - 07:35:18 EST
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