lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240930233257.1189730-33-lyude@redhat.com>
Date: Mon, 30 Sep 2024 19:10:15 -0400
From: Lyude Paul <lyude@...hat.com>
To: dri-devel@...ts.freedesktop.org,
	rust-for-linux@...r.kernel.org
Cc: Asahi Lina <lina@...hilina.net>,
	Danilo Krummrich <dakr@...nel.org>,
	mcanal@...lia.com,
	airlied@...hat.com,
	zhiw@...dia.com,
	cjia@...dia.com,
	jhubbard@...dia.com,
	Miguel Ojeda <ojeda@...nel.org>,
	Alex Gaynor <alex.gaynor@...il.com>,
	Wedson Almeida Filho <wedsonaf@...il.com>,
	Boqun Feng <boqun.feng@...il.com>,
	Gary Guo <gary@...yguo.net>,
	Björn Roy Baron <bjorn3_gh@...tonmail.com>,
	Benno Lossin <benno.lossin@...ton.me>,
	Andreas Hindborg <a.hindborg@...sung.com>,
	Alice Ryhl <aliceryhl@...gle.com>,
	Trevor Gross <tmgross@...ch.edu>,
	linux-kernel@...r.kernel.org (open list)
Subject: [WIP RFC v2 32/35] rust: drm/kms: Add Device::num_crtcs()

A binding for checking drm_device.num_crtcs. We'll need this in a moment
for vblank support, since setting it up requires knowing the number of
CRTCs that a driver has initialized.

Signed-off-by: Lyude Paul <lyude@...hat.com>
---
 rust/kernel/drm/kms.rs | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/rust/kernel/drm/kms.rs b/rust/kernel/drm/kms.rs
index 3edd90bc0025a..d0745b44ba9b6 100644
--- a/rust/kernel/drm/kms.rs
+++ b/rust/kernel/drm/kms.rs
@@ -253,10 +253,27 @@ pub fn mode_config_lock(&self) -> ModeConfigGuard<'_, T> {
 
     /// Return the number of registered [`Plane`](plane::Plane) objects on this [`Device`].
     #[inline]
-    pub fn num_plane(&self) -> i32 {
-        // SAFETY: The only context which this could change is before registration, which must be
-        // single-threaded anyway - so it's safe to just read this value
-        unsafe { (*self.as_raw()).mode_config.num_total_plane }
+    pub fn num_plane(&self) -> u32 {
+        // SAFETY:
+        // * This can only be modified during the single-threaded context before registration, so
+        //   this is safe
+        // * num_total_plane could be >= 0, but no less - so casting to u32 is fine (and better to
+        //   prevent errors)
+        unsafe { (*self.as_raw()).mode_config.num_total_plane as u32 }
+    }
+
+    /// Return the number of registered CRTCs
+    /// TODO: while `num_crtc` is of i32, that type actually makes literally no sense here and just
+    /// causes problems and unecessary casts. Same for num_plane(). So, fix that at some point (we
+    /// will never get n < 0 anyway)
+    #[inline]
+    pub fn num_crtcs(&self) -> u32 {
+        // SAFETY:
+        // * This can only be modified during the single-threaded context before registration, so
+        //   this is safe
+        // * num_crtc could be >= 0, but no less - so casting to u32 is fine (and better to prevent
+        //   errors)
+        unsafe { (*self.as_raw()).mode_config.num_crtc as u32 }
     }
 }
 
-- 
2.46.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ