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: Mon, 09 Mar 2026 08:21:39 +1000 Message-ID: In-Reply-To: <20260306-rust_serdev-v2-1-e9b23b42b255@posteo.de> References: <20260306-rust_serdev-v2-0-e9b23b42b255@posteo.de> <20260306-rust_serdev-v2-1-e9b23b42b255@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 modifies `devres::register` to return `Result<&'a T>` instead of `Result`, allowing callers to get a reference to the devres-managed data. **Safety concern with the returned reference:** ```rust + let data_ptr = &raw const *data; + register_foreign(dev, data) + // 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. + .map(|()| unsafe { &*data_ptr }) ``` The safety argument is that `data_ptr` remains valid for `'a` because the `Device` reference lives that long. This works because `register_foreign` calls `data.into_foreign()` which consumes the `Pin>` without moving the inner `T` -- the data at `data_ptr` is still at the same address, now owned by the devres system. However, the safety comment should be more precise: it should mention that `into_foreign()` for `Pin>` extracts the raw pointer without moving the inner `T`, so `data_ptr` continues pointing to valid data as long as the devres action hasn't fired (which is guaranteed while the device remains bound). **Existing callers are updated correctly** -- `cpufreq.rs` and `drm/driver.rs` now discard the returned reference with `?; Ok(())`, preserving existing behavior. Overall this patch is acceptable with a minor safety comment refinement. --- --- Generated by Claude Code Patch Reviewer