rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Igor Korotin" <igor.korotin.linux@gmail.com>
Cc: "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 v6 2/3] rust: i2c: Add basic I2C driver abstractions
Date: Mon, 27 Oct 2025 23:00:25 +0100	[thread overview]
Message-ID: <DDTFXY5VJCS2.1ZB9EPNLDTPAC@kernel.org> (raw)
In-Reply-To: <30fbb191-5300-45e9-93d3-8b2ef5cf18ef@gmail.com>

On Mon Oct 27, 2025 at 9:27 PM CET, Igor Korotin wrote:
> On 10/26/2025 7:20 PM, Danilo Krummrich wrote:
>> This is an API that should be used by drivers operating complicated devices
>> (DRM, NET, etc.) where there is no point in keeping an i2c::Registration alive
>> after the driver that registered the I2C client has been unbound itself.
>> 
>> For instance, a GPU driver may call this in probe() to register an I2C device
>> for some redriver, repeater, multiplexer, etc. So, it makes no sense to allow a
>> corresponding i2c::Registration to still exist beyond the GPU driver being unbound.
>> 
>> Hence, besides not really being necessary for safety reasons, it still seems
>> reasonable to enforce this for semantic reasons.
>
> I might be misunderstanding your point, but as I see it, Devres cannot 
> apply here
> because we can't bind it to i2c_adapter.

Yes, you do misunderstand.

I'm not saying to use the I2C adapter device for this, that makes no sense. In
fact, it wouldn't even work, because the underlying device can not be guaranteed
to be in a bound state.

> There's no guarantee that driver
> owns it. Registration can't be bound to i2c_client, cause it's kind of 
> chicken and egg situation.

I'm also not saying to use the the I2C client, which indeed makes even less
sense (and wouldn't work for the same reason mentioned above).

Think of the bigger picture, i.e. where is i2c:Registration::new() called from?

It's called from other drivers (e.g. DRM drivers [1] or network drivers [2])
that are bound to some bus device themselves, e.g. a platform device or a PCI
device.

This is the device that we can give to i2c:Registration::new() and use for the
internal call to devres.

With that we ensure that the i2c:Registration will be dropped, when the driver
that originally called i2c:Registration::new() is unbound; it makes no sense to
allow a driver to keep an i2c:Registration alive when it is unbound.

In fact, quite some C drivers are already doing exactly this by hand. For
instance, see [3]. Four lines after [3], raa215300_rtc_unregister_device() is
registered with devm_add_action_or_reset(), which calls i2c_unregister_device().

Having that said, I'm a bit curious now: What is your use-case for
i2c:Registration?

[1] https://elixir.bootlin.com/linux/v6.17.5/source/drivers/gpu/drm/xe/xe_i2c.c#L72
[2] https://elixir.bootlin.com/linux/v6.17.5/source/drivers/net/ethernet/intel/igb/igb_hwmon.c#L201
[3] https://elixir.bootlin.com/linux/v6.17.5/source/drivers/regulator/raa215300.c#L160

  reply	other threads:[~2025-10-27 22:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-05 10:22 [PATCH v6 0/3] rust: i2c: Add basic I2C driver abstractions Igor Korotin
2025-10-05 10:23 ` [PATCH v6 1/3] rust: i2c: add basic I2C device and " Igor Korotin
2025-10-26 10:49   ` Danilo Krummrich
2025-10-05 10:23 ` [PATCH v6 2/3] rust: i2c: add manual I2C device creation abstractions Igor Korotin
2025-10-26 10:48   ` Danilo Krummrich
2025-10-26 18:41     ` [PATCH v6 2/3] rust: i2c: Add basic I2C driver abstractions Igor Korotin
2025-10-26 19:20       ` Danilo Krummrich
2025-10-27 20:27         ` Igor Korotin
2025-10-27 22:00           ` Danilo Krummrich [this message]
2025-10-28 20:00             ` Igor Korotin
2025-10-05 10:23 ` [PATCH v6 3/3] samples: rust: add Rust I2C sample driver Igor Korotin
2025-10-26 10:48   ` Danilo Krummrich
2025-10-26 14:06     ` Igor Korotin
2025-10-26 15:43       ` Danilo Krummrich
2025-10-26 15:50         ` Igor Korotin
2025-10-26 15:55           ` Danilo Krummrich
2025-10-26  9:38 ` [PATCH v6 0/3] rust: i2c: Add basic I2C driver abstractions Igor Korotin
2025-10-26 10:52   ` Danilo Krummrich
2025-10-26 14:07     ` Igor Korotin
2025-10-26 14:25     ` Wolfram Sang

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=DDTFXY5VJCS2.1ZB9EPNLDTPAC@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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).