Skip to content

Commit 3edaefb

Browse files
author
Danilo Krummrich
committed
rust: pci: preserve device context in AsRef
Since device::Device has a generic over its context, preserve this device context in AsRef. For instance, when calling pci::Device<Core> the new AsRef implementation returns device::Device<Core>. Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent da6c47c commit 3edaefb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rust/kernel/pci.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,13 @@ impl<const SIZE: usize> Deref for Bar<SIZE> {
360360
}
361361
}
362362

363-
impl Device {
363+
impl<Ctx: device::DeviceContext> Device<Ctx> {
364364
fn as_raw(&self) -> *mut bindings::pci_dev {
365365
self.0.get()
366366
}
367+
}
367368

369+
impl Device {
368370
/// Returns the PCI vendor ID.
369371
pub fn vendor_id(&self) -> u16 {
370372
// SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
@@ -440,8 +442,8 @@ unsafe impl crate::types::AlwaysRefCounted for Device {
440442
}
441443
}
442444

443-
impl AsRef<device::Device> for Device {
444-
fn as_ref(&self) -> &device::Device {
445+
impl<Ctx: device::DeviceContext> AsRef<device::Device<Ctx>> for Device<Ctx> {
446+
fn as_ref(&self) -> &device::Device<Ctx> {
445447
// SAFETY: By the type invariant of `Self`, `self.as_raw()` is a pointer to a valid
446448
// `struct pci_dev`.
447449
let dev = unsafe { addr_of_mut!((*self.as_raw()).dev) };

0 commit comments

Comments
 (0)