The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] rust: drm: ioctl: fix call to unsafe function
@ 2026-11-18 13:32 Vishal Moola (Fractile)
  2026-11-18 15:29 ` Alice Ryhl
  2026-11-18 16:17 ` Danilo Krummrich
  0 siblings, 2 replies; 5+ messages in thread
From: Vishal Moola (Fractile) @ 2026-11-18 13:32 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, David Airlie, Simona Vetter,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Daniel Almeida,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan, Asahi Lina,
	Lyude Paul
  Cc: dri-devel, rust-for-linux, linux-kernel, Vishal Moola (Fractile)

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@gmail.com>

--------------------
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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-18 16:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 13:32 [PATCH] rust: drm: ioctl: fix call to unsafe function Vishal Moola (Fractile)
2026-11-18 15:29 ` Alice Ryhl
2026-11-18 15:55   ` Vishal Moola (Fractile)
2026-11-18 16:17 ` Danilo Krummrich
2026-11-18 16:57   ` Vishal Moola (Fractile)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox