Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit da38832

Browse files
committed
Get the codebase clippy clean
1 parent 28f3ea7 commit da38832

File tree

9 files changed

+48
-36
lines changed

9 files changed

+48
-36
lines changed

src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ unsafe impl GlobalAlloc for KernelAllocator {
1010
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
1111
// krealloc is used instead of kmalloc because kmalloc is an inline function and can't be
1212
// bound to as a result
13-
return bindings::krealloc(ptr::null(), layout.size(), bindings::GFP_KERNEL) as *mut u8;
13+
bindings::krealloc(ptr::null(), layout.size(), bindings::GFP_KERNEL) as *mut u8
1414
}
1515

1616
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {

src/bindings.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case, improper_ctypes)]
2-
3-
use crate::c_types;
4-
5-
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
1+
#[allow(
2+
clippy::all,
3+
non_camel_case_types,
4+
non_upper_case_globals,
5+
non_snake_case,
6+
improper_ctypes
7+
)]
8+
mod bindings {
9+
use crate::c_types;
10+
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
11+
}
12+
pub use bindings::*;
613

714
pub const GFP_KERNEL: gfp_t = BINDINGS_GFP_KERNEL;

src/chrdev.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ pub fn builder(name: &'static str, minors: Range<u16>) -> KernelResult<Builder>
1616
return Err(Error::EINVAL);
1717
}
1818

19-
return Ok(Builder {
19+
Ok(Builder {
2020
name,
2121
minors,
2222
file_ops: vec![],
23-
});
23+
})
2424
}
2525

2626
pub struct Builder {
@@ -35,7 +35,7 @@ impl Builder {
3535
panic!("More devices registered than minor numbers allocated.")
3636
}
3737
self.file_ops.push(&T::VTABLE);
38-
return self;
38+
self
3939
}
4040

4141
pub fn build(self) -> KernelResult<Registration> {
@@ -71,11 +71,11 @@ impl Builder {
7171
}
7272
}
7373

74-
return Ok(Registration {
74+
Ok(Registration {
7575
dev,
7676
count: self.minors.len(),
7777
cdevs,
78-
});
78+
})
7979
}
8080
}
8181

@@ -110,7 +110,7 @@ unsafe extern "C" fn open_callback<T: FileOperations>(
110110
Err(e) => return e.to_kernel_errno(),
111111
};
112112
(*file).private_data = Box::into_raw(f) as *mut c_types::c_void;
113-
return 0;
113+
0
114114
}
115115

116116
unsafe extern "C" fn read_callback<T: FileOperations>(
@@ -129,10 +129,10 @@ unsafe extern "C" fn read_callback<T: FileOperations>(
129129
Ok(()) => {
130130
let written = len - data.len();
131131
(*offset) += written as bindings::loff_t;
132-
return written as c_types::c_ssize_t;
132+
written as c_types::c_ssize_t
133133
}
134-
Err(e) => return e.to_kernel_errno() as c_types::c_ssize_t,
135-
};
134+
Err(e) => e.to_kernel_errno() as c_types::c_ssize_t,
135+
}
136136
}
137137

138138
unsafe extern "C" fn release_callback<T: FileOperations>(
@@ -141,12 +141,12 @@ unsafe extern "C" fn release_callback<T: FileOperations>(
141141
) -> c_types::c_int {
142142
let ptr = mem::replace(&mut (*file).private_data, ptr::null_mut());
143143
drop(Box::from_raw(ptr as *mut T));
144-
return 0;
144+
0
145145
}
146146

147147
impl FileOperationsVtable {
148148
pub const fn new<T: FileOperations>() -> FileOperationsVtable {
149-
return FileOperationsVtable(bindings::file_operations {
149+
FileOperationsVtable(bindings::file_operations {
150150
open: Some(open_callback::<T>),
151151
read: Some(read_callback::<T>),
152152
release: Some(release_callback::<T>),
@@ -181,7 +181,7 @@ impl FileOperationsVtable {
181181
unlocked_ioctl: None,
182182
write: None,
183183
write_iter: None,
184-
});
184+
})
185185
}
186186
}
187187

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ impl Error {
1111
pub const EFAULT: Self = Error(-(bindings::EFAULT as i32));
1212

1313
pub fn from_kernel_errno(errno: c_types::c_int) -> Error {
14-
return Error(errno);
14+
Error(errno)
1515
}
1616

1717
pub fn to_kernel_errno(&self) -> c_types::c_int {
18-
return self.0;
18+
self.0
1919
}
2020
}
2121

2222
impl From<TryFromIntError> for Error {
2323
fn from(_: TryFromIntError) -> Error {
24-
return Error::EINVAL;
24+
Error::EINVAL
2525
}
2626
}
2727

src/filesystem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ pub fn register<T: FileSystem>() -> error::KernelResult<FileSystemRegistration<T
7878
return Err(error::Error::from_kernel_errno(result));
7979
}
8080

81-
return Ok(fs_registration);
81+
Ok(fs_registration)
8282
}

src/printk.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct LogLineWriter {
2222
pos: usize,
2323
}
2424

25+
#[allow(clippy::new_without_default)]
2526
impl LogLineWriter {
2627
pub fn new() -> LogLineWriter {
2728
LogLineWriter {
@@ -31,7 +32,7 @@ impl LogLineWriter {
3132
}
3233

3334
pub fn as_bytes(&self) -> &[u8] {
34-
return &self.data[..self.pos];
35+
&self.data[..self.pos]
3536
}
3637
}
3738

@@ -40,7 +41,7 @@ impl fmt::Write for LogLineWriter {
4041
let copy_len = cmp::min(LOG_LINE_MAX - self.pos, s.as_bytes().len());
4142
self.data[self.pos..self.pos + copy_len].copy_from_slice(&s.as_bytes()[..copy_len]);
4243
self.pos += copy_len;
43-
return Ok(());
44+
Ok(())
4445
}
4546
}
4647

src/sysctl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn trim_whitespace(mut data: &[u8]) -> &[u8] {
2626
{
2727
data = &data[..data.len() - 1];
2828
}
29-
return data;
29+
data
3030
}
3131

3232
impl SysctlStorage for atomic::AtomicBool {
@@ -42,7 +42,7 @@ impl SysctlStorage for atomic::AtomicBool {
4242
}
4343
_ => Err(error::Error::EINVAL),
4444
};
45-
return (data.len(), result);
45+
(data.len(), result)
4646
}
4747

4848
fn read_value(&self, data: &mut UserSlicePtrWriter) -> (usize, error::KernelResult<()>) {
@@ -138,15 +138,15 @@ impl<T: SysctlStorage> Sysctl<T> {
138138
return Err(error::Error::ENOMEM);
139139
}
140140

141-
return Ok(Sysctl {
141+
Ok(Sysctl {
142142
inner: storage,
143143
_table: table,
144144
header: result,
145-
});
145+
})
146146
}
147147

148148
pub fn get(&self) -> &T {
149-
return &self.inner;
149+
&self.inner
150150
}
151151
}
152152

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ impl Mode {
88
}
99

1010
pub fn as_int(&self) -> u16 {
11-
return self.0;
11+
self.0
1212
}
1313
}

src/user_ptr.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl UserSlicePtr {
6060
if access_ok_helper(bindings::VERIFY_WRITE, ptr, length as c_types::c_ulong) == 0 {
6161
return Err(error::Error::EFAULT);
6262
}
63-
return Ok(UserSlicePtr(ptr, length));
63+
Ok(UserSlicePtr(ptr, length))
6464
}
6565

6666
/// Read the entirety of the user slice and return it in a `Vec`.
@@ -70,13 +70,13 @@ impl UserSlicePtr {
7070
pub fn read_all(self) -> error::KernelResult<Vec<u8>> {
7171
let mut data = vec![0; self.1];
7272
self.reader().read(&mut data)?;
73-
return Ok(data);
73+
Ok(data)
7474
}
7575

7676
/// Construct a `UserSlicePtrReader` that can incrementally read
7777
/// from the user slice.
7878
pub fn reader(self) -> UserSlicePtrReader {
79-
return UserSlicePtrReader(self.0, self.1);
79+
UserSlicePtrReader(self.0, self.1)
8080
}
8181

8282
/// Write the provided slice into the user slice.
@@ -86,13 +86,13 @@ impl UserSlicePtr {
8686
/// fault may be written), or `data` is larger than the user slice
8787
/// (in which case no data is written).
8888
pub fn write_all(self, data: &[u8]) -> error::KernelResult<()> {
89-
return self.writer().write(data);
89+
self.writer().write(data)
9090
}
9191

9292
/// Construct a `UserSlicePtrWrite` that can incrementally write
9393
/// into the user slice.
9494
pub fn writer(self) -> UserSlicePtrWriter {
95-
return UserSlicePtrWriter(self.0, self.1);
95+
UserSlicePtrWriter(self.0, self.1)
9696
}
9797
}
9898

@@ -126,7 +126,11 @@ pub struct UserSlicePtrWriter(*mut c_types::c_void, usize);
126126

127127
impl UserSlicePtrWriter {
128128
pub fn len(&self) -> usize {
129-
return self.1;
129+
self.1
130+
}
131+
132+
pub fn is_empty(&self) -> bool {
133+
self.len() == 0
130134
}
131135

132136
pub fn write(&mut self, data: &[u8]) -> error::KernelResult<()> {

0 commit comments

Comments
 (0)