summaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorBeata Michalska <beata.michalska@arm.com>2025-06-26 18:23:13 +0200
committerDanilo Krummrich <dakr@kernel.org>2025-07-21 17:53:07 +0200
commit94febfb5bcfb6ccf02283cc07bf58927c119afca (patch)
treee9e6b5cbccdda022de0624198546f3c9a0139f72 /rust/kernel
parentca2a6abdaee43808034cdb218428d2ed85fd3db8 (diff)
rust: drm: Drop the use of Opaque for ioctl arguments
With the Opaque<T>, the expectations are that Rust should not make any assumptions on the layout or invariants of the wrapped C types. That runs rather counter to ioctl arguments, which must adhere to certain data-layout constraints. By using Opaque<T>, ioctl handlers are forced to use unsafe code where none is actually needed. This adds needless complexity and maintenance overhead, brining no safety benefits. Drop the use of Opaque for ioctl arguments as that is not the best fit here. Signed-off-by: Beata Michalska <beata.michalska@arm.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20250626162313.2755584-1-beata.michalska@arm.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/drm/ioctl.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/rust/kernel/drm/ioctl.rs b/rust/kernel/drm/ioctl.rs
index fdec01c37168..af1bb29cf06d 100644
--- a/rust/kernel/drm/ioctl.rs
+++ b/rust/kernel/drm/ioctl.rs
@@ -83,7 +83,7 @@ pub mod internal {
///
/// ```ignore
/// fn foo(device: &kernel::drm::Device<Self>,
-/// data: &Opaque<uapi::argument_type>,
+/// data: &mut uapi::argument_type,
/// file: &kernel::drm::File<Self::File>,
/// ) -> Result<u32>
/// ```
@@ -138,9 +138,12 @@ macro_rules! declare_drm_ioctls {
// SAFETY: The ioctl argument has size `_IOC_SIZE(cmd)`, which we
// asserted above matches the size of this type, and all bit patterns of
// UAPI structs must be valid.
- let data = unsafe {
- &*(raw_data as *const $crate::types::Opaque<$crate::uapi::$struct>)
- };
+ // The `ioctl` argument is exclusively owned by the handler
+ // and guaranteed by the C implementation (`drm_ioctl()`) to remain
+ // valid for the entire lifetime of the reference taken here.
+ // There is no concurrent access or aliasing; no other references
+ // to this object exist during this call.
+ let data = unsafe { &mut *(raw_data.cast::<$crate::uapi::$struct>()) };
// SAFETY: This is just the DRM file structure
let file = unsafe { $crate::drm::File::from_raw(raw_file) };