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: Thu, 23 Apr 2026 09:21:38 +1000 Message-ID: In-Reply-To: <20260420-rust_serdev-v5-1-57e8ba0519f3@posteo.de> References: <20260420-rust_serdev-v5-0-57e8ba0519f3@posteo.de> <20260420-rust_serdev-v5-1-57e8ba0519f3@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 changes `devres::register` from returning `Result` to `Result<&'a T>`, tying the returned reference's lifetime to the `&'a Device` parameter. The SAFETY comment is the critical part: ```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. + .map(|()| unsafe { &*data_ptr }) ``` This is correct given the semantics of `Device` -- the Bound context guarantees the device hasn't been unbound, and devres resources are freed at unbind time. However, the reasoning depends entirely on the invariant that `Device` references cannot outlive the bound state. This is an important invariant for the devres subsystem maintainers to validate. The mechanical updates to `cpufreq.rs` and `drm/driver.rs` (adding `?; Ok(())`) are straightforward and correct -- existing callers that don't use the returned reference simply discard it. The doc example should also be updated to show the new return type: ```rust -/// devres::register(dev, Registration::new(), GFP_KERNEL) +/// devres::register(dev, Registration::new(), GFP_KERNEL)?; +/// Ok(()) ``` This is done correctly. Already has an `Acked-by` from Viresh Kumar, which is good since it touches cpufreq. --- Generated by Claude Code Patch Reviewer