From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: rust: device: generalize drvdata methods over ForLt Date: Thu, 07 May 2026 13:02:04 +1000 Message-ID: In-Reply-To: <20260506215113.851360-4-dakr@kernel.org> References: <20260506215113.851360-1-dakr@kernel.org> <20260506215113.851360-4-dakr@kernel.org> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Patch Review This is the critical patch that changes how driver private data is stored/retrieved. In `set_drvdata`: ```rust pub fn set_drvdata<'bound, F: ForLt>( &self, data: impl PinInit, Error>, ) -> Result { let data = KBox::pin_init(data, GFP_KERNEL)?; let ptr = KBox::into_raw(unsafe { Pin::into_inner_unchecked(data) }); unsafe { bindings::dev_set_drvdata(self.as_raw(), ptr.cast()) }; Ok(()) } ``` The key insight is that `F::Of<'bound>` and `F::Of<'static>` have identical layout (lifetimes are erased at runtime), so storing via raw pointer is sound. The `Pin::into_inner_unchecked` is safe because we're immediately converting to a raw pointer. In `drvdata_unchecked`: ```rust let pinned: Pin<&F::Of<'static>> = unsafe { Pin::>>::borrow(ptr.cast()) }; unsafe { Pin::new_unchecked(F::cast_ref(pinned.get_ref())) } ``` This reconstructs a `Pin<&F::Of<'_>>` by first borrowing as `'static`, then shortening the lifetime via `ForLt::cast_ref`. The `Pin::new_unchecked` is justified because the data was pinned when stored and lifetime shortening doesn't affect pinning. **Minor:** The transition from `ForeignOwnable`-based storage (`into_foreign`/`from_foreign`/`borrow`) to raw `KBox::into_raw`/`KBox::from_raw` changes the abstraction level. This is fine but means the `ForeignOwnable` import for `Pin>` is likely now unused. The diff doesn't show whether that import is cleaned up. --- Generated by Claude Code Patch Reviewer