All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eliot Courtney" <ecourtney@nvidia.com>
Cc: gary@garyguo.net, dri-devel@lists.freedesktop.org,
	ojeda@kernel.org, "Danilo Krummrich" <dakr@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>
Subject: Re: [PATCH v3 1/8] rust: alloc: add Vec::try_push_init
Date: Mon, 28 Sep 2026 08:51:09 +0000	[thread overview]
Message-ID: <20260928085109.D44DD1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260928-b4-nvkv-v3-1-f04504c262c2@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] rust: missing #[inline] on try_push_init()
--

commit 5b0998c4906cb7b8fa1c27d53ac13078b73e0f91
Author: Eliot Courtney <ecourtney@nvidia.com>

rust: alloc: add Vec::try_push_init

This commit adds Vec::try_push_init for fallible initializers along
with a new PushInitError sum type. It allows the original initializer
to be returned to the caller if the allocation fails.

> diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
> index c7546b9da4fa3..a2b72a7779d9d 100644
> --- a/rust/kernel/alloc/kvec.rs
> +++ b/rust/kernel/alloc/kvec.rs
[ ... ]
> @@ -359,6 +367,49 @@ pub fn push(&mut self, v: T, flags: Flags) -> Result<(), AllocError> {
>          Ok(())
>      }
>  
> +    /// Appends an element to the back of the [`Vec`] instance by initializing it in place.
> +    ///
> +    /// Unlike [`Vec::push`], the initializer may be fallible. If the allocation fails, the
[ ... ]
> +    /// let mut v: KVec<Element> = KVec::new();
> +    /// v.try_push_init(Element::new(), GFP_KERNEL)?;
> +    /// assert!(v[0].buf.is_empty());
> +    /// # Ok::<(), Error>(())
> +    /// ```
> +    pub fn try_push_init<I, E>(&mut self, init: I, flags: Flags) -> Result<(), PushInitError<I, E>>
> +    where
> +        I: Init<T, E>,
> +    {

[Severity: Low]
Should try_push_init() be annotated with #[inline]?

The Rust subsystem coding guidelines recommend that small functions in
abstractions should be annotated with #[inline] to allow the compiler
to better optimize them.

> +        if self.reserve(1, flags).is_err() {
> +            return Err(PushInitError::AllocError(init));
> +        }
> +        // SAFETY: The call to `reserve` was successful, so there is at least one spare slot.
> +        unsafe { init.__init(self.spare_capacity_mut().as_mut_ptr().cast::<T>()) }
> +            .map_err(PushInitError::InitError)?;
> +        // SAFETY: The call to `__init` returned `Ok`, so the first spare slot now holds an
> +        // initialized `T`. The new length does not exceed the capacity because `reserve` ensured
> +        // the capacity is greater than the length by at least one.
> +        unsafe { self.inc_len(1) };
> +        Ok(())
> +    }
> +
>      /// Appends an element to the back of the [`Vec`] instance without reallocating.
>      ///
>      /// Fails if the vector does not have capacity for the new element.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260928-b4-nvkv-v3-0-f04504c262c2@nvidia.com?part=1

  reply	other threads:[~2026-09-28  8:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  8:42 [PATCH v3 0/8] gpu: nova-core: add NVKV codec Eliot Courtney
2026-09-28  8:42 ` [PATCH v3 1/8] rust: alloc: add Vec::try_push_init Eliot Courtney
2026-09-28  8:51   ` sashiko-bot [this message]
2026-10-06  5:52   ` Alexandre Courbot
2026-10-13  6:22     ` Eliot Courtney
2026-09-28  8:42 ` [PATCH v3 2/8] rust: alloc: add Vec::push_init Eliot Courtney
2026-09-28  8:52   ` sashiko-bot
2026-10-06  6:10   ` Alexandre Courbot
2026-09-28  8:42 ` [PATCH v3 3/8] rust: alloc: add ArrayVec Eliot Courtney
2026-09-28  8:51   ` sashiko-bot
2026-10-07  6:27   ` Alexandre Courbot
2026-10-13  9:13     ` Eliot Courtney
2026-09-28  8:42 ` [PATCH v3 4/8] gpu: nova-core: add NVKV encoder Eliot Courtney
2026-09-28  8:52   ` sashiko-bot
2026-10-07  3:43   ` Alexandre Courbot
2026-10-07  3:48     ` Alexandre Courbot
2026-10-07 11:33       ` John Hubbard
2026-10-07 11:56         ` Alexandre Courbot
2026-10-13  7:08           ` Eliot Courtney
2026-09-28  8:42 ` [PATCH v3 5/8] gpu: nova-core: add NVKV decoder Eliot Courtney
2026-09-28  8:52   ` sashiko-bot
2026-10-07  4:51   ` Alexandre Courbot
2026-10-13  8:26     ` Eliot Courtney
2026-09-28  8:42 ` [PATCH v3 6/8] gpu: nova-core: add NVKV typed encoding Eliot Courtney
2026-10-07  6:30   ` Alexandre Courbot
2026-09-28  8:42 ` [PATCH v3 7/8] gpu: nova-core: add NVKV typed decoding Eliot Courtney
2026-10-07  6:30   ` Alexandre Courbot
2026-10-07 12:05   ` Alexandre Courbot
2026-09-28  8:42 ` [PATCH v3 8/8] gpu: nova-core: add NVKV GSP_INIT schemas Eliot Courtney
2026-10-07 10:53   ` Alexandre Courbot

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=20260928085109.D44DD1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --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.