mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
rust: i2c: remove TryFrom<&Device> implementation for &I2cClient
Remove the `TryFrom<&device::Device<Ctx>>` implementation for
`&I2cClient<Ctx>` since it has had no users since its introduction.
Fixes: 57c5bd9aee ("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>
Signed-off-by: Igor Korotin <igor.korotin@linux.dev>
This commit is contained in:
parent
0f6be986ad
commit
e7755b5f29
|
|
@ -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 {}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user