From: Igor Korotin <igor.korotin@linux.dev>
To: "Nicolás Antinori" <nico.antinori.7@gmail.com>,
"Gary Guo" <gary@garyguo.net>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Benno Lossin" <lossin@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Boqun Feng" <boqun@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Tamir Duberstein" <tamird@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel-mentees@lists.linux.dev,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH] rust: i2c: avoid locking when calling I2cAdapter::inc_ref
Date: Sun, 09 Aug 2026 14:17:25 +0100 [thread overview]
Message-ID: <178628144572.5226.7072490581990266256@linux.dev> (raw)
In-Reply-To: <DJRJCCGCXYOL.2O4HP9N37SPAK@gmail.com>
Hello Nicolás
Sorry for the delay.
Yes, worth fixing regardless of real users -- inc_ref taking a lock it
doesn't need is a real bug, not speculative work.
Instead of adding a separate Rust-only wrapper, please consider splitting
i2c_get_adapter itself: pull the increment into a helper, export it, and
call it directly from inc_ref -- no lock, no lookup:
+bool __i2c_adapter_get(struct i2c_adapter *adapter)
+{
+ if (try_module_get(adapter->owner)) {
+ get_device(&adapter->dev);
+ return true;
+ }
+ return false;
+}
+EXPORT_SYMBOL(__i2c_adapter_get);
+
struct i2c_adapter *i2c_get_adapter(int nr)
{
struct i2c_adapter *adapter;
mutex_lock(&core_lock);
adapter = idr_find(&i2c_adapter_idr, nr);
- if (!adapter)
- goto exit;
-
- if (try_module_get(adapter->owner))
- get_device(&adapter->dev);
- else
+ if (adapter && !__i2c_adapter_get(adapter))
adapter = NULL;
-
- exit:
mutex_unlock(&core_lock);
return adapter;
}
EXPORT_SYMBOL(i2c_get_adapter);
Heads up for v2: Trevor Chan has a patch changing AlwaysRefCounted::inc_ref
to an associated function (fn inc_ref(obj: &Self)). Not merged yet --
rebase onto it if it lands first.
Cheers
Igor
prev parent reply other threads:[~2026-08-09 13:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 20:10 [PATCH] rust: i2c: avoid locking when calling I2cAdapter::inc_ref Nicolás Antinori
2026-06-16 21:15 ` Nicolás Antinori
2026-06-17 14:12 ` Gary Guo
2026-06-18 15:32 ` Nicolás Antinori
2026-07-06 13:50 ` Nicolás Antinori
2026-08-09 13:17 ` Igor Korotin [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=178628144572.5226.7072490581990266256@linux.dev \
--to=igor.korotin@linux.dev \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nico.antinori.7@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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