Re: [PATCH v6 2/3] rust: i2c: add manual I2C device creation abstractions

From: Danilo Krummrich
Date: Sun Oct 26 2025 - 06:48:35 EST


On 10/5/25 12:23 PM, Igor Korotin wrote:
> +impl Registration {
> + /// The C `i2c_new_client_device` function wrapper for manual I2C client creation.
> + pub fn new(i2c_adapter: &I2cAdapter, i2c_board_info: &I2cBoardInfo) -> Result<Self> {
> + // SAFETY: the kernel guarantees that `i2c_new_client_device()` returns either a valid
> + // pointer or NULL. `from_err_ptr` separates errors. Following `NonNull::new` checks for NULL.
> + let raw_dev = from_err_ptr(unsafe {
> + bindings::i2c_new_client_device(i2c_adapter.as_raw(), i2c_board_info.as_raw())
> + })?;
> +
> + let dev_ptr = NonNull::new(raw_dev).ok_or(ENODEV)?;
> +
> + Ok(Self(dev_ptr))
> + }
> +}

I wonder if we want to ensure that a Registration can't out-live the driver that
registers the I2C client device.

This should only ever be called by drivers bound to more complex devices, so if
the parent driver is unbound I don't think I2C client device registered by this
driver should be able to survive.

Hence, I think Registration::new() should return
impl PinInit<Devres<Self>, Error> instead.