File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 4
4
//!
5
5
//! C header: [`include/linux/uaccess.h`](../../../../include/linux/uaccess.h)
6
6
7
- use crate :: { c_types, error:: Error , KernelResult } ;
7
+ use crate :: { bindings , c_types, error:: Error , KernelResult } ;
8
8
use alloc:: vec:: Vec ;
9
9
use core:: mem:: { size_of, MaybeUninit } ;
10
10
@@ -242,6 +242,27 @@ impl UserSlicePtrWriter {
242
242
self . len ( ) == 0
243
243
}
244
244
245
+ /// Writes zeroes to the user slice.
246
+ pub fn clear ( & mut self , mut len : usize ) -> KernelResult {
247
+ let mut ret = Ok ( ( ) ) ;
248
+ if len > self . 1 {
249
+ ret = Err ( Error :: EFAULT ) ;
250
+ len = self . 1 ;
251
+ }
252
+
253
+ // SAFETY: The buffer will be validated by `clear_user`. We ensure that `len` is within
254
+ // bounds in the check above.
255
+ let left = unsafe { bindings:: clear_user ( self . 0 , len as _ ) } as usize ;
256
+ if left != 0 {
257
+ ret = Err ( Error :: EFAULT ) ;
258
+ len -= left;
259
+ }
260
+
261
+ self . 0 = self . 0 . wrapping_add ( len) ;
262
+ self . 1 -= len;
263
+ ret
264
+ }
265
+
245
266
/// Writes a byte slice to the user slice.
246
267
///
247
268
/// Returns `EFAULT` if the byte slice is bigger than the remaining size
You can’t perform that action at this time.
0 commit comments