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
> + }
> + }
> +}