Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-04-05 Thread Tamir Duberstein
On Sun, Mar 16, 2025 at 7:17 AM Andrew Ballance wrote: > > implement the equivalent of the rust std's Vec::resize > on the kernel's Vec type. > > Signed-off-by: Andrew Ballance > --- > rust/kernel/alloc/kvec.rs | 26 ++ > 1 file changed, 26 insertions(+) > > diff --git a/

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-19 Thread Tamir Duberstein
On Wed, Mar 19, 2025 at 12:43 PM Miguel Ojeda wrote: > > On Wed, Mar 19, 2025 at 5:13 PM Tamir Duberstein wrote: > > > > No, I meant avoiding the check. The existing code already explicitly > > checks `new_len > self.len()` before evaluating `new_len - > > self.len()`. This means the check occurs

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-19 Thread Miguel Ojeda
On Wed, Mar 19, 2025 at 5:13 PM Tamir Duberstein wrote: > > No, I meant avoiding the check. The existing code already explicitly > checks `new_len > self.len()` before evaluating `new_len - > self.len()`. This means the check occurs twice. `checked_sub` reduces > the number of checks by 1. Perhaps

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-19 Thread Tamir Duberstein
On Wed, Mar 19, 2025 at 12:06 PM Miguel Ojeda wrote: > > On Wed, Mar 19, 2025 at 4:59 PM Tamir Duberstein wrote: > > > > If we're talking about the same thing then I think we're both wrong > > and the correct phrasing would have been: "you can avoid underflow > > checking when CONFIG_RUST_OVERFLO

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-19 Thread Miguel Ojeda
On Wed, Mar 19, 2025 at 4:59 PM Tamir Duberstein wrote: > > If we're talking about the same thing then I think we're both wrong > and the correct phrasing would have been: "you can avoid underflow > checking when CONFIG_RUST_OVERFLOW_CHECKS=y by using `checked_sub`". I > was referring to the under

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-19 Thread Tamir Duberstein
On Wed, Mar 19, 2025 at 10:34 AM Benno Lossin wrote: > > On Wed Mar 19, 2025 at 2:42 PM CET, Tamir Duberstein wrote: > > On Tue, Mar 18, 2025 at 8:50 PM Benno Lossin wrote: > >> > >> On Tue Mar 18, 2025 at 9:12 PM CET, Tamir Duberstein wrote: > >> > On Sun, Mar 16, 2025 at 7:17 AM Andrew Ballance

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-19 Thread Benno Lossin
On Wed Mar 19, 2025 at 2:42 PM CET, Tamir Duberstein wrote: > On Tue, Mar 18, 2025 at 8:50 PM Benno Lossin wrote: >> >> On Tue Mar 18, 2025 at 9:12 PM CET, Tamir Duberstein wrote: >> > On Sun, Mar 16, 2025 at 7:17 AM Andrew Ballance >> > wrote: >> >> +pub fn resize(&mut self, new_len: usize,

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-19 Thread Tamir Duberstein
On Tue, Mar 18, 2025 at 8:50 PM Benno Lossin wrote: > > On Tue Mar 18, 2025 at 9:12 PM CET, Tamir Duberstein wrote: > > On Sun, Mar 16, 2025 at 7:17 AM Andrew Ballance > > wrote: > >> +pub fn resize(&mut self, new_len: usize, value: T, flags: Flags) -> > >> Result<(), AllocError> { > >> +

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-18 Thread Benno Lossin
On Tue Mar 18, 2025 at 9:12 PM CET, Tamir Duberstein wrote: > On Sun, Mar 16, 2025 at 7:17 AM Andrew Ballance > wrote: >> +pub fn resize(&mut self, new_len: usize, value: T, flags: Flags) -> >> Result<(), AllocError> { >> +if new_len > self.len() { >> +self.extend_with(new

Re: [PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-16 Thread Benno Lossin
On Sun Mar 16, 2025 at 12:16 PM CET, Andrew Ballance wrote: > implement the equivalent of the rust std's Vec::resize > on the kernel's Vec type. > > Signed-off-by: Andrew Ballance Reviewed-by: Benno Lossin --- Cheers, Benno > --- > rust/kernel/alloc/kvec.rs | 26 ++ >

[PATCH v2 2/3] rust: alloc: add Vec::resize method

2025-03-16 Thread Andrew Ballance
implement the equivalent of the rust std's Vec::resize on the kernel's Vec type. Signed-off-by: Andrew Ballance --- rust/kernel/alloc/kvec.rs | 26 ++ 1 file changed, 26 insertions(+) diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs index 18bcc59f0b38..