All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: linux-pci@vger.kernel.org, ojeda@kernel.org,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v20 6/8] rust: Add missing SAFETY documentation for `ARef` example
Date: Mon, 24 Aug 2026 11:25:06 +0000	[thread overview]
Message-ID: <20260824112506.A52091F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260824-unique-ref-v20-6-490735672187@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Mismatched and incorrect SAFETY comments in the `ARef::into_raw` doctest, alongside an unsound `RefCounted` trait implementation.
--

--- Patch [6]: [PATCH v20 6/8] rust: Add missing SAFETY documentation for `ARef` example ---
commit 1891eeeba9b2ed0af7d99f9518dcd85941d2518c
Author: Oliver Mangold <oliver.mangold@pm.me>

rust: Add missing SAFETY documentation for ARef example

This commit updates the rustdoc example for ARef to replace the "TODO"
SAFETY comments with explanations for the RefCounted trait implementation
and ARef::from_raw call.

> diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs
> --- a/rust/kernel/sync/aref.rs
> +++ b/rust/kernel/sync/aref.rs
> @@ -142,7 +142,9 @@ pub unsafe fn from_raw(ptr: NonNull<T>) -> Self {
>      ///
>      /// struct Empty {}
>      ///
> -    /// # // SAFETY: TODO.
> +    /// // SAFETY: The `RefCounted` implementation for `Empty` does not count references and never
> +    /// // frees the underlying object. Thus we can act as owning an increment on the refcount for
> +    /// // the object that we pass to the newly created `ARef`.
>      /// unsafe impl RefCounted for Empty {
>      ///     fn inc_ref(&self) {}
>      ///     unsafe fn dec_ref(_obj: NonNull<Self>) {}

[Severity: Low]
Are the SAFETY comments for the trait implementation and from_raw call swapped
here?

This comment justifies the caller requirement of ARef::from_raw (owning an
increment), rather than the trait's own safety requirement (that increments keep
the object alive).

Additionally, does this explanation overlook the fact that the stack-allocated
variable data will eventually go out of scope and be freed?

If a developer copies this pattern and calls ARef::clone(), could it extend the
pointer's lifetime beyond the stack frame without keeping the underlying object
alive?

> @@ -150,7 +152,7 @@ pub unsafe fn from_raw(ptr: NonNull<T>) -> Self {
>      ///
>      /// let mut data = Empty {};
>      /// let ptr = NonNull::<Empty>::new(&mut data).unwrap();
> -    /// # // SAFETY: TODO.
> +    /// // SAFETY: We keep `data` around longer than the `ARef`.
>      /// let data_ref: ARef<Empty> = unsafe { ARef::from_raw(ptr) };

[Severity: Low]
Does this comment justify the object's lifetime (which is the responsibility of
the RefCounted trait implementation) instead of addressing the specific safety
requirement of ARef::from_raw?

The from_raw method requires the caller to own a reference count increment.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824-unique-ref-v20-0-490735672187@kernel.org?part=6

  reply	other threads:[~2026-08-24 11:25 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 11:17 [PATCH v20 0/8] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-08-24 11:17 ` [PATCH v20 1/8] rust: alloc: add `KBox::into_non_null` Andreas Hindborg
2026-08-24 11:22   ` sashiko-bot
2026-08-25 13:01   ` Danilo Krummrich
2026-08-24 11:17 ` [PATCH v20 2/8] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-08-24 11:27   ` sashiko-bot
2026-08-24 11:17 ` [PATCH v20 3/8] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-08-24 11:24   ` sashiko-bot
2026-08-24 11:17 ` [PATCH v20 4/8] rust: page: convert to `Ownable` Andreas Hindborg
2026-08-24 11:26   ` sashiko-bot
2026-08-25 13:20   ` [PATCH v20 4/8] rust: page: convert to `Ownable`' Alice Ryhl
2026-09-06 13:02     ` Gary Guo
2026-09-07  9:24       ` Alice Ryhl
2026-09-07 12:38         ` Andreas Hindborg
2026-09-07 13:31           ` Alice Ryhl
2026-09-07 13:58             ` Andreas Hindborg
2026-09-07 14:06               ` Alice Ryhl
2026-09-08  8:46                 ` Andreas Hindborg
2026-09-08  9:18                   ` Alice Ryhl
2026-09-08 12:10                     ` Andreas Hindborg
2026-08-25 13:34   ` [PATCH v20 4/8] rust: page: convert to `Ownable` Danilo Krummrich
2026-08-24 11:17 ` [PATCH v20 5/8] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-08-24 11:28   ` sashiko-bot
2026-08-24 12:26   ` Uwe Kleine-König
2026-08-24 11:17 ` [PATCH v20 6/8] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-08-24 11:25   ` sashiko-bot [this message]
2026-08-24 11:36   ` Miguel Ojeda
2026-08-26  9:29     ` Andreas Hindborg
2026-09-03 13:28       ` Miguel Ojeda
2026-08-24 11:17 ` [PATCH v20 7/8] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-08-24 11:28   ` sashiko-bot
2026-08-25 13:16   ` Danilo Krummrich
2026-08-25 13:37     ` Gary Guo
2026-08-24 11:18 ` [PATCH v20 8/8] rust: page: add `from_raw()` Andreas Hindborg
2026-08-24 11:25   ` sashiko-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=20260824112506.A52091F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.