dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: ojeda@kernel.org, gary@garyguo.net,
	dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v21 4/9] rust: rename `AlwaysRefCounted` to `RefCounted`.
Date: Thu, 10 Sep 2026 09:14:09 +0000	[thread overview]
Message-ID: <20260910091410.127391F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910-unique-ref-v21-4-e83257373062@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The `ForeignOwnable` implementation for `ARef<T>` unnecessarily requires `T: AlwaysRefCounted` instead of `T: RefCounted`.
- [Low] Conditional compilation failure in `fwctl.rs` and `serdev.rs` due to incomplete `AlwaysRefCounted` refactoring.
--

commit 6b87875ccf108a75e9bf33ac87bec77ac53590b0
Author: Oliver Mangold <oliver.mangold@pm.me>

rust: rename `AlwaysRefCounted` to `RefCounted`.

There are types where it may both be reference counted in some cases and
owned in others. In such cases, obtaining `ARef<T>` from `&T` would be
unsound as it allows creation of `ARef<T>` copy from `&Owned<T>`.

[ ... ]

[Severity: Low]
The tree-wide refactoring seems to have missed `rust/kernel/fwctl.rs` and
`rust/kernel/serdev.rs`, which still attempt to implement methods on
`AlwaysRefCounted`.

For example, in `rust/kernel/fwctl.rs`:

unsafe impl<T: Operations> AlwaysRefCounted for Device<T> {
    #[inline]
    fn inc_ref(&self) {
        // SAFETY: `self` holds a live reference.
        unsafe { bindings::fwctl_get(self.as_raw()) };
    }
    ...

Since `AlwaysRefCounted` is now an empty marker trait, will this cause
compilation failures when `CONFIG_FWCTL` or `CONFIG_SERIAL_DEV_BUS` are
enabled?

> diff --git a/rust/kernel/sync/aref.rs b/rust/kernel/sync/aref.rs
> index 9983ee0852486..215e7eb139fac 100644
> --- a/rust/kernel/sync/aref.rs
> +++ b/rust/kernel/sync/aref.rs
[ ... ]
> @@ -188,15 +201,15 @@ fn drop(&mut self) {
>  
>  impl<T, U> PartialEq<ARef<U>> for ARef<T>
>  where
> -    T: AlwaysRefCounted + PartialEq<U>,
> -    U: AlwaysRefCounted,
> +    T: RefCounted + PartialEq<U>,
> +    U: RefCounted,
>  {
>      #[inline]
>      fn eq(&self, other: &ARef<U>) -> bool {
>          T::eq(&**self, &**other)
>      }
>  }
> -impl<T: AlwaysRefCounted + Eq> Eq for ARef<T> {}
> +impl<T: RefCounted + Eq> Eq for ARef<T> {}
>  
>  // SAFETY: `into_foreign` returns a pointer from `NonNull::as_ptr`, so it's non-null. The
>  // `ARef` invariant guarantees that `ptr` points to a valid `T`, so it's aligned to `T`.

[Severity: Medium]
This trait bound appears to have been missed during the conversion. Just below
this context in `aref.rs` is:

unsafe impl<T: AlwaysRefCounted> ForeignOwnable for ARef<T> {

Does this unnecessarily limit the FFI usability of `ARef<T>` for types that
are `RefCounted` but not `AlwaysRefCounted`? Should this be updated to
`T: RefCounted` instead?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260910-unique-ref-v21-0-e83257373062@kernel.org?part=4

  reply	other threads:[~2026-09-10  9:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  9:00 [PATCH v21 0/9] rust: add `Ownable` trait and `Owned` type Andreas Hindborg
2026-09-10  9:00 ` [PATCH v21 1/9] rust: alloc: add `KBox::into_non_null` Andreas Hindborg
2026-09-10  9:05   ` sashiko-bot
2026-09-10  9:00 ` [PATCH v21 2/9] rust: types: Add Ownable/Owned types Andreas Hindborg
2026-09-10  9:06   ` sashiko-bot
2026-09-10  9:00 ` [PATCH v21 3/9] rust: implement `ForeignOwnable` for `Owned` Andreas Hindborg
2026-09-10  9:08   ` sashiko-bot
2026-09-10  9:00 ` [PATCH v21 4/9] rust: rename `AlwaysRefCounted` to `RefCounted` Andreas Hindborg
2026-09-10  9:14   ` sashiko-bot [this message]
2026-09-11  9:08   ` Alice Ryhl
2026-09-11 12:29     ` Gary Guo
2026-09-13  9:49       ` Andreas Hindborg
2026-09-10  9:00 ` [PATCH v21 5/9] rust: Add missing SAFETY documentation for `ARef` example Andreas Hindborg
2026-09-10  9:07   ` sashiko-bot
2026-09-11  9:09   ` Alice Ryhl
2026-09-10  9:00 ` [PATCH v21 6/9] rust: Add `OwnableRefCounted` Andreas Hindborg
2026-09-10  9:09   ` sashiko-bot
2026-09-11  9:19   ` Alice Ryhl
2026-09-11 13:25     ` Andreas Hindborg
2026-09-10  9:00 ` [PATCH v21 7/9] rust: page: convert to `AlwaysRefCounted` Andreas Hindborg
2026-09-10  9:18   ` sashiko-bot
2026-09-11 13:43   ` Alice Ryhl
2026-09-10  9:00 ` [PATCH v21 8/9] rust: page: add `from_raw()` Andreas Hindborg
2026-09-10  9:11   ` sashiko-bot
2026-09-10  9:00 ` [PATCH v21 9/9] rust: page: add `ExclusivePage` for race-free page access Andreas Hindborg
2026-09-10  9:14   ` sashiko-bot
2026-09-13  3:11   ` Matthew Wilcox
2026-09-13  9:36     ` Andreas Hindborg

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=20260910091410.127391F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).