public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
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	[thread overview]
Message-ID: <review-patch3-20260309-drm-rust-next-v4-3-4ef485b19a4c@proton.me> (raw)
In-Reply-To: <20260309-drm-rust-next-v4-3-4ef485b19a4c@proton.me>

Patch Review

This is a significant API change that improves both soundness and ergonomics.

**Soundness fixes**: The commit message correctly identifies two soundness issues in the old macros: reliance on absence of `Deref` implementations, and lack of protection against `#[repr(packed)]` misaligned accesses. The new 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 infrastructure. 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 the `CoherentAllocation` type already provides interior mutability semantics through its `field_write` safety contract. But it might be worth a brief comment explaining why `&self` returns a `*mut` pointer.

**`dma_write!` macro parsing**: The recursive `@parse` rules to separate the projection tokens from the trailing value expression are necessary because the macro needs to split `[0]?.ptes.field, value` at the right comma. The approach is correct.

**Removal of `item_from_index`**: Good cleanup — this method's bounds-checking is now handled by the projection infrastructure.

**Sample code changes**: The refactoring to move DMA read checks from `PinnedDrop` 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 = kernel::dma_read!(self.ca, [i]?.h);
        ...
    }
    Ok(())
}
```

Note that the `dma_read!` macro no longer returns `Result` — it returns the value directly (with `?` propagating index errors). The old code had `assert!(val0.is_ok())` followed by `if let Ok(val0) = val0 { ... }` which was redundant; the new code is much cleaner.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-03-10  2:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-09 16:34 [PATCH v4 0/4] Fixes the stack overflow Tim Kovalenko via B4 Relay
2026-03-09 16:34 ` [PATCH v4 1/4] rust: ptr: add `KnownSize` trait to support DST size info extraction Tim Kovalenko via B4 Relay
2026-03-10  2:10   ` Claude review: " Claude Code Review Bot
2026-03-09 16:34 ` [PATCH v4 2/4] rust: ptr: add projection infrastructure Tim Kovalenko via B4 Relay
2026-03-10  2:10   ` Claude review: " Claude Code Review Bot
2026-03-09 16:34 ` [PATCH v4 3/4] rust: dma: use pointer projection infra for `dma_{read,write}` macro Tim Kovalenko via B4 Relay
2026-03-10  2:10   ` Claude Code Review Bot [this message]
2026-03-09 16:34 ` [PATCH v4 4/4] gpu: nova-core: fix stack overflow in GSP memory allocation Tim Kovalenko via B4 Relay
2026-03-09 19:40   ` Danilo Krummrich
2026-03-09 22:40     ` Miguel Ojeda
2026-03-10  1:40   ` Alexandre Courbot
2026-03-10  1:51     ` Gary Guo
2026-03-10  2:10   ` Claude review: " Claude Code Review Bot
2026-03-09 17:00 ` [PATCH v4 0/4] Fixes the stack overflow Danilo Krummrich
2026-03-10  2:10 ` Claude review: " Claude Code Review Bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=review-patch3-20260309-drm-rust-next-v4-3-4ef485b19a4c@proton.me \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox