rust: generalize userSliceReader to support any Vec
Subsystems (2)
PATCH v2 1/1 rust: generalize userSliceReader to support any Vec
The UserSliceReader::read_all function is currently restricted to use only Vec with the kmalloc allocator.
However, there is no reason for this limitation.
This patch generalizes the function to accept any Vec regardless of the allocator used.
There's a use-case for a KVVec in Binder to avoid maximum sizes for a certain array.
---
Changes in v2:
- Commit description: added use case on description and send to memorymanagment on copy.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- rust/kernel/uaccess.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
rust/kernel/uaccess.rs +3 -3
@@ -5,7 +5,7 @@//! C header: [`include/linux/uaccess.h`](srctree/include/linux/uaccess.h) use crate ::{ - alloc::Flags , + alloc::{Allocator ,Flags }, bindings, error::Result , ffi::c_void,
@@ -127,7 +127,7 @@ pub fn new(ptr: UserPtr, length: usize) -> Self {/// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. -pub fn read_all (self, buf: &mut KVec <u8 >, flags:Flags ) ->Result { +pub fn read_all <A :Allocator >(self, buf: &mut Vec <u8 ,A >, flags:Flags ) ->Result { self.reader ().read_all (buf, flags) }
@@ -281,7 +281,7 @@ pub fn read<T: FromBytes>(&mut self) -> Result<T> {/// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. -pub fn read_all (mut self, buf: &mut KVec <u8 >, flags:Flags ) ->Result { +pub fn read_all <A :Allocator >(mut self, buf: &mut Vec <u8 ,A >, flags:Flags ) ->Result {let len = self.length; buf.reserve (len, flags)?;
---
base-commit: 0c5928deada15a8d075516e6e0d9ee19011bb000
change-id: 20241222-gen-userslice-readall-alloc-8049c668e65e
Best regards,
Signature · 1 line
Filipe Xavier <[email protected]>
Quoted 11 lines · Filipe Xavier
The
UserSliceReader::read_allfunction is currently restricted to use only Vec with the kmalloc allocator.
However, there is no reason for this limitation.
This patch generalizes the function to accept any Vec regardless of the allocator used.
There's a use-case for a KVVec in Binder to avoid maximum sizes for a certain array.
Quoted 10 lines · Filipe Xavier
The
UserSliceReader::read_allfunction is currently restricted to use only Vec with the kmalloc allocator.
However, there is no reason for this limitation.
This patch generalizes the function to accept any Vec regardless of the allocator used.
There's a use-case for a KVVec in Binder to avoid maximum sizes for a certain array.
Regards,
Boqun
Quoted 48 lines
---
Changes in v2:
- Commit description: added use case on description and send to memorymanagment on copy.
- Link to v1: https://lore.kernel.org/r/[email protected]--- rust/kernel/uaccess.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)rust/kernel/uaccess.rs +3
-4@@ -5,7 +5,7 @@//! C header: [`include/linux/uaccess.h`](srctree/include/linux/uaccess.h) use crate ::{ - alloc::Flags , + alloc::{Allocator ,Flags }, bindings, error::Result , ffi::c_void,@@ -127,7 +127,7 @@ pub fn new(ptr: UserPtr, length: usize) -> Self {/// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. -pub fn read_all (self, buf: &mut KVec <u8 >, flags:Flags ) ->Result { +pub fn read_all <A :Allocator >(self, buf: &mut Vec <u8 ,A >, flags:Flags ) ->Result { self.reader ().read_all (buf, flags) }@@ -281,7 +281,7 @@ pub fn read<T: FromBytes>(&mut self) -> Result<T> {/// Reads the entirety of the user slice, appending it to the end of the provided buffer. /// /// Fails with [`EFAULT`] if the read happens on a bad address. -pub fn read_all (mut self, buf: &mut KVec <u8 >, flags:Flags ) ->Result { +pub fn read_all <A :Allocator >(mut self, buf: &mut Vec <u8 ,A >, flags:Flags ) ->Result {let len = self.length; buf.reserve (len, flags)?; ---base-commit:
0c5928deada15a8d075516e6e0d9ee19011bb000
change-id: 20241222-gen-userslice-readall-alloc-8049c668e65eBest regards,
Signature · 1 line
Filipe Xavier <[email protected]>
Miguel Ojeda
AppliedQuoted 11 lines · Filipe Xavier
The
UserSliceReader::read_allfunction is currently restricted to use only Vec with the kmalloc allocator.
However, there is no reason for this limitation.
This patch generalizes the function to accept any Vec regardless of the allocator used.
There's a use-case for a KVVec in Binder to avoid maximum sizes for a certain array.
Applied to rust-next -- thanks everyone!
[ Reflowed and slightly reworded title. - Miguel ]
Cheers,
Miguel