Re: [PATCH 0/5] rust: extend I2C functionality

From: Bartosz Golaszewski

Date: Mon Feb 09 2026 - 06:31:33 EST


On Sat, 31 Jan 2026 15:26:22 +0100, Danilo Krummrich <dakr@xxxxxxxxxx> 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/