A KMS driver built on the minimal bindings added earlier in this series
needs the raw `struct drm_device` pointer to hand to the C KMS helpers
(drm_simple_display_pipe_init, drm_connector_init, the drm_atomic_helper_*
family, …) until safe Rust KMS abstractions cover them.

Make drm::Device::as_raw() pub, documented as a temporary escape hatch
with the caller's locking/lifetime obligations spelled out. This is the
part of the KMS work most likely to draw objections, so it is split into
its own patch: it can be dropped or reworked (e.g. replaced by narrow safe
wrappers, or kept pub(crate) behind per-helper methods) without disturbing
the feature flags and header bindings, which are useful on their own.

Signed-off-by: Mike Lothian <[email protected]>
Assisted-by: Claude:claude-opus-4-8 [Claude-Code]
---
 rust/kernel/drm/device.rs | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs
index 1d3319b713e2..c89c947b399a 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -296,7 +296,15 @@ pub struct Device<T: drm::Driver, C: DeviceContext = 
Registered> {
 }
 
 impl<T: drm::Driver, C: DeviceContext> Device<T, C> {
-    pub(crate) fn as_raw(&self) -> *mut bindings::drm_device {
+    /// Returns a raw pointer to the underlying `struct drm_device`.
+    ///
+    /// This is a temporary escape hatch for drivers that need to call C KMS 
helpers
+    /// not yet covered by safe Rust abstractions; it is expected to be 
removed (or
+    /// narrowed to `pub(crate)`) once the in-progress safe KMS layer can 
express
+    /// those operations. The returned pointer is valid for as long as `self` 
is
+    /// borrowed; the caller must uphold the locking and lifetime rules of 
every C
+    /// function it is passed to.
+    pub fn as_raw(&self) -> *mut bindings::drm_device {
         self.dev.get()
     }
 
-- 
2.54.0

Reply via email to