mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform
@ 2026-11-04 19:50 Nicolás Antinori
  2026-11-04 19:50 ` [PATCH v2 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-11-04 19:50 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,
	Daniel Almeida, Gary Guo, Miguel Ojeda, Onur Özkan,
	Tamir Duberstein, Trevor Gross, linux-kernel, rust-for-linux

Hello,

This patch series removes `TryFrom<&Device<Ctx>>` implementations for
pci and platform's `Device` struct.

I made this a series because both TryFrom implementations were
introduced in a series:
https://lore.kernel.org/all/20250321214826.140946-1-dakr@kernel.org/

Changelog:
v2:
 - Replaced "Closes:" tags with "Link:" tag in both patches.
 - Added mention to the soundness problem in the commit messages.
 - Removed bindings::dev_is_platform C binding since it has no other
   usages.
 - Solved Sashiko from v1: "[Low] rust: pci: unused
   rust_helper_dev_is_pci() left in rust/helpers/pci.c": Deleted the
   binding. Platform was in the same situation as mentioned in the
   previous item.
Link to v1: https://lore.kernel.org/rust-for-linux/cover.1792417858.git.nico.antinori.7@gmail.com/T/#t

Best regards,
Nicolás

Nicolás Antinori (2):
  rust: pci: remove TryFrom<&Device> implementation for &pci::Device
  rust: platform: remove TryFrom<&Device> implementation for
    &platform::Device

 rust/helpers/helpers.c  |  1 -
 rust/helpers/pci.c      |  5 -----
 rust/helpers/platform.c |  8 --------
 rust/kernel/pci.rs      | 21 ---------------------
 rust/kernel/platform.rs | 21 ---------------------
 5 files changed, 56 deletions(-)
 delete mode 100644 rust/helpers/platform.c

--
2.47.3


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

* [PATCH v2 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device
  2026-11-04 19:50 [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform Nicolás Antinori
@ 2026-11-04 19:50 ` Nicolás Antinori
  2026-11-04 19:50 ` [PATCH v2 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device Nicolás Antinori
  2026-11-09 21:44 ` [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform Danilo Krummrich
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-11-04 19:50 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,
	Daniel Almeida, Gary Guo, Miguel Ojeda, Onur Özkan,
	Tamir Duberstein, Trevor Gross, linux-kernel, rust-for-linux

Remove the `TryFrom<&device::Device<Ctx>>` implementation for
`&Device<Ctx>` since it has no remaining users.

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
pci::Device` in safe Rust. Removing the device could leave a dangling
reference.

Fixes: 7edc491f6fca ("drm: nova: Use nova-core to read VRAM_BAR_SIZE parameter")
Reported-by: Georgios Androutsopoulos <georgeandrout13@gmail.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1264
Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
---
 rust/helpers/pci.c |  5 -----
 rust/kernel/pci.rs | 21 ---------------------
 2 files changed, 26 deletions(-)

diff --git a/rust/helpers/pci.c b/rust/helpers/pci.c
index a8540f90b13c..3822b7f47c57 100644
--- a/rust/helpers/pci.c
+++ b/rust/helpers/pci.c
@@ -25,11 +25,6 @@ __rust_helper unsigned long rust_helper_pci_resource_flags(const struct pci_dev
 	return pci_resource_flags(pdev, bar);
 }

-__rust_helper bool rust_helper_dev_is_pci(const struct device *dev)
-{
-	return dev_is_pci(dev);
-}
-
 __rust_helper unsigned int rust_helper_pci_irq_type(struct pci_dev *pdev)
 {
 	return pci_irq_type(pdev);
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 769d01d23429..0e9455fd544d 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -6,7 +6,6 @@

 use crate::{
     bindings,
-    container_of,
     device,
     device_id::{
         RawDeviceId,
@@ -535,26 +534,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_pci(dev.as_raw()) } {
-            return Err(EINVAL);
-        }
-
-        // SAFETY: We've just verified that the bus type of `dev` equals `bindings::pci_bus_type`,
-        // hence `dev` must be embedded in a valid `struct pci_dev` as guaranteed by the
-        // corresponding C code.
-        let pdev = unsafe { container_of!(dev.as_raw(), bindings::pci_dev, dev) };
-
-        // SAFETY: `pdev` is a valid pointer to a `struct pci_dev`.
-        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


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

* [PATCH v2 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device
  2026-11-04 19:50 [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform Nicolás Antinori
  2026-11-04 19:50 ` [PATCH v2 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
@ 2026-11-04 19:50 ` Nicolás Antinori
  2026-11-09 21:44 ` [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform Danilo Krummrich
  2 siblings, 0 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-11-04 19:50 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,
	Daniel Almeida, Gary Guo, Miguel Ojeda, Onur Özkan,
	Tamir Duberstein, Trevor Gross, linux-kernel, rust-for-linux

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@gmail.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1264
Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
---
 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


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

* Re: [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform
  2026-11-04 19:50 [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform Nicolás Antinori
  2026-11-04 19:50 ` [PATCH v2 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
  2026-11-04 19:50 ` [PATCH v2 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device Nicolás Antinori
@ 2026-11-09 21:44 ` Danilo Krummrich
  2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-11-09 21:44 UTC (permalink / raw)
  To: Nicolás Antinori
  Cc: Igor Korotin, Danilo Krummrich, Georgios Androutsopoulos,
	Alexandre Courbot, Alice Ryhl, Andreas Hindborg, Benno Lossin,
	Björn Roy Baron, Boqun Feng, Daniel Almeida, Gary Guo,
	Miguel Ojeda, Onur Özkan, Tamir Duberstein, Trevor Gross,
	linux-kernel, rust-for-linux

On Wed,  4 Nov 2026 16:50:13 -0300, Nicolás Antinori wrote:
> [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform

Applied, thanks!

  Branch: driver-core-testing
  Tree:   git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device
      commit: 6a185ac6b46d
[2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device
      commit: cecc2e38b631

The patches will appear in the next linux-next integration (typically within 24
hours on weekdays).

The patches are in the driver-core-testing branch and will be promoted to
driver-core-next after validation.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 19:50 [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform Nicolás Antinori
2026-11-04 19:50 ` [PATCH v2 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
2026-11-04 19:50 ` [PATCH v2 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device Nicolás Antinori
2026-11-09 21:44 ` [PATCH v2 0/2] remove TryFrom<&Device> implementations for pci and platform Danilo Krummrich

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®