diff --git a/rust/kernel/file_operations.rs b/rust/kernel/file_operations.rs index 01505e9fc8f1a9..343c24f00bbea4 100644 --- a/rust/kernel/file_operations.rs +++ b/rust/kernel/file_operations.rs @@ -150,7 +150,7 @@ unsafe extern "C" fn llseek_callback( _ => 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) } } @@ -164,7 +164,7 @@ unsafe extern "C" fn unlocked_ioctl_callback( 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 _) } } @@ -178,7 +178,7 @@ unsafe extern "C" fn compat_ioctl_callback( 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 _) } } @@ -194,7 +194,7 @@ unsafe extern "C" fn fsync_callback( 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()) } } @@ -386,15 +386,15 @@ impl IoctlCommand { pub fn dispatch(&mut self, handler: &T, file: &File) -> KernelResult { 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), } } @@ -531,7 +531,7 @@ impl PointerWrapper for Box { } unsafe fn from_pointer(ptr: *const T) -> Self { - Box::::from_raw(ptr as _) + Box::from_raw(ptr as _) } } @@ -551,6 +551,6 @@ impl PointerWrapper for Arc { } unsafe fn from_pointer(ptr: *const T) -> Self { - Arc::::from_raw(ptr) + Arc::from_raw(ptr) } } diff --git a/rust/kernel/user_ptr.rs b/rust/kernel/user_ptr.rs index d9d91bcdbfa983..a15273efad870e 100644 --- a/rust/kernel/user_ptr.rs +++ b/rust/kernel/user_ptr.rs @@ -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}; @@ -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> { + pub fn read_all(&mut self) -> KernelResult> { let mut data = Vec::::new(); data.try_reserve_exact(self.1)?; data.resize(self.1, 0); @@ -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 @@ -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