* [PATCH] rust: alloc: add doc test for `Vec::extend_with` and fix comment
@ 2026-04-25 6:08 Hsiu Che Yu
2026-04-25 6:32 ` Alexandre Courbot
[not found] ` <cover.1777111268.git.yu.whisper.personal@gmail.com>
0 siblings, 2 replies; 13+ messages in thread
From: Hsiu Che Yu @ 2026-04-25 6:08 UTC (permalink / raw)
To: rust-for-linux
Cc: Hsiu Che Yu, Danilo Krummrich, Lorenzo Stoakes, Vlastimil Babka,
Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, open list
Add a doc test for `Vec::extend_with` demonstrating basic usage and the
zero-length case.
Also fix an incorrect operator in the SAFETY comment, changing `<` to `<=`,
since `Vec::reserve` guarantees capacity for exactly n additional elements,
so the equal case should be included.
Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
---
rust/kernel/alloc/kvec.rs | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index ac8d6f763ae8..fc4bf0a7934d 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -737,6 +737,24 @@ pub fn retain(&mut self, mut f: impl FnMut(&mut T) -> bool) {
impl<T: Clone, A: Allocator> Vec<T, A> {
/// Extend the vector by `n` clones of `value`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// let mut v = KVec::new();
+ /// v.push(1, GFP_KERNEL)?;
+ ///
+ /// v.extend_with(3, 5, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5]);
+ ///
+ /// v.extend_with(2, 8, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
+ ///
+ /// v.extend_with(0, 3, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
+ ///
+ /// # Ok::<(), Error>(())
+ /// ```
pub fn extend_with(&mut self, n: usize, value: T, flags: Flags) -> Result<(), AllocError> {
if n == 0 {
return Ok(());
@@ -754,7 +772,7 @@ pub fn extend_with(&mut self, n: usize, value: T, flags: Flags) -> Result<(), Al
spare[n - 1].write(value);
// SAFETY:
- // - `self.len() + n < self.capacity()` due to the call to reserve above,
+ // - `self.len() + n <= self.capacity()` due to the call to reserve above,
// - the loop and the line above initialized the next `n` elements.
unsafe { self.inc_len(n) };
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH] rust: alloc: add doc test for `Vec::extend_with` and fix comment
2026-04-25 6:08 [PATCH] rust: alloc: add doc test for `Vec::extend_with` and fix comment Hsiu Che Yu
@ 2026-04-25 6:32 ` Alexandre Courbot
2026-04-25 6:53 ` Hsiu Che Yu
[not found] ` <cover.1777111268.git.yu.whisper.personal@gmail.com>
1 sibling, 1 reply; 13+ messages in thread
From: Alexandre Courbot @ 2026-04-25 6:32 UTC (permalink / raw)
To: Hsiu Che Yu
Cc: rust-for-linux, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
Hello Hsiu,
On Sat Apr 25, 2026 at 3:08 PM JST, Hsiu Che Yu wrote:
> Add a doc test for `Vec::extend_with` demonstrating basic usage and the
> zero-length case.
>
> Also fix an incorrect operator in the SAFETY comment, changing `<` to `<=`,
> since `Vec::reserve` guarantees capacity for exactly n additional elements,
> so the equal case should be included.
As per the guidelines [1], "A patch should do one thing and one thing
only".
These should be two separate patches.
[1] https://kernelnewbies.org/PatchSeries
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH] rust: alloc: add doc test for `Vec::extend_with` and fix comment
2026-04-25 6:32 ` Alexandre Courbot
@ 2026-04-25 6:53 ` Hsiu Che Yu
2026-04-25 7:20 ` Alexandre Courbot
0 siblings, 1 reply; 13+ messages in thread
From: Hsiu Che Yu @ 2026-04-25 6:53 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Hsiu Che Yu, rust-for-linux, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
Hi Alexandre,
On Sat, Apr 25, 2026 at 03:32:57PM +0900, Alexandre Courbot wrote:
>As per the guidelines [1], "A patch should do one thing and one thing
>only".
>
>These should be two separate patches.
You're right, my apologies for bundling two unrelated changes together.
Should I send these as two separate v2 patches, or start fresh with two new patch series?
Thanks,
Hsiu
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] rust: alloc: add doc test for `Vec::extend_with` and fix comment
2026-04-25 6:53 ` Hsiu Che Yu
@ 2026-04-25 7:20 ` Alexandre Courbot
2026-04-25 9:00 ` Hsiu Che Yu
0 siblings, 1 reply; 13+ messages in thread
From: Alexandre Courbot @ 2026-04-25 7:20 UTC (permalink / raw)
To: Hsiu Che Yu
Cc: rust-for-linux, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
On Sat Apr 25, 2026 at 3:53 PM JST, Hsiu Che Yu wrote:
> Hi Alexandre,
>
> On Sat, Apr 25, 2026 at 03:32:57PM +0900, Alexandre Courbot wrote:
>>As per the guidelines [1], "A patch should do one thing and one thing
>>only".
>>
>>These should be two separate patches.
>
> You're right, my apologies for bundling two unrelated changes together.
>
> Should I send these as two separate v2 patches, or start fresh with two new patch series?
A v2 sounds appropriate since this it is the same work, only rearranged a bit.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] rust: alloc: add doc test for `Vec::extend_with` and fix comment
2026-04-25 7:20 ` Alexandre Courbot
@ 2026-04-25 9:00 ` Hsiu Che Yu
0 siblings, 0 replies; 13+ messages in thread
From: Hsiu Che Yu @ 2026-04-25 9:00 UTC (permalink / raw)
To: Alexandre Courbot
Cc: Hsiu Che Yu, rust-for-linux, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
On Sat, Apr 25, 2026 at 04:20:22PM +0900, Alexandre Courbot wrote:
>A v2 sounds appropriate since this it is the same work, only rearranged a bit.
Got it. I will send out v2 shortly.
thanks,
Hsiu
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <cover.1777111268.git.yu.whisper.personal@gmail.com>]
* [PATCH v2 1/2] rust: alloc: add doc test for `Vec::extend_with`
[not found] ` <cover.1777111268.git.yu.whisper.personal@gmail.com>
@ 2026-04-25 10:16 ` Hsiu Che Yu
2026-04-26 3:58 ` Alexandre Courbot
2026-04-25 10:16 ` [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment Hsiu Che Yu
1 sibling, 1 reply; 13+ messages in thread
From: Hsiu Che Yu @ 2026-04-25 10:16 UTC (permalink / raw)
To: rust-for-linux
Cc: Alexandre Courbot, Hsiu Che Yu, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
Add a doc test for `Vec::extend_with` demonstrating basic usage and the
zero-length case.
Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
---
rust/kernel/alloc/kvec.rs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index ac8d6f763ae8..408a51ad3623 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -737,6 +737,24 @@ pub fn retain(&mut self, mut f: impl FnMut(&mut T) -> bool) {
impl<T: Clone, A: Allocator> Vec<T, A> {
/// Extend the vector by `n` clones of `value`.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// let mut v = KVec::new();
+ /// v.push(1, GFP_KERNEL)?;
+ ///
+ /// v.extend_with(3, 5, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5]);
+ ///
+ /// v.extend_with(2, 8, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
+ ///
+ /// v.extend_with(0, 3, GFP_KERNEL)?;
+ /// assert_eq!(&v, &[1, 5, 5, 5, 8, 8]);
+ ///
+ /// # Ok::<(), Error>(())
+ /// ```
pub fn extend_with(&mut self, n: usize, value: T, flags: Flags) -> Result<(), AllocError> {
if n == 0 {
return Ok(());
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v2 1/2] rust: alloc: add doc test for `Vec::extend_with`
2026-04-25 10:16 ` [PATCH v2 1/2] rust: alloc: add doc test for `Vec::extend_with` Hsiu Che Yu
@ 2026-04-26 3:58 ` Alexandre Courbot
0 siblings, 0 replies; 13+ messages in thread
From: Alexandre Courbot @ 2026-04-26 3:58 UTC (permalink / raw)
To: Hsiu Che Yu
Cc: rust-for-linux, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
On Sat Apr 25, 2026 at 7:16 PM JST, Hsiu Che Yu wrote:
> Add a doc test for `Vec::extend_with` demonstrating basic usage and the
> zero-length case.
>
> Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment
[not found] ` <cover.1777111268.git.yu.whisper.personal@gmail.com>
2026-04-25 10:16 ` [PATCH v2 1/2] rust: alloc: add doc test for `Vec::extend_with` Hsiu Che Yu
@ 2026-04-25 10:16 ` Hsiu Che Yu
2026-04-25 15:17 ` Alexandre Courbot
2026-04-26 13:10 ` Miguel Ojeda
1 sibling, 2 replies; 13+ messages in thread
From: Hsiu Che Yu @ 2026-04-25 10:16 UTC (permalink / raw)
To: rust-for-linux
Cc: Alexandre Courbot, Hsiu Che Yu, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
Fix an incorrect operator in the SAFETY comment, changing `<` to `<=`,
since `Vec::reserve` guarantees capacity for exactly n additional elements,
so the equal case should be included.
Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
---
rust/kernel/alloc/kvec.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index 408a51ad3623..fc4bf0a7934d 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -772,7 +772,7 @@ pub fn extend_with(&mut self, n: usize, value: T, flags: Flags) -> Result<(), Al
spare[n - 1].write(value);
// SAFETY:
- // - `self.len() + n < self.capacity()` due to the call to reserve above,
+ // - `self.len() + n <= self.capacity()` due to the call to reserve above,
// - the loop and the line above initialized the next `n` elements.
unsafe { self.inc_len(n) };
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment
2026-04-25 10:16 ` [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment Hsiu Che Yu
@ 2026-04-25 15:17 ` Alexandre Courbot
2026-04-26 13:10 ` Miguel Ojeda
1 sibling, 0 replies; 13+ messages in thread
From: Alexandre Courbot @ 2026-04-25 15:17 UTC (permalink / raw)
To: Hsiu Che Yu
Cc: rust-for-linux, Danilo Krummrich, Lorenzo Stoakes,
Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, open list
On Sat Apr 25, 2026 at 7:16 PM JST, Hsiu Che Yu wrote:
> Fix an incorrect operator in the SAFETY comment, changing `<` to `<=`,
> since `Vec::reserve` guarantees capacity for exactly n additional elements,
> so the equal case should be included.
>
> Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment
2026-04-25 10:16 ` [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment Hsiu Che Yu
2026-04-25 15:17 ` Alexandre Courbot
@ 2026-04-26 13:10 ` Miguel Ojeda
2026-04-27 3:58 ` Hsiu Che Yu
1 sibling, 1 reply; 13+ messages in thread
From: Miguel Ojeda @ 2026-04-26 13:10 UTC (permalink / raw)
To: Hsiu Che Yu
Cc: rust-for-linux, Alexandre Courbot, Danilo Krummrich,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, open list
On Sat, Apr 25, 2026 at 12:18 PM Hsiu Che Yu
<yu.whisper.personal@gmail.com> wrote:
>
> Fix an incorrect operator in the SAFETY comment, changing `<` to `<=`,
> since `Vec::reserve` guarantees capacity for exactly n additional elements,
> so the equal case should be included.
>
> Signed-off-by: Hsiu Che Yu <yu.whisper.personal@gmail.com>
Thanks!
For this case it doesn't matter too much, but in general, when
something is a fix, we add a Fixes: tag (and in most cases Cc: stable@
to accompany it). That helps backporting (when needed), adds context
e.g. for reviewing (at times), etc.
By the way, now that I was looking at `reserve()`, the assert in the
example there should probably use `>= 11` since there is already an
element, instead of `>= 10`. That could be another similar patch.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment
2026-04-26 13:10 ` Miguel Ojeda
@ 2026-04-27 3:58 ` Hsiu Che Yu
2026-04-27 13:22 ` Miguel Ojeda
0 siblings, 1 reply; 13+ messages in thread
From: Hsiu Che Yu @ 2026-04-27 3:58 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Hsiu Che Yu, rust-for-linux, Alexandre Courbot, Danilo Krummrich,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, open list
On Sun, Apr 26, 2026 at 03:10:12PM +0200, Miguel Ojeda wrote:
>For this case it doesn't matter too much, but in general, when
>something is a fix, we add a Fixes: tag (and in most cases Cc: stable@
>to accompany it). That helps backporting (when needed), adds context
>e.g. for reviewing (at times), etc.
I did miss the Fixes: tag — and what I hadn't thought about was that
these tags feed into the underlying tooling and workflows.
I'll make sure to include a Fixes: tag in fix-related commits going
forward (and will likely use one in the assert! patch coming up shortly)!
On Sun, Apr 26, 2026 at 03:10:12PM +0200, Miguel Ojeda wrote:
>By the way, now that I was looking at `reserve()`, the assert in the
>example there should probably use `>= 11` since there is already an
>element, instead of `>= 10`. That could be another similar patch.
I'll go ahead and work on that. I was thinking of changing it
to `>= v.len() + 10`, which might make the intent clearer.
For this patch, should I include the Suggested-by:, Reported-by:,
and Fixes: tags?
Thanks,
Hsiu
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment
2026-04-27 3:58 ` Hsiu Che Yu
@ 2026-04-27 13:22 ` Miguel Ojeda
2026-04-27 13:44 ` Hsiu Che Yu
0 siblings, 1 reply; 13+ messages in thread
From: Miguel Ojeda @ 2026-04-27 13:22 UTC (permalink / raw)
To: Miguel Ojeda, rust-for-linux, Alexandre Courbot, Danilo Krummrich,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, open list
Cc: Hsiu Che Yu
On Mon, Apr 27, 2026 at 5:58 AM Hsiu Che Yu
<yu.whisper.personal@gmail.com> wrote:
>
> For this patch, should I include the Suggested-by:, Reported-by:,
> and Fixes: tags?
If you only need to resend just for that, then what is usually done
instead is to reply with the tags here -- then they can be picked up
by maintainers or in the next version by the author, e.g.
Fixes: ...
(ideally without the indentation so that tools may pick it up automatically)
By the way, an easy rule of thumb is using, for fixes, Reported-by: +
Closes: + Fixes:, while Suggested-by: + Link: for features (but there
are of course exceptions, e.g. someone may have suggested something
important in a fix etc., i.e. it depends -- please see
Documentation/process/submitting-patches.rst for the actual meaning).
I hope that helps!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment
2026-04-27 13:22 ` Miguel Ojeda
@ 2026-04-27 13:44 ` Hsiu Che Yu
0 siblings, 0 replies; 13+ messages in thread
From: Hsiu Che Yu @ 2026-04-27 13:44 UTC (permalink / raw)
To: Miguel Ojeda
Cc: rust-for-linux, Alexandre Courbot, Danilo Krummrich,
Lorenzo Stoakes, Vlastimil Babka, Liam R. Howlett,
Uladzislau Rezki, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, open list, Hsiu Che Yu
On Mon, Apr 27, 2026 at 03:22:18PM +0200, Miguel Ojeda wrote:
>If you only need to resend just for that, then what is usually done
>instead is to reply with the tags here -- then they can be picked up
>by maintainers or in the next version by the author, e.g.
>
> Fixes: ...
>
>(ideally without the indentation so that tools may pick it up automatically)
>
>By the way, an easy rule of thumb is using, for fixes, Reported-by: +
>Closes: + Fixes:, while Suggested-by: + Link: for features (but there
>are of course exceptions, e.g. someone may have suggested something
>important in a fix etc., i.e. it depends -- please see
>Documentation/process/submitting-patches.rst for the actual meaning).
Thanks, that's very helpful!
Fixes: 2aac4cd7dae3d ("rust: alloc: implement kernel `Vec` type")
Thanks,
Hsiu
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2026-04-27 13:44 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-25 6:08 [PATCH] rust: alloc: add doc test for `Vec::extend_with` and fix comment Hsiu Che Yu
2026-04-25 6:32 ` Alexandre Courbot
2026-04-25 6:53 ` Hsiu Che Yu
2026-04-25 7:20 ` Alexandre Courbot
2026-04-25 9:00 ` Hsiu Che Yu
[not found] ` <cover.1777111268.git.yu.whisper.personal@gmail.com>
2026-04-25 10:16 ` [PATCH v2 1/2] rust: alloc: add doc test for `Vec::extend_with` Hsiu Che Yu
2026-04-26 3:58 ` Alexandre Courbot
2026-04-25 10:16 ` [PATCH v2 2/2] rust: alloc: fix `Vec::extend_with` SAFETY comment Hsiu Che Yu
2026-04-25 15:17 ` Alexandre Courbot
2026-04-26 13:10 ` Miguel Ojeda
2026-04-27 3:58 ` Hsiu Che Yu
2026-04-27 13:22 ` Miguel Ojeda
2026-04-27 13:44 ` Hsiu Che Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox