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: dma: use pointer projection infra for `dma_{read,write}` macro Date: Tue, 10 Mar 2026 12:10:28 +1000 Message-ID: In-Reply-To: <20260309-drm-rust-next-v4-3-4ef485b19a4c@proton.me> References: <20260309-drm-rust-next-v4-0-4ef485b19a4c@proton.me> <20260309-drm-rust-next-v4-3-4ef485b19a4c@proton.me> 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 is a significant API change that improves both soundness and ergonomic= s. **Soundness fixes**: The commit message correctly identifies two soundness = issues in the old macros: reliance on absence of `Deref` implementations, a= nd lack of protection against `#[repr(packed)]` misaligned accesses. The ne= w macros address both via the projection infrastructure. **New `as_ptr` / `as_mut_ptr` methods**: These return `*const [T]` / `*mut = [T]` fat pointers, which is the correct type to feed into the projection in= frastructure. However, note that `as_mut_ptr` takes `&self` (not `&mut self= `): ```rust pub fn as_mut_ptr(&self) -> *mut [T] { core::ptr::slice_from_raw_parts_mut(self.cpu_addr.as_ptr(), self.count) } ``` This is intentional since DMA coherent memory is shared with hardware and t= he `CoherentAllocation` type already provides interior mutability semantics= through its `field_write` safety contract. But it might be worth a brief c= omment explaining why `&self` returns a `*mut` pointer. **`dma_write!` macro parsing**: The recursive `@parse` rules to separate th= e projection tokens from the trailing value expression are necessary becaus= e the macro needs to split `[0]?.ptes.field, value` at the right comma. The= approach is correct. **Removal of `item_from_index`**: Good cleanup =E2=80=94 this method's boun= ds-checking is now handled by the projection infrastructure. **Sample code changes**: The refactoring to move DMA read checks from `Pinn= edDrop` into a separate `check_dma` method is cleaner: ```rust fn check_dma(&self) -> Result { for (i, value) in TEST_VALUES.into_iter().enumerate() { let val0 =3D kernel::dma_read!(self.ca, [i]?.h); ... } Ok(()) } ``` Note that the `dma_read!` macro no longer returns `Result` =E2=80=94 it ret= urns the value directly (with `?` propagating index errors). The old code h= ad `assert!(val0.is_ok())` followed by `if let Ok(val0) =3D val0 { ... }` w= hich was redundant; the new code is much cleaner. --- Generated by Claude Code Patch Reviewer