summaryrefslogtreecommitdiff
path: root/rust/kernel/drm
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2026-06-28 16:53:34 +0200
committerDanilo Krummrich <dakr@kernel.org>2026-07-12 16:01:06 +0200
commit47f600d40bc6bf7bcc1f28f8c7fa3e3a7aa445eb (patch)
tree1a348d92334342dc246a370a8163af4056eb0564 /rust/kernel/drm
parent478da53e5b682f0c39a4c6c3eeb09c0131342e8a (diff)
downloadlinux-next-47f600d40bc6bf7bcc1f28f8c7fa3e3a7aa445eb.tar.gz
linux-next-47f600d40bc6bf7bcc1f28f8c7fa3e3a7aa445eb.zip
rust: drm: return ParentDevice from Device AsRef
Change AsRef for drm::Device to return &T::ParentDevice<device::Normal> instead of &device::Device, and restrict it to the Normal context. Device<T, Registered> still gets this through Deref coercion. This provides access to the typed parent bus device rather than the raw base device. Reviewed-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Tested-by: Deborah Brouwer <deborah.brouwer@collabora.com> Link: https://patch.msgid.link/20260628145406.2107056-15-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel/drm')
-rw-r--r--rust/kernel/drm/device.rs10
-rw-r--r--rust/kernel/drm/driver.rs3
-rw-r--r--rust/kernel/drm/gem/shmem.rs3
3 files changed, 11 insertions, 5 deletions
diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
index 97e2b3de78bc..d4521ef8ed80 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -450,11 +450,15 @@ unsafe impl<T: drm::Driver> AlwaysRefCounted for Device<T> {
}
}
-impl<T: drm::Driver, C: DeviceContext> AsRef<device::Device> for Device<T, C> {
- fn as_ref(&self) -> &device::Device {
+impl<T: drm::Driver> AsRef<T::ParentDevice<device::Normal>> for Device<T> {
+ fn as_ref(&self) -> &T::ParentDevice<device::Normal> {
// SAFETY: `bindings::drm_device::dev` is valid as long as the DRM device itself is valid,
// which is guaranteed by the type invariant.
- unsafe { device::Device::from_raw((*self.as_raw()).dev) }
+ let dev = unsafe { device::Device::from_raw((*self.as_raw()).dev) };
+
+ // SAFETY: The DRM device was constructed in `UnregisteredDevice::new()` with a parent
+ // device of type `T::ParentDevice`, hence `dev` is contained in a `T::ParentDevice`.
+ unsafe { device::AsBusDevice::from_device(dev) }
}
}
diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs
index 3cda8dceb498..9ba2eba84191 100644
--- a/rust/kernel/drm/driver.rs
+++ b/rust/kernel/drm/driver.rs
@@ -170,7 +170,8 @@ impl<T: Driver> Registration<T> {
where
T: 'static,
{
- if drm.as_ref().as_raw() != dev.as_raw() {
+ let parent = drm.as_ref();
+ if parent.as_ref().as_raw() != dev.as_raw() {
return Err(EINVAL);
}
diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs
index e0ef47352e88..c1d82a04878b 100644
--- a/rust/kernel/drm/gem/shmem.rs
+++ b/rust/kernel/drm/gem/shmem.rs
@@ -264,7 +264,8 @@ impl<T: DriverObject> Object<T> {
&'a self,
dev: &'a device::Device<Bound>,
) -> Result<&'a scatterlist::SGTable> {
- if dev.as_raw() != self.dev().as_ref().as_raw() {
+ let parent = self.dev().as_ref();
+ if dev.as_raw() != parent.as_ref().as_raw() {
return Err(EINVAL);
}