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=1796143346; b=OYUa+PrcZsEv3aaJCtp0Af6h7eDJ15FdgoqvRMK+VpqkQD4zllskI1UlGvtZw33pYD4K GOqFht2/YUb44BRvBnFsNIyPZxwStJW0z8C3W4Mam+iC3yvkHhgB4+XC9yBt1oIPo9d8o gkAT/tRNWYteCh5OXYAagxK+Hx4iAuxqEXpPFhTkQGbeHqT2/eEy29rmpG8MFTOcz/TLe cfwUgXJpMChT0FU2enutt9kJhOSvsSpfsZLpeZEk1DvLLCfMsjAp6e/nZAf4MhE1WoIwH VOIvt4LZ/raOg1PY9varhZwLB7JR2VYjTUX4gwLvsXX4ywl4SG+wnYCiEPeu8rOvacw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143346; h=Received:DKIM-Signature:Mime-Version:Content-Transfer-Encoding: Content-Type:Date:Message-Id:Cc:To:From:Subject:References: In-Reply-To; bh=m6rC1x+LmDaTyCaM8OIJKEQIC8w7KRX7X0ISFkp6y1U=; b=CwIyzSaIfOihydzdBe+DTCwsXHfHauQUNVwMoZ5VxKHZpCXq+uzcMnXx47bBve670sNr jqfh5n9YubrJxbivhXvjqAEgNkYuqQbSjLC2d/9nBeEzmgRqCJ5aWZ6jwja0AGJonsmHa zBx4o73F4l8EgvzvioevzcLn1tyZroxkveChJvtpgP/zQzarQ69cHxM+FEGMZ7lg0z+Lc 5RlYdNcKkuN1iR1SkHat5ffVmC8Hf2+FOMjEr6L010XA+15PIU3OLi3GnXk78xVXlcCVF ShaoMYKOvr/LFOG2k3nqV5REyoB1QC83jF4tpZPCWMS8Ut2fVczN41kX+MFdTSYeR6g== 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=EXK6Y7X6; 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 E5132606A31A; Tue, 1 Dec 2026 16:42:25 +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=EXK6Y7X6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0ADE31F00893; Tue, 1 Dec 2026 16:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796143345; bh=m6rC1x+LmDaTyCaM8OIJKEQIC8w7KRX7X0ISFkp6y1U=; h=Date:Cc:To:From:Subject:References:In-Reply-To; b=EXK6Y7X6DQkEu1di+fXpOekt/i4vjUFW7ntDtlRzseZxd+JIb7mQUTNJWXI53amcI LolrRTsxv8UORhOZz39JWo87VeIuOfZQ1cDRThrjE76WXPh1jpNWie/ftz8O47eBP0 nh8Am8InNGHC1eR/8MkhtoeiiC1mYDGjyKdSZ7sk+0r0nZ8EJHSxAThH+lQnQGDF1A EcWFwcrnx7B2SZUCz/BuILzxJbddVVwCOy9nFswN9XoHgzYBCc1lggJqQshfNXD8x5 6lMu17QOuweEp99Bm3Liha9BJHbr9E6EY8hJ4ocbCeHeVpJimc428h8wu3j9TZxMqv 6/bq0kmgX4ezA== X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Dec 2026 17:42:20 +0100 Message-Id: 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" , =?utf-8?q?Onur_=C3=96zkan?= , "Lorenzo Stoakes" , "Vlastimil Babka" , "Liam R. Howlett" , "Uladzislau Rezki" , "Daniel Almeida" , , To: "Andreas Hindborg" From: "Danilo Krummrich" Subject: Re: [PATCH v4] rust: add a ring buffer implementation References: <20261126-ringbuffer-v4-1-035b949fd239@kernel.org> 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 NIT: Please add the "alloc:" prefix to the patch subject. > + pub fn new(capacity: usize, flags: Flags) -> Result { > + let slots =3D capacity.checked_add(1).ok_or(ENOMEM)?; > + let mut nodes =3D Vec::with_capacity(slots, flags)?; > + > + for _ in 0..nodes.capacity() { I think this should be 0..slots. When Option is zero-sized, nodes.capaci= ty() returns usize::MAX, so the ring reports usize::MAX - 1 free slots instead o= f the requested capacity. > + nodes.push_within_capacity(None)?; > + } > + > + // INVARIANT: `nodes` holds `nodes.capacity() >=3D slots >=3D 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 =3D=3D 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 simpl= y a v5). Thanks, Danilo