From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: rust: types: Add Ownable/Owned types
Date: Mon, 23 Feb 2026 06:08:50 +1000 [thread overview]
Message-ID: <review-patch1-20260220-unique-ref-v15-1-893ed86b06cc@kernel.org> (raw)
In-Reply-To: <20260220-unique-ref-v15-1-893ed86b06cc@kernel.org>
Patch Review
This patch introduces the core `Ownable` trait and `Owned<T>` type in a new `rust/kernel/owned.rs` file, and re-exports them from `types.rs`.
The design is clean. A few observations:
> +/// let result = NonNull::new(KBox::into_raw(result))
> +/// .expect("Raw pointer to newly allocation KBox is null, this should never happen.");
As Alice noted on the list, `KBox::into_raw` cannot return null (it returns `*mut T` from a valid allocation). A `KBox::into_raw_nonnull()` would be cleaner. This is fixed in patch 5 where the example switches to `.ok_or(ENOMEM)?`, but `ok_or(ENOMEM)` is also somewhat misleading since the null case is unreachable.
> +/// let foo = Foo::new().expect("Failed to allocate a Foo. This shouldn't happen");
Also fixed in patch 5 to use `?`.
> +/// # Invariants
> +///
> +/// - The [`Owned<T>`] has exclusive access to the instance of `T`.
> +/// - The instance of `T` will stay alive at least as long as the [`Owned<T>`] is alive.
Alice's suggestion to make the invariants more concrete (permission to call `release` once, permission for mutable access until `release`, value is pinned) would strengthen the safety reasoning throughout the series. In particular, the pinning guarantee is currently argued through "what APIs we expose" rather than as a type invariant, which makes each `Pin::new_unchecked` safety argument fragile.
> +impl<T: Ownable + Unpin> DerefMut for Owned<T> {
> + fn deref_mut(&mut self) -> &mut Self::Target {
> + // SAFETY: The type invariants guarantee that the object is valid, and that we can safely
> + // return a mutable reference to it.
> + unsafe { self.ptr.as_mut() }
As Alice noted, if "pinned" were a type invariant, this safety comment would naturally need to explain why unpinning is okay (because `T: Unpin`). Without the invariant, the safety reasoning is incomplete.
No bugs found in this patch; the issues are documentation quality.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-02-22 20:08 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 9:51 [PATCH v15 0/9] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-02-20 9:51 ` [PATCH v15 1/9] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-02-20 10:35 ` Alice Ryhl
2026-02-22 20:08 ` Claude Code Review Bot [this message]
2026-02-20 9:51 ` [PATCH v15 2/9] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-20 9:51 ` [PATCH v15 3/9] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-02-20 10:49 ` Alice Ryhl
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-20 9:51 ` [PATCH v15 4/9] rust: aref: update formatting of use statements Andreas Hindborg
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-20 9:51 ` [PATCH v15 5/9] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-20 9:51 ` [PATCH v15 6/9] rust: page: update formatting of `use` statements Andreas Hindborg
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-20 9:51 ` [PATCH v15 7/9] rust: page: convert to `Ownable` Andreas Hindborg
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-20 9:51 ` [PATCH v15 8/9] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-20 9:51 ` [PATCH v15 9/9] rust: page: add `from_raw()` Andreas Hindborg
2026-02-20 10:49 ` Alice Ryhl
2026-02-20 17:33 ` Miguel Ojeda
2026-02-20 17:50 ` Tamir Duberstein
2026-02-22 20:08 ` Claude review: " Claude Code Review Bot
2026-02-22 20:08 ` Claude review: rust: add `Ownable` trait and `Owned` type Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-02-24 11:17 [PATCH v16 00/10] " Andreas Hindborg
2026-02-24 11:17 ` [PATCH v16 02/10] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-02-27 5:11 ` 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-patch1-20260220-unique-ref-v15-1-893ed86b06cc@kernel.org \
--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