[PATCH] rust: drm: ioctl: fix call to unsafe function
From: Vishal Moola (Fractile)
Date: Wed Nov 18 2026 - 08:32:50 EST
dev is created via an unsafe pointer dereference. Following the
convention, it should be wrapped in an unsafe block, but it is not.
The compiler only properly lints declare_drm_ioctls! when its defined
in the same crate as it expands in. Since upstream drivers are all
separate crates, this is silently ignored.
This has been present since commit 9a69570682b1 ("rust: drm: ioctl:
Add DRM ioctl abstraction").
Fixes: 9a69570682b1 ("rust: drm: ioctl: Add DRM ioctl abstraction")
Signed-off-by: Vishal Moola (Fractile) <vishal.moola@xxxxxxxxx>
--------------------
Based on drm-rust-next.
I encountered this while trying to build a rust driver out of tree. I
copied the macro to an out-of-tree crate so that our uapi can see the
same generated values without needing the generated bindings.
Ai has told me that this is because the macro expands from the same
crate its defined in, which sounds sensible.
I see:
error[E0133]: call to unsafe function `kernel::drm::Device::<T, C>::from_raw` is unsafe and requires unsafe block
--> driver/drm_ioctl.rs:77:33
|
77 | ... ::kernel::drm::device::Device::from_raw(raw_dev);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
Plus a number of warnings. But warnings are warnings so those are
whatever... Its all silently ignored upstream anyways, so doesn't
need a cc-stable either.
---
rust/kernel/drm/ioctl.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
index 64af9eacc306..5a2e2f4f0e91 100644
--- a/rust/kernel/drm/ioctl.rs
+++ b/rust/kernel/drm/ioctl.rs
@@ -152,7 +152,7 @@ macro_rules! declare_drm_ioctls {
// dev/file match the current driver these ioctls are being declared
// for, and it's not clear how to enforce this within the type system.
let dev: &$crate::drm::device::Device<_, $crate::drm::Ioctl> =
- $crate::drm::device::Device::from_raw(raw_dev);
+ unsafe { $crate::drm::device::Device::from_raw(raw_dev) };
// Type-inference anchor: the closure is never called but ties `dev`'s
// type to `$func`'s first parameter, which the compiler cannot infer
--
2.55.0