Rust for Linux List
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v4] rust: add a ring buffer implementation
Date: Tue, 01 Dec 2026 17:42:20 +0100	[thread overview]
Message-ID: <DN9JOBBO20ZC.1GHJZQT3KJ4B4@kernel.org> (raw)
In-Reply-To: <20261126-ringbuffer-v4-1-035b949fd239@kernel.org>

On Thu Nov 26, 2026 at 1:53 PM CET, Andreas Hindborg wrote:
> Add a fixed-capacity FIFO ring buffer. The implementation uses a circular
> buffer with head and tail pointers, providing constant-time push and pop
> operations.
>
> The module includes a few tests covering basic operations, wrap-around
> behavior, interleaved push/pop sequences, and edge cases such as
> single-capacity buffers.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>

NIT: Please add the "alloc:" prefix to the patch subject.

> +    pub fn new(capacity: usize, flags: Flags) -> Result<Self> {
> +        let slots = capacity.checked_add(1).ok_or(ENOMEM)?;
> +        let mut nodes = Vec::with_capacity(slots, flags)?;
> +
> +        for _ in 0..nodes.capacity() {

I think this should be 0..slots. When Option<T> is zero-sized, nodes.capacity()
returns usize::MAX, so the ring reports usize::MAX - 1 free slots instead of the
requested capacity.

> +            nodes.push_within_capacity(None)?;
> +        }
> +
> +        // INVARIANT: `nodes` holds `nodes.capacity() >= slots >= 1` slots, all
> +        // of which are vacant. Thus:
> +        // - `head` points at a vacant slot.
> +        // - `tail` need not point at an occupied slot, since the buffer is
> +        //   empty.
> +        // - The buffer is empty and `head == tail`.
> +        // - The buffer has at least one vacant slot.
> +        Ok(Self {
> +            nodes,
> +            head: 0,
> +            tail: 0,
> +        })
> +    }

[snip]

> +#[kunit_tests(rust_kernel_ringbuffer)]
> +mod tests {

This needs a separate Kconfig.

I did consider fixing this up on my end, but didn't want to make too many
changes without having it on the list.

I'm happy to still pick it up if you want to provide a quick diff (or simply a
v5).

Thanks,
Danilo

      reply	other threads:[~2026-12-01 16:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 12:53 [PATCH v4] rust: add a ring buffer implementation Andreas Hindborg
2026-12-01 16:42 ` Danilo Krummrich [this message]

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=DN9JOBBO20ZC.1GHJZQT3KJ4B4@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=work@onurozkan.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