mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rust: i2c: remove TryFrom<&Device> implementation for &I2cClient
@ 2026-10-19 15:23 Nicolás Antinori
  2026-10-21 10:38 ` Igor Korotin
  2026-10-21 12:32 ` Igor Korotin
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-10-19 15:23 UTC (permalink / raw)
  To: Igor Korotin, Danilo Krummrich, Georgios Androutsopoulos
  Cc: Nicolás Antinori, Alexandre Courbot, Alice Ryhl,
	Andreas Hindborg, Benno Lossin, Björn Roy Baron, Boqun Feng,
	Brigham Campbell, Daniel Almeida, Gary Guo, Jori Koolstra,
	Miguel Ojeda, Onur Özkan, Shuah Khan, Tamir Duberstein,
	Trevor Gross, linux-kernel, rust-for-linux, linux-kernel-mentees

Remove the `TryFrom<&device::Device<Ctx>>` implementation for
`&I2cClient<Ctx>` since it has had no users since its introduction.

Fixes: 57c5bd9aee94 ("rust: i2c: add basic I2C device and driver abstractions")
Reported-by: Georgios Androutsopoulos <georgeandrout13@gmail.com>
Closes: https://github.com/Rust-for-Linux/linux/issues/1264
Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
---
To make sure that there were no remaining users, I checked for usages of
the `try_from` method and the `I2cClient` struct using rust analyzer,
activated the modules that were using `I2cClient`, removed the
implementation and compiled the kernel (did not trust entirely in rust
analyzer because it does not find usages that depend on this
implementation like the `try_into()` automatic implementation).

I also checked for usages in all major versions in most recent versions
until the introduction of the trait implementation (from 7.3-rc7 to
6.19), rust-next and linux-next to find the last usage and mark the
commit in the `Fixes:` tag.

 rust/kernel/i2c.rs | 21 ---------------------
 1 file changed, 21 deletions(-)

diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
index 0487bae811fb..b4ff25c830fc 100644
--- a/rust/kernel/i2c.rs
+++ b/rust/kernel/i2c.rs
@@ -5,7 +5,6 @@
 // I2C Driver abstractions.
 use crate::{
     acpi,
-    container_of,
     device,
     device_id::{
         RawDeviceId,
@@ -517,26 +516,6 @@ fn as_ref(&self) -> &device::Device<Ctx> {
     }
 }

-impl<Ctx: device::DeviceContext> TryFrom<&device::Device<Ctx>> for &I2cClient<Ctx> {
-    type Error = kernel::error::Error;
-
-    fn try_from(dev: &device::Device<Ctx>) -> Result<Self, Self::Error> {
-        // SAFETY: By the type invariant of `Device`, `dev.as_raw()` is a valid pointer to a
-        // `struct device`.
-        if unsafe { bindings::i2c_verify_client(dev.as_raw()).is_null() } {
-            return Err(EINVAL);
-        }
-
-        // SAFETY: We've just verified that the type of `dev` equals to
-        // `bindings::i2c_client_type`, hence `dev` must be embedded in a valid
-        // `struct i2c_client` as guaranteed by the corresponding C code.
-        let idev = unsafe { container_of!(dev.as_raw(), bindings::i2c_client, dev) };
-
-        // SAFETY: `idev` is a valid pointer to a `struct i2c_client`.
-        Ok(unsafe { &*idev.cast() })
-    }
-}
-
 // SAFETY: A `I2cClient` is always reference-counted and can be released from any thread.
 unsafe impl Send for I2cClient {}

--
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-21 12:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19 15:23 [PATCH] rust: i2c: remove TryFrom<&Device> implementation for &I2cClient Nicolás Antinori
2026-10-21 10:38 ` Igor Korotin
2026-10-21 12:32 ` Igor Korotin
2026-10-21 12:44   ` Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®