From: "Nicolás Antinori" <nico.antinori.7@gmail.com>
To: Igor Korotin <igor.korotin@linux.dev>,
Danilo Krummrich <dakr@kernel.org>,
Georgios Androutsopoulos <georgeandrout13@gmail.com>
Cc: "Nicolás Antinori" <nico.antinori.7@gmail.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Benno Lossin" <lossin@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Boqun Feng" <boqun@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Gary Guo" <gary@garyguo.net>, "Miguel Ojeda" <ojeda@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
"Tamir Duberstein" <tamird@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: [PATCH v2 1/2] rust: pci: remove TryFrom<&Device> implementation for &pci::Device
Date: Wed, 4 Nov 2026 16:50:14 -0300 [thread overview]
Message-ID: <e04f96f1fb2af818d64d2d6061eb6b6ae793b594.1793818280.git.nico.antinori.7@gmail.com> (raw)
In-Reply-To: <cover.1793818280.git.nico.antinori.7@gmail.com>
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
next prev parent reply other threads:[~2026-11-04 19:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-04 19:50 ` [PATCH v2 2/2] rust: platform: remove TryFrom<&Device> implementation for &platform::Device Nicolás Antinori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e04f96f1fb2af818d64d2d6061eb6b6ae793b594.1793818280.git.nico.antinori.7@gmail.com \
--to=nico.antinori.7@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=georgeandrout13@gmail.com \
--cc=igor.korotin@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®