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: devres: return reference in `devres::register` Date: Sun, 12 Apr 2026 08:55:16 +1000 Message-ID: In-Reply-To: <20260411-rust_serdev-v4-1-845e960c6627@posteo.de> References: <20260411-rust_serdev-v4-0-845e960c6627@posteo.de> <20260411-rust_serdev-v4-1-845e960c6627@posteo.de> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 Patch Review This patch changes `devres::register` from returning `Result` to `Result<&'a T>`, tying the returned reference's lifetime to the `&'a Device` argument. This is needed by patch 3 to access `PrivateData` after registration. **Soundness analysis**: The approach is sound. After `KBox::pin_init`, a raw pointer `data_ptr` is captured before `register_foreign` takes ownership of the `KBox`. The `KBox`'s heap allocation (and thus the pointed-to data) remains valid as long as devres hasn't cleaned it up. Since devres cleanup occurs at unbind time (after `remove`), and `Device` references cannot exist after unbind, tying the reference to `'a` is conservative and correct. However, the SAFETY comment could be improved: ```rust + // SAFETY: `dev` is valid for the lifetime of 'a. As long as there is a reference to + // `Device`, it is guaranteed that the device is not unbound and data has not been + // dropped. Thus `data_ptr` is also valid for the lifetime of 'a. ``` This should also mention that `data_ptr` was obtained from the `KBox` before `register_foreign` took ownership, and that `register_foreign` preserves the heap allocation (it transfers ownership to devres, it doesn't move the data). **Existing callers updated correctly**: `cpufreq.rs` and `drm/driver.rs` now discard the returned reference with `?;` + `Ok(())`. This is correct but slightly awkward -- a `register_void()` helper or a method that explicitly discards the reference would be cleaner. Minor style point, not blocking. --- Generated by Claude Code Patch Reviewer