[PATCH v2 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device
From: Nicolás Antinori
Date: Wed Nov 04 2026 - 16:18:29 EST
Remove the `TryFrom<&device::Device<Ctx>>` implementation for
`&Device<Ctx>` as it has had no users since its introduction.
This removal also eliminates a pre-existing lifetime soundness issue:
the input and output reference lifetimes were independent, allowing the
conversion of a temporarily borrowed `device::Device` into `&'static
platform::Device` in safe Rust. Removing the device could leave a
dangling reference.
Fixes: a38dfd60fe53 ("rust: platform: impl TryFrom<&Device> for &platform::Device")
Reported-by: Georgios Androutsopoulos <georgeandrout13@xxxxxxxxx>
Link: https://github.com/Rust-for-Linux/linux/issues/1264
Signed-off-by: Nicolás Antinori <nico.antinori.7@xxxxxxxxx>
---
rust/helpers/helpers.c | 1 -
rust/helpers/platform.c | 8 --------
rust/kernel/platform.rs | 21 ---------------------
3 files changed, 30 deletions(-)
delete mode 100644 rust/helpers/platform.c
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index d62c7be1ca7b..787dd8ff8c6c 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -82,7 +82,6 @@
#include "page.c"
#include "pci.c"
#include "pid_namespace.c"
-#include "platform.c"
#include "poll.c"
#include "processor.c"
#include "property.c"
diff --git a/rust/helpers/platform.c b/rust/helpers/platform.c
deleted file mode 100644
index 188b3240f32d..000000000000
--- a/rust/helpers/platform.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/platform_device.h>
-
-__rust_helper bool rust_helper_dev_is_platform(const struct device *dev)
-{
- return dev_is_platform(dev);
-}
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index ac0a012ae1bb..f49aedcc94b1 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -7,7 +7,6 @@
use crate::{
acpi,
bindings,
- container_of,
device::{
self,
Bound, //
@@ -557,26 +556,6 @@ fn as_ref(&self) -> &device::Device<Ctx> {
}
}
-impl<Ctx: device::DeviceContext> TryFrom<&device::Device<Ctx>> for &Device<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::dev_is_platform(dev.as_raw()) } {
- return Err(EINVAL);
- }
-
- // SAFETY: We've just verified that the bus type of `dev` equals
- // `bindings::platform_bus_type`, hence `dev` must be embedded in a valid
- // `struct platform_device` as guaranteed by the corresponding C code.
- let pdev = unsafe { container_of!(dev.as_raw(), bindings::platform_device, dev) };
-
- // SAFETY: `pdev` is a valid pointer to a `struct platform_device`.
- Ok(unsafe { &*pdev.cast() })
- }
-}
-
// SAFETY: A `Device` is always reference-counted and can be released from any thread.
unsafe impl Send for Device {}
--
2.47.3