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, 04 Jun 2026 15:57:27 +1000 Message-ID: In-Reply-To: <20260530-rust_serdev-v8-1-2a95f1da22a7@posteo.de> References: <20260530-rust_serdev-v8-0-2a95f1da22a7@posteo.de> <20260530-rust_serdev-v8-1-2a95f1da22a7@posteo.de> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review This changes `devres::register` from returning `Result` (unit) to `Result<&= 'a T>`, allowing callers to obtain a reference to the devres-managed data. = The lifetime `'a` is tied to the `&'a Device` borrow, which ensures = the reference can't outlive the bound state (during which devres won't fire= ). The safety argument is sound: `data_ptr` is obtained from the `Pin>= ` heap allocation before the `KBox` is moved into `register_foreign`. The m= ove only transfers ownership of the heap pointer =E2=80=94 the allocation i= tself doesn't move, so `data_ptr` remains valid. After registration, devres= owns the allocation and keeps it alive until unbind. ```rust + let data_ptr =3D &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 unboun= d and data has not been + // dropped. Thus `data_ptr` is also valid for the lifetime of 'a. + .map(|()| unsafe { &*data_ptr }) ``` The existing callers (`cpufreq.rs`, `drm/driver.rs`) are updated to discard= the new return value with `?; Ok(())`, preserving their existing behavior.= Clean mechanical adaptation. Reviewed-by quality: **Good.** Already has Viresh Kumar's Ack. --- --- Generated by Claude Code Patch Reviewer