Re: [PATCH v5 12/19] rust: drm: Add RegistrationGuard for drm_dev_enter/exit critical sections

"Alexandre Courbot" <[email protected]>
Newsgroups dev.linux.lists.nova-gpu,dev.linux.lists.driver-core,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On Sun Jun 28, 2026 at 11:53 PM JST, Danilo Krummrich wrote:
<...>
> +impl<T: drm::Driver> Device<T, Ioctl> {
> +    /// Guard against the parent bus device being unbound.
> +    ///
> +    /// Returns a [`RegistrationGuard`] if the device has not been unplugged, [`None`] otherwise.
> +    ///
> +    /// While [`RegistrationGuard`] is held the parent device is guaranteed to be bound.
> +    #[must_use]
> +    pub fn registration_guard(&self) -> Option<RegistrationGuard<'_, T>> {
> +        let mut idx: i32 = 0;

Forgot this nit: since this is used as a parameter of a C function,
don't we prefer to use `ffi::c_int` as the type?

> +        // SAFETY: `self.as_raw()` is a valid pointer to a `struct drm_device`.
> +        if unsafe { bindings::drm_dev_enter(self.as_raw(), &mut idx) } {
> +            // INVARIANT:
> +            // - `idx` is the SRCU index from the successful `drm_dev_enter()` above.
> +            // - The parent bus device is bound: `drm_dev_enter()` succeeded, meaning
> +            //   `drm_dev_unplug()` has not completed; since it is only called from
> +            //   `Registration::drop()` during parent unbind, the parent is still bound.
> +            Some(RegistrationGuard {
> +                // SAFETY: See INVARIANT above; the `Registered` context invariant holds.
> +                dev: unsafe { self.assume_ctx() },
> +                idx,
> +                _not_send: NotThreadSafe,
> +            })
> +        } else {
> +            None
> +        }
> +    }
> +}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.