Re: [PATCH v5 3/3] samples: rust: add Rust I2C sample driver

From: Igor Korotin

Date: Sat Sep 27 2025 - 14:20:58 EST


Hello Danilo

On 9/11/2025 9:46 PM, Danilo Krummrich wrote:
On Thu Sep 11, 2025 at 5:50 PM CEST, Igor Korotin wrote:
+// NOTE: The code below is expanded macro module_i2c_driver. It is not used here
+// because we need to manually create an I2C client in `init()`. The macro
+// hides `init()`, so to demo client creation on adapter SAMPLE_I2C_ADAPTER_INDEX
+// we expand it by hand.
+type Ops<T> = kernel::i2c::Adapter<T>;

Not a huge fan of this type alias, but up to you. :)

I literally just unwrapped module_driver! macro to get to the init function.
This type was part of that macro. I do not see it necessary, so I'll remove it
in the next drop.
>> +
+ i2c::Registration::new(adapter.as_ref(), &BOARD_INFO)

Does i2c_new_client_device() grab a reference count of the adapter? If not, you
have to store an ARef<I2cAdapter> within your i2c::Registration as well.

Well, as far as I traced the C code, `adapter->dev` is a `client->dev->parent`. Inside of the i2c_new_client_device the new created client device is being registered and as part of this registration device's parent reference count is being incremented.

A big thanks for the review and comments.

Regards
Igor