Skip to content

Commit 858b23c

Browse files
authored
Merge pull request #170 from wedsonaf/clutter
Reduce clutter in the code.
2 parents 8d2489b + d99c466 commit 858b23c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

rust/kernel/file_operations.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ unsafe extern "C" fn llseek_callback<T: FileOperations>(
150150
_ => return Err(Error::EINVAL),
151151
};
152152
let f = &*((*file).private_data as *const T);
153-
let off = T::seek(f, &File::from_ptr(file), off)?;
153+
let off = f.seek(&File::from_ptr(file), off)?;
154154
Ok(off as bindings::loff_t)
155155
}
156156
}
@@ -164,7 +164,7 @@ unsafe extern "C" fn unlocked_ioctl_callback<T: FileOperations>(
164164
let f = &*((*file).private_data as *const T);
165165
// SAFETY: This function is called by the kernel, so it must set `fs` appropriately.
166166
let mut cmd = IoctlCommand::new(cmd as _, arg as _);
167-
let ret = T::ioctl(f, &File::from_ptr(file), &mut cmd)?;
167+
let ret = f.ioctl(&File::from_ptr(file), &mut cmd)?;
168168
Ok(ret as _)
169169
}
170170
}
@@ -178,7 +178,7 @@ unsafe extern "C" fn compat_ioctl_callback<T: FileOperations>(
178178
let f = &*((*file).private_data as *const T);
179179
// SAFETY: This function is called by the kernel, so it must set `fs` appropriately.
180180
let mut cmd = IoctlCommand::new(cmd as _, arg as _);
181-
let ret = T::compat_ioctl(f, &File::from_ptr(file), &mut cmd)?;
181+
let ret = f.compat_ioctl(&File::from_ptr(file), &mut cmd)?;
182182
Ok(ret as _)
183183
}
184184
}
@@ -194,7 +194,7 @@ unsafe extern "C" fn fsync_callback<T: FileOperations>(
194194
let end = end.try_into()?;
195195
let datasync = datasync != 0;
196196
let f = &*((*file).private_data as *const T);
197-
let res = T::fsync(f, &File::from_ptr(file), start, end, datasync)?;
197+
let res = f.fsync(&File::from_ptr(file), start, end, datasync)?;
198198
Ok(res.try_into().unwrap())
199199
}
200200
}
@@ -386,15 +386,15 @@ impl IoctlCommand {
386386
pub fn dispatch<T: IoctlHandler>(&mut self, handler: &T, file: &File) -> KernelResult<i32> {
387387
let dir = (self.cmd >> bindings::_IOC_DIRSHIFT) & bindings::_IOC_DIRMASK;
388388
if dir == bindings::_IOC_NONE {
389-
return T::pure(handler, file, self.cmd, self.arg);
389+
return handler.pure(file, self.cmd, self.arg);
390390
}
391391

392392
let data = self.user_slice.take().ok_or(Error::EINVAL)?;
393393
const READ_WRITE: u32 = bindings::_IOC_READ | bindings::_IOC_WRITE;
394394
match dir {
395-
bindings::_IOC_WRITE => T::write(handler, file, self.cmd, &mut data.reader()),
396-
bindings::_IOC_READ => T::read(handler, file, self.cmd, &mut data.writer()),
397-
READ_WRITE => T::read_write(handler, file, self.cmd, data),
395+
bindings::_IOC_WRITE => handler.write(file, self.cmd, &mut data.reader()),
396+
bindings::_IOC_READ => handler.read(file, self.cmd, &mut data.writer()),
397+
READ_WRITE => handler.read_write(file, self.cmd, data),
398398
_ => Err(Error::EINVAL),
399399
}
400400
}
@@ -531,7 +531,7 @@ impl<T> PointerWrapper<T> for Box<T> {
531531
}
532532

533533
unsafe fn from_pointer(ptr: *const T) -> Self {
534-
Box::<T>::from_raw(ptr as _)
534+
Box::from_raw(ptr as _)
535535
}
536536
}
537537

@@ -551,6 +551,6 @@ impl<T> PointerWrapper<T> for Arc<T> {
551551
}
552552

553553
unsafe fn from_pointer(ptr: *const T) -> Self {
554-
Arc::<T>::from_raw(ptr)
554+
Arc::from_raw(ptr)
555555
}
556556
}

rust/kernel/user_ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
//! C header: [`include/linux/uaccess.h`](../../../../include/linux/uaccess.h)
66
7-
use crate::{c_types, error, KernelResult};
7+
use crate::{c_types, error::Error, KernelResult};
88
use alloc::vec::Vec;
99
use core::mem::{size_of, MaybeUninit};
1010

@@ -148,7 +148,7 @@ impl UserSlicePtrReader {
148148
///
149149
/// Returns `EFAULT` if the address does not currently point to
150150
/// mapped, readable memory.
151-
pub fn read_all(&mut self) -> error::KernelResult<Vec<u8>> {
151+
pub fn read_all(&mut self) -> KernelResult<Vec<u8>> {
152152
let mut data = Vec::<u8>::new();
153153
data.try_reserve_exact(self.1)?;
154154
data.resize(self.1, 0);
@@ -174,11 +174,11 @@ impl UserSlicePtrReader {
174174
/// The output buffer must be valid.
175175
pub unsafe fn read_raw(&mut self, out: *mut u8, len: usize) -> KernelResult {
176176
if len > self.1 || len > u32::MAX as usize {
177-
return Err(error::Error::EFAULT);
177+
return Err(Error::EFAULT);
178178
}
179179
let res = rust_helper_copy_from_user(out as _, self.0, len as _);
180180
if res != 0 {
181-
return Err(error::Error::EFAULT);
181+
return Err(Error::EFAULT);
182182
}
183183
// Since this is not a pointer to a valid object in our program,
184184
// we cannot use `add`, which has C-style rules for defined
@@ -233,11 +233,11 @@ impl UserSlicePtrWriter {
233233
/// The input buffer must be valid.
234234
unsafe fn write_raw(&mut self, data: *const u8, len: usize) -> KernelResult {
235235
if len > self.1 || len > u32::MAX as usize {
236-
return Err(error::Error::EFAULT);
236+
return Err(Error::EFAULT);
237237
}
238238
let res = rust_helper_copy_to_user(self.0, data as _, len as _);
239239
if res != 0 {
240-
return Err(error::Error::EFAULT);
240+
return Err(Error::EFAULT);
241241
}
242242
// Since this is not a pointer to a valid object in our program,
243243
// we cannot use `add`, which has C-style rules for defined

0 commit comments

Comments
 (0)