All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Igor Korotin" <igor.korotin.linux@gmail.com>
Cc: "Daniel Almeida" <daniel.almeida@collabora.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wolfram Sang" <wsa+renesas@sang-engineering.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Asahi Lina" <lina+kernel@asahilina.net>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Alex Hung" <alex.hung@amd.com>,
	"Tamir Duberstein" <tamird@gmail.com>,
	"Xiangfei Ding" <dingxiangfei2009@gmail.com>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-i2c@vger.kernel.org
Subject: Re: [PATCH v4 3/3] samples: rust: add Rust I2C sample driver
Date: Tue, 09 Sep 2025 20:34:12 +0200	[thread overview]
Message-ID: <DCOHHWQDKJCL.1CKT9HCBZXNNN@kernel.org> (raw)
In-Reply-To: <dd798632-1865-464d-8a02-f8d9e20a16b6@gmail.com>

On Tue Sep 9, 2025 at 7:55 PM CEST, Igor Korotin wrote:
> On 8/27/2025 8:38 PM, Daniel Almeida wrote:
>>> +#[pin_data]
>>> +struct DriverModule {
>>> +    #[pin]
>>> +    _driver: kernel::driver::Registration<Ops<SampleDriver>>,
>>> +    _reg: i2c::Registration,
>>> +}
>> 
>> I was expecting this to be ARef of something, most likely I2cClient?

This is the Registration of an I2C device, just like auxiliary::Registration or
faux::Registration. There is no point in reference counting the registration
object.

You can't have an ARef<I2cClient> here either because you want to manage the
lifetime of the I2cClient to be registered in the system, i.e.
i2c_new_client_device() and i2c_unregister_device().

>> This is where my knowledge of i2c drivers start to fall short, but others will
>> probably chime in :)
>
> You're right to mention this. This rust_driver_i2c is not the standard 
> way of handling I2C devices.

It is indeed the normal way of handling this. This Registration object
represents the lifetime of calling i2c_new_client_device() e.g. from a platform
device probe (as Igor also mentions below) and calling i2c_unregister_device()
e.g. from platform device remove.

The ARef<I2cClient> can be obtained from the subsequent bus callback from the
I2C bus.

In fact, you could add a method to i2c::Registration to provide you with an
ARef<I2cClient> if that's ever needed.

But the i2c::Registration itself simply manages the lifetime for the I2C device
being registered in the system.

> The idea was suggested by Danilo in the 
> review of Patch v2: this driver merges an I2C driver sample with manual 
> I2C device creation. The module creates a new I2cClient in its init 
> function, and this new I2cClient is then probed by the SampleDriver.
>
> In a normal driver it should be different. For example, let’s say 
> there’s a platform device — the probe function for this platform device 
> would create an I2cClient, and an appropriate I2C driver would then 
> probe it.
> Thanks for the review.
>
> Best Regards
> Igor


      reply	other threads:[~2025-09-09 18:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20 15:14 [PATCH v4 0/3] rust: i2c: Add basic I2C driver abstractions Igor Korotin
2025-08-20 15:19 ` [PATCH v4 1/3] rust: i2c: add basic I2C device and " Igor Korotin
2025-08-27 18:37   ` Daniel Almeida
2025-09-09 17:19     ` Igor Korotin
2025-09-09 17:53       ` Daniel Almeida
2025-09-09 18:19         ` Danilo Krummrich
2025-09-09 18:22           ` Daniel Almeida
2025-08-20 15:21 ` [PATCH v4 2/3] rust: i2c: add manual I2C device creation abstractions Igor Korotin
2025-08-27 19:23   ` Daniel Almeida
2025-08-20 15:23 ` [PATCH v4 3/3] samples: rust: add Rust I2C sample driver Igor Korotin
2025-08-27 19:38   ` Daniel Almeida
2025-09-09 17:55     ` Igor Korotin
2025-09-09 18:34       ` Danilo Krummrich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DCOHHWQDKJCL.1CKT9HCBZXNNN@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=alex.hung@amd.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=daniel.almeida@collabora.com \
    --cc=dingxiangfei2009@gmail.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=igor.korotin.linux@gmail.com \
    --cc=lina+kernel@asahilina.net \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tmgross@umich.edu \
    --cc=viresh.kumar@linaro.org \
    --cc=wedsonaf@gmail.com \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.