From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: rust/drm: Don't setup private driver data until registration
Date: Sun, 22 Mar 2026 03:17:22 +1000 [thread overview]
Message-ID: <review-patch3-20260320233645.950190-4-lyude@redhat.com> (raw)
In-Reply-To: <20260320233645.950190-4-lyude@redhat.com>
Patch Review
**Critical concern — error path for data initialization failure:**
```rust
fn new(
drm: drm::UnregisteredDevice<T>,
data: impl PinInit<T::Data, Error>,
flags: usize,
) -> Result<Self> {
unsafe { data.__pinned_init(drm.0.data.get().cast()) }?;
drm.data_is_init.store(true, Ordering::Relaxed);
to_result(unsafe { bindings::drm_dev_register(drm.as_raw(), flags) })?;
```
If `data.__pinned_init()` succeeds but `drm_dev_register()` fails, the function returns `Err`, which drops `drm` (the `UnregisteredDevice`). This will eventually call `release()`, which checks `data_is_init` and will drop the initialized data — so this is correct.
However, if `data.__pinned_init()` itself fails, the `?` propagates the error and `drm` is dropped. At this point `data_is_init` is still `false`, so the data won't be double-dropped. But we need to verify that the partially-initialized data from a failed `__pinned_init` is properly handled. By the `PinInit` contract, if `__pinned_init` returns an error, the memory is left in a valid-to-deallocate state (i.e., not needing drop). So this is fine.
**`pub(super)` on `UnregisteredDevice` tuple field:**
```rust
pub struct UnregisteredDevice<T: drm::Driver>(pub(super) ARef<Device<T, Uninit>>, NotThreadSafe);
```
Making the inner `ARef` `pub(super)` is needed for the `drm.0.data.get().cast()` access in `driver.rs`. This is acceptable since both files are in the `drm` module, but it does weaken the encapsulation of `UnregisteredDevice`.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-03-21 17:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 23:34 [PATCH v6 0/5] Introduce DeviceContext Lyude Paul
2026-03-20 23:34 ` [PATCH v6 1/5] rust/drm: Fix potential drop of uninitialized driver data Lyude Paul
2026-03-21 17:17 ` Claude review: " Claude Code Review Bot
2026-03-20 23:34 ` [PATCH v6 2/5] rust/drm: Introduce DeviceContext Lyude Paul
2026-03-21 17:17 ` Claude review: " Claude Code Review Bot
2026-03-20 23:34 ` [PATCH v6 3/5] rust/drm: Don't setup private driver data until registration Lyude Paul
2026-03-21 17:17 ` Claude Code Review Bot [this message]
2026-03-20 23:34 ` [PATCH v6 4/5] rust/drm/gem: Add DriverAllocImpl type alias Lyude Paul
2026-03-21 17:17 ` Claude review: " Claude Code Review Bot
2026-03-20 23:34 ` [PATCH v6 5/5] rust/drm/gem: Use DeviceContext with GEM objects Lyude Paul
2026-03-21 17:17 ` Claude review: " Claude Code Review Bot
2026-03-21 17:17 ` Claude review: Introduce DeviceContext 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-20260320233645.950190-4-lyude@redhat.com \
--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