Skip to content

Commit e7a26cb

Browse files
hoshinolinamarcan
authored andcommitted
rust: drm: device: Convert Device to AlwaysRefCounted
Switch from being a refcount wrapper itself to a transparent wrapper around `bindings::drm_device`. The refcounted type then becomes ARef<Device<T>>. Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent f1a087c commit e7a26cb

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

rust/kernel/drm/gem/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
error::{to_result, Result},
1313
prelude::*,
1414
};
15-
use core::{mem, mem::ManuallyDrop, ops::Deref, ops::DerefMut};
15+
use core::{mem, ops::Deref, ops::DerefMut};
1616

1717
/// GEM object functions, which must be implemented by drivers.
1818
pub trait BaseDriverObject<T: BaseObject>: Sync + Send + Sized {
@@ -192,7 +192,7 @@ pub struct Object<T: DriverObject> {
192192
obj: bindings::drm_gem_object,
193193
// The DRM core ensures the Device exists as long as its objects exist, so we don't need to
194194
// manage the reference count here.
195-
dev: ManuallyDrop<device::Device<T::Driver>>,
195+
dev: *const bindings::drm_device,
196196
inner: T,
197197
}
198198

@@ -223,7 +223,7 @@ impl<T: DriverObject> Object<T> {
223223
obj: unsafe { mem::zeroed() },
224224
// SAFETY: The drm subsystem guarantees that the drm_device will live as long as
225225
// the GEM object lives, so we can conjure a reference out of thin air.
226-
dev: ManuallyDrop::new(unsafe { device::Device::from_raw(dev.ptr) }),
226+
dev: dev.drm.get(),
227227
inner: T::new(dev, size)?,
228228
})?;
229229

@@ -241,7 +241,9 @@ impl<T: DriverObject> Object<T> {
241241

242242
/// Returns the `Device` that owns this GEM object.
243243
pub fn dev(&self) -> &device::Device<T::Driver> {
244-
&self.dev
244+
// SAFETY: The drm subsystem guarantees that the drm_device will live as long as
245+
// the GEM object lives, so we can just borrow from the raw pointer.
246+
unsafe { device::Device::borrow(self.dev) }
245247
}
246248
}
247249

0 commit comments

Comments
 (0)