diff mbox series

[07/11] rust/pl011: move pub callback decl to local scope

Message ID 20241024-rust-round-2-v1-7-051e7a25b978@linaro.org (mailing list archive)
State New
Headers show
Series Rust device model patches and misc cleanups | expand

Commit Message

Manos Pitsidianakis Oct. 24, 2024, 2:03 p.m. UTC
extern "C" callbacks in instance_init() do not need to be public. Move
them to local function scope instead.

No functional change.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
 rust/hw/char/pl011/src/device.rs | 104 +++++++++++++++++++--------------------
 1 file changed, 50 insertions(+), 54 deletions(-)
diff mbox series

Patch

diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 3aa055dee4b10866a624505a9d05ef1ab8182dce..75399fa6352916fa9cc24164af0ea2e20fe29399 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -219,6 +219,56 @@  unsafe fn instance_init(&mut self) {
 
 impl DeviceImpl for PL011State {
     fn realize(&mut self) {
+        /// # Safety
+        ///
+        /// We expect the FFI user of this function to pass a valid pointer, that has
+        /// the same size as [`PL011State`]. We also expect the device is
+        /// readable/writeable from one thread at any time.
+        unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int {
+            unsafe {
+                debug_assert!(!opaque.is_null());
+                let state = NonNull::new_unchecked(opaque.cast::<PL011State>());
+                state.as_ref().can_receive().into()
+            }
+        }
+        /// # Safety
+        ///
+        /// We expect the FFI user of this function to pass a valid pointer, that has
+        /// the same size as [`PL011State`]. We also expect the device is
+        /// readable/writeable from one thread at any time.
+        ///
+        /// The buffer and size arguments must also be valid.
+        unsafe extern "C" fn pl011_receive(
+            opaque: *mut core::ffi::c_void,
+            buf: *const u8,
+            size: core::ffi::c_int,
+        ) {
+            unsafe {
+                debug_assert!(!opaque.is_null());
+                let mut state = NonNull::new_unchecked(opaque.cast::<PL011State>());
+                if state.as_ref().loopback_enabled() {
+                    return;
+                }
+                if size > 0 {
+                    debug_assert!(!buf.is_null());
+                    state.as_mut().put_fifo(c_uint::from(buf.read_volatile()))
+                }
+            }
+        }
+
+        /// # Safety
+        ///
+        /// We expect the FFI user of this function to pass a valid pointer, that has
+        /// the same size as [`PL011State`]. We also expect the device is
+        /// readable/writeable from one thread at any time.
+        unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event: QEMUChrEvent) {
+            unsafe {
+                debug_assert!(!opaque.is_null());
+                let mut state = NonNull::new_unchecked(opaque.cast::<PL011State>());
+                state.as_mut().event(event)
+            }
+        }
+
         // SAFETY: self.char_backend has the correct size and alignment for a
         // CharBackend object, and its callbacks are of the correct types.
         unsafe {
@@ -611,60 +661,6 @@  pub fn update(&self) {
 
 /// # Safety
 ///
-/// We expect the FFI user of this function to pass a valid pointer, that has
-/// the same size as [`PL011State`]. We also expect the device is
-/// readable/writeable from one thread at any time.
-#[no_mangle]
-pub unsafe extern "C" fn pl011_can_receive(opaque: *mut c_void) -> c_int {
-    unsafe {
-        debug_assert!(!opaque.is_null());
-        let state = NonNull::new_unchecked(opaque.cast::<PL011State>());
-        state.as_ref().can_receive().into()
-    }
-}
-
-/// # Safety
-///
-/// We expect the FFI user of this function to pass a valid pointer, that has
-/// the same size as [`PL011State`]. We also expect the device is
-/// readable/writeable from one thread at any time.
-///
-/// The buffer and size arguments must also be valid.
-#[no_mangle]
-pub unsafe extern "C" fn pl011_receive(
-    opaque: *mut core::ffi::c_void,
-    buf: *const u8,
-    size: core::ffi::c_int,
-) {
-    unsafe {
-        debug_assert!(!opaque.is_null());
-        let mut state = NonNull::new_unchecked(opaque.cast::<PL011State>());
-        if state.as_ref().loopback_enabled() {
-            return;
-        }
-        if size > 0 {
-            debug_assert!(!buf.is_null());
-            state.as_mut().put_fifo(c_uint::from(buf.read_volatile()))
-        }
-    }
-}
-
-/// # Safety
-///
-/// We expect the FFI user of this function to pass a valid pointer, that has
-/// the same size as [`PL011State`]. We also expect the device is
-/// readable/writeable from one thread at any time.
-#[no_mangle]
-pub unsafe extern "C" fn pl011_event(opaque: *mut core::ffi::c_void, event: QEMUChrEvent) {
-    unsafe {
-        debug_assert!(!opaque.is_null());
-        let mut state = NonNull::new_unchecked(opaque.cast::<PL011State>());
-        state.as_mut().event(event)
-    }
-}
-
-/// # Safety
-///
 /// We expect the FFI user of this function to pass a valid pointer for `chr`.
 #[no_mangle]
 pub unsafe extern "C" fn pl011_create(