Skip to content

Commit

Permalink
Merge pull request torvalds#170 from wedsonaf/clutter
Browse files Browse the repository at this point in the history
Reduce clutter in the code.
  • Loading branch information
alex authored Apr 8, 2021
2 parents 8d2489b + d99c466 commit 858b23c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions rust/kernel/file_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ unsafe extern "C" fn llseek_callback<T: FileOperations>(
_ => return Err(Error::EINVAL),
};
let f = &*((*file).private_data as *const T);
let off = T::seek(f, &File::from_ptr(file), off)?;
let off = f.seek(&File::from_ptr(file), off)?;
Ok(off as bindings::loff_t)
}
}
Expand All @@ -164,7 +164,7 @@ unsafe extern "C" fn unlocked_ioctl_callback<T: FileOperations>(
let f = &*((*file).private_data as *const T);
// SAFETY: This function is called by the kernel, so it must set `fs` appropriately.
let mut cmd = IoctlCommand::new(cmd as _, arg as _);
let ret = T::ioctl(f, &File::from_ptr(file), &mut cmd)?;
let ret = f.ioctl(&File::from_ptr(file), &mut cmd)?;
Ok(ret as _)
}
}
Expand All @@ -178,7 +178,7 @@ unsafe extern "C" fn compat_ioctl_callback<T: FileOperations>(
let f = &*((*file).private_data as *const T);
// SAFETY: This function is called by the kernel, so it must set `fs` appropriately.
let mut cmd = IoctlCommand::new(cmd as _, arg as _);
let ret = T::compat_ioctl(f, &File::from_ptr(file), &mut cmd)?;
let ret = f.compat_ioctl(&File::from_ptr(file), &mut cmd)?;
Ok(ret as _)
}
}
Expand All @@ -194,7 +194,7 @@ unsafe extern "C" fn fsync_callback<T: FileOperations>(
let end = end.try_into()?;
let datasync = datasync != 0;
let f = &*((*file).private_data as *const T);
let res = T::fsync(f, &File::from_ptr(file), start, end, datasync)?;
let res = f.fsync(&File::from_ptr(file), start, end, datasync)?;
Ok(res.try_into().unwrap())
}
}
Expand Down Expand Up @@ -386,15 +386,15 @@ impl IoctlCommand {
pub fn dispatch<T: IoctlHandler>(&mut self, handler: &T, file: &File) -> KernelResult<i32> {
let dir = (self.cmd >> bindings::_IOC_DIRSHIFT) & bindings::_IOC_DIRMASK;
if dir == bindings::_IOC_NONE {
return T::pure(handler, file, self.cmd, self.arg);
return handler.pure(file, self.cmd, self.arg);
}

let data = self.user_slice.take().ok_or(Error::EINVAL)?;
const READ_WRITE: u32 = bindings::_IOC_READ | bindings::_IOC_WRITE;
match dir {
bindings::_IOC_WRITE => T::write(handler, file, self.cmd, &mut data.reader()),
bindings::_IOC_READ => T::read(handler, file, self.cmd, &mut data.writer()),
READ_WRITE => T::read_write(handler, file, self.cmd, data),
bindings::_IOC_WRITE => handler.write(file, self.cmd, &mut data.reader()),
bindings::_IOC_READ => handler.read(file, self.cmd, &mut data.writer()),
READ_WRITE => handler.read_write(file, self.cmd, data),
_ => Err(Error::EINVAL),
}
}
Expand Down Expand Up @@ -531,7 +531,7 @@ impl<T> PointerWrapper<T> for Box<T> {
}

unsafe fn from_pointer(ptr: *const T) -> Self {
Box::<T>::from_raw(ptr as _)
Box::from_raw(ptr as _)
}
}

Expand All @@ -551,6 +551,6 @@ impl<T> PointerWrapper<T> for Arc<T> {
}

unsafe fn from_pointer(ptr: *const T) -> Self {
Arc::<T>::from_raw(ptr)
Arc::from_raw(ptr)
}
}
12 changes: 6 additions & 6 deletions rust/kernel/user_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! C header: [`include/linux/uaccess.h`](../../../../include/linux/uaccess.h)
use crate::{c_types, error, KernelResult};
use crate::{c_types, error::Error, KernelResult};
use alloc::vec::Vec;
use core::mem::{size_of, MaybeUninit};

Expand Down Expand Up @@ -148,7 +148,7 @@ impl UserSlicePtrReader {
///
/// Returns `EFAULT` if the address does not currently point to
/// mapped, readable memory.
pub fn read_all(&mut self) -> error::KernelResult<Vec<u8>> {
pub fn read_all(&mut self) -> KernelResult<Vec<u8>> {
let mut data = Vec::<u8>::new();
data.try_reserve_exact(self.1)?;
data.resize(self.1, 0);
Expand All @@ -174,11 +174,11 @@ impl UserSlicePtrReader {
/// The output buffer must be valid.
pub unsafe fn read_raw(&mut self, out: *mut u8, len: usize) -> KernelResult {
if len > self.1 || len > u32::MAX as usize {
return Err(error::Error::EFAULT);
return Err(Error::EFAULT);
}
let res = rust_helper_copy_from_user(out as _, self.0, len as _);
if res != 0 {
return Err(error::Error::EFAULT);
return Err(Error::EFAULT);
}
// Since this is not a pointer to a valid object in our program,
// we cannot use `add`, which has C-style rules for defined
Expand Down Expand Up @@ -233,11 +233,11 @@ impl UserSlicePtrWriter {
/// The input buffer must be valid.
unsafe fn write_raw(&mut self, data: *const u8, len: usize) -> KernelResult {
if len > self.1 || len > u32::MAX as usize {
return Err(error::Error::EFAULT);
return Err(Error::EFAULT);
}
let res = rust_helper_copy_to_user(self.0, data as _, len as _);
if res != 0 {
return Err(error::Error::EFAULT);
return Err(Error::EFAULT);
}
// Since this is not a pointer to a valid object in our program,
// we cannot use `add`, which has C-style rules for defined
Expand Down

0 comments on commit 858b23c

Please sign in to comment.