From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796237334; b=KaNStm2WMG3xYw047YxaFVjmp14ic2cTu0ReRRw60WzZU3HBuov2dP8SQf2LQ7z2jxH0 VSg+gavnFPHSZpCv5ENyRxw7CPNrHKNKnW33mIMzjz4vFpYIcpClDRQZx/jqHDbD8WVIT qkCbWOFIiWbC6/8hiM+FpZUo3ziuTf01GryNujabG9Sl/+INLbAA9IdTG4hWSstj99YJ8 gQVpWKZLadXgCM9JheBaMCFCJrFFPFl8fhL+mSjnV/ngywg5qd9V2ZTsX5CQ8XC5E4E3k gtrFfeyQ3WaBJandnoicfBw8SDFRmGaEOeMeawG4pn26qCFJyssayDYa/FnRsBT2dPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796237334; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type; bh=fMRBD3P7JHOV0vqmhWLwRNIA2WZgt7D9+XEdPm0SL5o=; b=qD0HfLbcWBMAttnsporB5ed04zNSkMmKi6rHOOFElBcUhsGzQqID7Mc947xv8UGHNqRB oT7hokDs+t3DMFKDbXEZtta9/u4pU033DCMGvGSz0S/BZ7iApFJhMtigQMWmP8eUMt4UP qWTJwNs4ucd+eQ+16HkvqtSOl33kh8/1jXN0NVF/AX/sDI3sQtTpc+mQ2eeZAaF//jNUG UxgLshViXp++2mEU/O6bteFYaD0J8GIjK9Azw38IqOzySiSXNkp0SYCm1SQapsCUr+mPB ILbI5rkdlt6r04jlJd7mhn+siQbR8NrBi1QU8MNsTumORzxWCqMieZW/NNvSYaktl7g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=alAbhSU7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13364606A6AA; Wed, 2 Dec 2026 18:48:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=alAbhSU7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9D3C1F00893; Wed, 2 Dec 2026 18:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796237333; bh=fMRBD3P7JHOV0vqmhWLwRNIA2WZgt7D9+XEdPm0SL5o=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=alAbhSU79PJOuVWvIqIu6CkwnlqCiaSxATKWQOU9JYsgd3N/zuISGsHLqkKaTcIog 0YsUl257lo6+SGUi6Bk58WuPPlS47glk2GrlRq7zifwDFfO/+g1HMKPjhO6hXoFVcY RJ+vg1ikrO5dlfUFeR1S6sbIwdU04fXI3UlNZW6ulvS4/e9/hPWXH/WmHWx6BqNlRo 74LdBwjyvtCCkbA2gG9dE5hPXiKS3Qlq3LMP5M6Fg/35jitQgJYi8VBqC9+sYLqfVY 9/mnsIP2ByKcBCjaE1Py7r7GqVniUJEFanDQni0n8NNtxsertbtMYhY57ZQh2hVpHQ 4G3xQaobjH3YA== From: Andreas Hindborg To: Danilo Krummrich Cc: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , Benno Lossin , Alice Ryhl , Trevor Gross , Tamir Duberstein , Alexandre Courbot , Onur =?utf-8?Q?=C3=96zkan?= , Lorenzo Stoakes , Vlastimil Babka , "Liam R. Howlett" , Uladzislau Rezki , Daniel Almeida , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH v4] rust: add a ring buffer implementation In-Reply-To: References: <20261126-ringbuffer-v4-1-035b949fd239@kernel.org> Date: Wed, 02 Dec 2026 19:48:42 +0100 Message-ID: <8733sfselx.fsf@t14s.mail-host-address-is-not-set> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain "Danilo Krummrich" writes: > 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 > > NIT: Please add the "alloc:" prefix to the patch subject. > >> + pub fn new(capacity: usize, flags: Flags) -> Result { >> + 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 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). I'll ship a v5 today. Best regards, Andreas Hindborg