Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH 0/2] remove TryFrom<&Device> implementation for pci and platform
@ 2026-10-19 16:13 Nicolás Antinori
  2026-10-19 16:13 ` [PATCH 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
  2026-10-19 16:13 ` [PATCH 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device Nicolás Antinori
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-10-19 16:13 UTC (permalink / raw)
  To: 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

Hello,

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

To make sure that there were no remaining users, I checked for usages of
the `try_from` method and the structs implementing `TryFrom` using rust
analyzer, activated the modules that were using the structs, 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()` in fact, the last usage of the
trait was a `try_into()` in pci).

I did what I described above from the most recent changes (rust-next,
linux-next, drm-rust-next) down to the introduction of the
implementation, stopping in all major versions (7.3-rc7 to 6.19) to find
the last usage and mark the commit in the `Fixes:` tag. I found no
usages for the platform implementation.

If applied to current rust-next, commit 7c306f00835a ("rust: zerocopy:
update to v0.8.62"), nova driver will fail to build, drm-rust-next and
linux-next are ok.

This series, along with the i2c patch [1], closes:
https://github.com/Rust-for-Linux/linux/issues/1264

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/

[1] https://lore.kernel.org/rust-for-linux/20261019152329.620610-1-nico.antinori.7@gmail.com/T/#u

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/kernel/pci.rs      | 21 ---------------------
 rust/kernel/platform.rs | 21 ---------------------
 2 files changed, 42 deletions(-)

--
2.47.3


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

* [PATCH 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device
  2026-10-19 16:13 [PATCH 0/2] remove TryFrom<&Device> implementation for pci and platform Nicolás Antinori
@ 2026-10-19 16:13 ` Nicolás Antinori
  2026-10-19 18:24   ` Nicolás Antinori
  2026-10-19 16:13 ` [PATCH 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device Nicolás Antinori
  1 sibling, 1 reply; 4+ messages in thread
From: Nicolás Antinori @ 2026-10-19 16:13 UTC (permalink / raw)
  To: 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
`&Device<Ctx>` since it has no remaining users.

Fixes: 7edc491f6fca ("drm: nova: Use nova-core to read VRAM_BAR_SIZE parameter")
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>
---
 rust/kernel/pci.rs | 21 ---------------------
 1 file changed, 21 deletions(-)

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 related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device
  2026-10-19 16:13 [PATCH 0/2] remove TryFrom<&Device> implementation for pci and platform Nicolás Antinori
  2026-10-19 16:13 ` [PATCH 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
@ 2026-10-19 16:13 ` Nicolás Antinori
  1 sibling, 0 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-10-19 16:13 UTC (permalink / raw)
  To: 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
`&Device<Ctx>` since it has had no users since its introduction.

Fixes: a38dfd60fe53 ("rust: platform: impl TryFrom<&Device> for &platform::Device")
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>
---
 rust/kernel/platform.rs | 21 ---------------------
 1 file changed, 21 deletions(-)

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 related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device
  2026-10-19 16:13 ` [PATCH 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
@ 2026-10-19 18:24   ` Nicolás Antinori
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolás Antinori @ 2026-10-19 18:24 UTC (permalink / raw)
  To: Nicolás Antinori, Danilo Krummrich, Georgios Androutsopoulos
  Cc: 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

Hello,

On Mon Oct 19, 2026 at 1:13 PM -03, Nicolás Antinori wrote:
> Remove the `TryFrom<&device::Device<Ctx>>` implementation for
> `&Device<Ctx>` since it has no remaining users.
>
> Fixes: 7edc491f6fca ("drm: nova: Use nova-core to read VRAM_BAR_SIZE parameter")
> 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>

I got two reviews from Sashiko [1]

> [Severity: Low]
> Does removing this TryFrom implementation break the build when
> CONFIG_DRM_NOVA is enabled?
>
> The commit message references commit 7edc491f6fca ("drm: nova: Use
> nova-core to read VRAM_BAR_SIZE parameter"), which is not present in
> this baseline branch. Without that commit applied first, File::get_param()
> in drivers/gpu/drm/nova/file.rs still relies on this conversion:

This is true for the rust-next branch in the R4L tree, but the named
commit is present in linux-next [2] and drm-rust-next [3], and the patch
application and compilation were tested in those too.

I am pretty sure the patches were created based on the master branch of
linux-next tree (because of the discussion in [4]).

> [Severity: Low]
> Since TryFrom::try_from() was the only caller of bindings::dev_is_pci(),
> should rust_helper_dev_is_pci() in rust/helpers/pci.c also be removed
> along with it?

I didn't see this. I apologize for the oversight. I can send a separate
patch or a v2 of this patch alone, since the patches of the series are
related but can be applied independently.

Best regards,
Nicolás 

[1] https://sashiko.dev/#/patchset/cover.1792417858.git.nico.antinori.7@gmail.com?part=1
[2] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=7edc491f6fca8e22f51e37a16d74914cd959274d
[3] https://gitlab.freedesktop.org/drm/rust/kernel/-/commit/7edc491f6fca8e22f51e37a16d74914cd959274d
[4] https://github.com/Rust-for-Linux/linux/issues/1264#issuecomment-6194695910

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

end of thread, other threads:[~2026-10-19 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 16:13 [PATCH 0/2] remove TryFrom<&Device> implementation for pci and platform Nicolás Antinori
2026-10-19 16:13 ` [PATCH 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device Nicolás Antinori
2026-10-19 18:24   ` Nicolás Antinori
2026-10-19 16:13 ` [PATCH 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device Nicolás Antinori

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