Re: [PATCH v5 1/8] rust: alloc: add Vec::zeroed method

"Alexandre Courbot" <[email protected]> Mon, 27 Jul 2026 17:06:08 +0900
Newsgroups dev.linux.lists.nova-gpu,dev.linux.lists.driver-core,org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On Sat Jul 11, 2026 at 8:04 AM JST, Timur Tabi wrote:
> Add a constructor for kernel Vec that allocates a vector of a given lengt=
h
> with all elements zero-initialized. Memory is allocated with the __GFP_ZE=
RO
> flag, matching the existing KBox::zeroed() pattern.
>
> Signed-off-by: Timur Tabi <[email protected]>
> ---
>  rust/kernel/alloc/kvec.rs | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
> index f7af62835aa8..4ca589919c1c 100644
> --- a/rust/kernel/alloc/kvec.rs
> +++ b/rust/kernel/alloc/kvec.rs
> @@ -9,6 +9,7 @@
>          Vmalloc,
>          VmallocPageIter, //
>      },
> +    flags::__GFP_ZERO,
>      layout::ArrayLayout,
>      AllocError,
>      Allocator,
> @@ -51,6 +52,8 @@
>      }, //
>  };
> =20
> +use pin_init::Zeroable;
> +
>  mod errors;
>  pub use self::errors::{InsertError, PushError, RemoveError};
> =20
> @@ -532,6 +535,23 @@ pub fn with_capacity(capacity: usize, flags: Flags) =
-> Result<Self, AllocError>
>          Ok(v)
>      }
> =20
> +    /// Creates a new [`Vec`] with `n` zero-initialized elements.
> +    ///
> +    /// New memory is allocated with `A` and the [`__GFP_ZERO`] flag.

Every other method I've looked at has an `# Examples` paragraph in its
doccomment, can you add a short example to this one as well?

With this, and Miguel's comment taken into account:

Reviewed-by: Alexandre Courbot <[email protected]>