Skip to content

Commit bbfb834

Browse files
kernel: Fixed clippy warnings
Signed-off-by: Ioan-Cristian CÎRSTEA <ioan.cirstea@oxidos.io>
1 parent 80d5d60 commit bbfb834

16 files changed

Lines changed: 73 additions & 102 deletions

File tree

arch/cortex-m/src/syscall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<A: CortexMVariant> kernel::syscall::UserspaceKernelBoundary for SysCall<A>
210210
//
211211
// Refer to
212212
// https://doc.rust-lang.org/std/primitive.pointer.html#safety-13
213-
kernel::utilities::arch_helpers::encode_syscall_return_trd104(
213+
kernel::utilities::arch_helpers::encode_syscall_return_trd104_32bit(
214214
&kernel::utilities::arch_helpers::TRD104SyscallReturn::from_syscall_return(
215215
return_value,
216216
),

arch/riscv/src/syscall.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl kernel::syscall::UserspaceKernelBoundary for SysCall {
174174
let (a1slice, r) = r.split_at_mut(R_A2 - R_A1);
175175
let (a2slice, a3slice) = r.split_at_mut(R_A3 - R_A2);
176176

177-
kernel::utilities::arch_helpers::encode_syscall_return_trd104(
177+
kernel::utilities::arch_helpers::encode_syscall_return_trd104_32bit(
178178
&kernel::utilities::arch_helpers::TRD104SyscallReturn::from_syscall_return(
179179
return_value,
180180
),
@@ -223,7 +223,7 @@ impl kernel::syscall::UserspaceKernelBoundary for SysCall {
223223
_user_accessible_memory_start: &ImmutableUserVirtualPointer<u8>,
224224
_user_app_brk: &ImmutableUserVirtualPointer<u8>,
225225
_state: &mut Riscv32iStoredState,
226-
) -> (ContextSwitchReason, Option<*const u8>) {
226+
) -> (ContextSwitchReason, Option<ImmutableUserVirtualPointer<u8>>) {
227227
// Convince lint that 'mcause' and 'R_A4' are used during test build
228228
let _cause = mcause::Trap::from(_state.mcause as usize);
229229
let _arg4 = _state.regs[R_A4];

arch/x86/src/boundary/boundary_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl UserspaceKernelBoundary for Boundary {
113113
//
114114
// Refer to
115115
// https://doc.rust-lang.org/std/primitive.pointer.html#safety-13
116-
kernel::utilities::arch_helpers::encode_syscall_return_trd104(
116+
kernel::utilities::arch_helpers::encode_syscall_return_trd104_32bit(
117117
&kernel::utilities::arch_helpers::TRD104SyscallReturn::from_syscall_return(
118118
return_value,
119119
),

kernel/src/kernel.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ impl Kernel {
10471047
syscall: Syscall,
10481048
) {
10491049
// Hook for process debugging.
1050-
process.debug_syscall_called(syscall.clone());
1050+
process.debug_syscall_called(syscall);
10511051

10521052
// Enforce platform-specific syscall filtering here.
10531053
//
@@ -1229,23 +1229,21 @@ impl Kernel {
12291229
// > immediately return a failure with a error code of
12301230
// > `INVALID`.
12311231
let rval1 = upcall_ptr.map_or(None, |upcall_ptr_nonnull| {
1232-
// CAST: u8 and () have the same alignment.
1233-
let raw_ptr = upcall_ptr_nonnull.as_ptr() as *const u8;
1232+
let raw_ptr = upcall_ptr_nonnull.as_ptr();
12341233
// SAFETY: `raw_ptr` comes from `upcall_ptr` which is a pointer passed
12351234
// by the user space.
12361235
let result_user_upcall_ptr = unsafe { ImmutableUserVirtualPointer::new_from_raw_byte(raw_ptr) };
12371236
// PANIC: `raw_ptr` is non-null
12381237
let user_upcall_ptr = result_user_upcall_ptr.unwrap();
12391238
self.translate_user_protected_virtual_pointer_byte(process, user_upcall_ptr)
12401239
.ok()
1241-
.map(|kernel_upcall_ptr| {
1240+
.and_then(|kernel_upcall_ptr| {
12421241
if !process.is_valid_upcall_function_pointer(kernel_upcall_ptr) {
12431242
Some(ErrorCode::INVAL)
12441243
} else {
12451244
None
12461245
}
12471246
})
1248-
.flatten()
12491247
});
12501248

12511249
// If the upcall is either null or valid, then we
@@ -1849,7 +1847,7 @@ impl Kernel {
18491847
// system call class.
18501848
_ => {
18511849
let return_value = SyscallReturn::Failure(ErrorCode::NOSUPPORT);
1852-
process.set_syscall_return_value(return_value.clone());
1850+
process.set_syscall_return_value(return_value);
18531851
Some(return_value)
18541852
}
18551853
};

kernel/src/memory_management/allocators/static.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'a, Granule> StaticAllocator<'a, Granule> {
1919

2020
fn take(&self) -> Result<MutablePhysicalSlice<'a, Granule>, ()> {
2121
match self.0.take() {
22-
None => return Err(()),
22+
None => Err(()),
2323
Some(memory) => Ok(memory),
2424
}
2525
}
@@ -37,7 +37,6 @@ impl<'a, Granule> StaticAllocator<'a, Granule> {
3737
> {
3838
memory.split_at_checked(mid).map_err(|memory| {
3939
self.0.insert(Some(memory));
40-
()
4140
})
4241
}
4342
}

kernel/src/memory_management/configuration.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a, Granule> ProcessConfiguration<'a, Granule> {
143143
let physical_pointer =
144144
match ram_region.translate_protected_physical_pointer_byte(physical_pointer) {
145145
Err(physical_pointer) => physical_pointer,
146-
ok @ _ => return ok,
146+
ok => return ok,
147147
};
148148

149149
let prog_region = self.get_prog_region();
@@ -159,7 +159,7 @@ impl<'a, Granule> ProcessConfiguration<'a, Granule> {
159159
let virtual_pointer =
160160
match ram_region.translate_protected_virtual_pointer_byte(virtual_pointer) {
161161
Err(virtual_pointer) => virtual_pointer,
162-
ok @ _ => return ok,
162+
ok => return ok,
163163
};
164164

165165
let prog_region = self.get_prog_region();
@@ -175,7 +175,7 @@ impl<'a, Granule> ProcessConfiguration<'a, Granule> {
175175
let virtual_pointer =
176176
match ram_region.translate_allocated_virtual_pointer_byte(virtual_pointer) {
177177
Err(virtual_pointer) => virtual_pointer,
178-
ok @ _ => return ok,
178+
ok => return ok,
179179
};
180180

181181
let prog_region = self.get_prog_region();
@@ -244,18 +244,18 @@ impl<'a, Granule> ValidProcessConfiguration<'a, Granule> {
244244
}
245245
}
246246

247-
impl<'a, Granule> core::fmt::Display for ValidProcessConfiguration<'a, Granule> {
247+
impl<Granule> core::fmt::Display for ValidProcessConfiguration<'_, Granule> {
248248
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
249-
let header = r#"
249+
let header = r"
250250
+---------------------------------+
251251
| |
252252
| PROCESS MEMORY CONFIGURATION |
253253
| |
254254
+---------------------------------+
255-
"#;
255+
";
256256

257257
write!(formatter, "\n{}\n", header)?;
258-
write!(formatter, "PROG region: {}\n", self.get_prog_region())?;
258+
writeln!(formatter, "PROG region: {}", self.get_prog_region())?;
259259
write!(formatter, "RAM region: {}", self.get_ram_region())
260260
}
261261
}

kernel/src/memory_management/pointers.rs

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -204,29 +204,29 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment>
204204
/// The addition must not overflow.
205205
pub(crate) unsafe fn unchecked_add_zero(&self, count: usize) -> Self {
206206
match NonZero::new(count) {
207-
None => self.clone(),
207+
None => *self,
208208
// SAFETY: the caller ensures that the addition does not overflow
209209
Some(non_zero_count) => unsafe { self.unchecked_add(non_zero_count) },
210210
}
211211
}
212212

213213
pub fn checked_add_zero(&self, count: usize) -> Result<Self, ()> {
214214
match NonZero::new(count) {
215-
None => Ok(self.clone()),
215+
None => Ok(*self),
216216
Some(non_zero_count) => self.checked_add(non_zero_count),
217217
}
218218
}
219219

220220
pub fn checked_sub_zero(&self, count: usize) -> Result<Self, ()> {
221221
match NonZero::new(count) {
222-
None => Ok(self.clone()),
222+
None => Ok(*self),
223223
Some(non_zero_count) => self.checked_add(non_zero_count),
224224
}
225225
}
226226

227227
pub fn checked_offset_zero(&self, count: isize) -> Result<Self, ()> {
228228
match NonZero::new(count) {
229-
None => Ok(self.clone()),
229+
None => Ok(*self),
230230
Some(non_zero_count) => self.checked_offset(non_zero_count),
231231
}
232232
}
@@ -323,10 +323,7 @@ impl<const IS_VIRTUAL: bool, T: Alignment> ImmutablePointer<IS_VIRTUAL, T> {
323323
///
324324
/// The caller must ensure that `pointer` is of right type.
325325
pub(crate) unsafe fn new_raw(pointer: *const T) -> Result<Self, Error> {
326-
let pointer = match ImmutablePtr::new(pointer) {
327-
Err(error) => return Err(error),
328-
Ok(pointer) => pointer,
329-
};
326+
let pointer = ImmutablePtr::new(pointer)?;
330327

331328
// SAFETY: The caller ensures that `pointer` is of the right type
332329
let pointer = unsafe { Self::new(pointer) };
@@ -337,7 +334,7 @@ impl<const IS_VIRTUAL: bool, T: Alignment> ImmutablePointer<IS_VIRTUAL, T> {
337334
/// # Safety
338335
///
339336
/// The caller must ensure that `reference` is of right type.
340-
pub unsafe fn new_from_ref<'a>(reference: &'a T) -> Self {
337+
pub unsafe fn new_from_ref(reference: &T) -> Self {
341338
let immutable_pointer = ImmutablePtr::new_from_ref(reference);
342339
// SAFETY: The caller ensures that `reference` is of the right type
343340
unsafe { Self::new(immutable_pointer) }
@@ -382,10 +379,7 @@ impl<const IS_VIRTUAL: bool, T: Alignment> MutablePointer<IS_VIRTUAL, T> {
382379
///
383380
/// The caller must ensure that `pointer` is of right type.
384381
pub unsafe fn new_raw(pointer: *mut T) -> Result<Self, Error> {
385-
let pointer = match MutablePtr::new(pointer) {
386-
Err(error) => return Err(error),
387-
Ok(pointer) => pointer,
388-
};
382+
let pointer = MutablePtr::new(pointer)?;
389383

390384
// SAFETY: The caller ensures that `pointer` is of the right type
391385
let pointer = unsafe { Self::new(pointer) };
@@ -448,7 +442,7 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> PartialOrd
448442
for Pointer<IS_VIRTUAL, IS_MUTABLE, T>
449443
{
450444
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
451-
self.as_inner().partial_cmp(other.as_inner())
445+
Some(self.cmp(other))
452446
}
453447
}
454448

@@ -460,8 +454,8 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Ord
460454
}
461455
}
462456

463-
impl<'a, const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Sub
464-
for &'a Pointer<IS_VIRTUAL, IS_MUTABLE, T>
457+
impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Sub
458+
for &Pointer<IS_VIRTUAL, IS_MUTABLE, T>
465459
{
466460
type Output = isize;
467461

@@ -482,9 +476,7 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Clone
482476
for Pointer<IS_VIRTUAL, IS_MUTABLE, T>
483477
{
484478
fn clone(&self) -> Self {
485-
let inner = self.as_inner();
486-
// SAFETY: `inner` comes from `self`
487-
unsafe { Self::new(inner.clone()) }
479+
*self
488480
}
489481
}
490482

@@ -520,10 +512,10 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment>
520512
unsafe { &*core::ptr::from_ref(self).cast() }
521513
}
522514

523-
pub(crate) fn to_immutable(&self) -> ValidImmutableVirtualPointer<IS_USER, T> {
515+
pub(crate) fn to_immutable(self) -> ValidImmutableVirtualPointer<IS_USER, T> {
524516
// SAFETY: `ValidVirtualPointer` is marked #[repr(transparent)], so it has the same memory
525517
// representation for both immutable and mutable counter parts.
526-
unsafe { *core::ptr::from_ref(self).cast() }
518+
unsafe { *core::ptr::from_ref(&self).cast() }
527519
}
528520

529521
pub fn to_nullable(self) -> ValidNullableVirtualPointer<IS_USER, IS_MUTABLE, T> {
@@ -578,7 +570,7 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment>
578570
/// The addition must not overflow.
579571
pub(crate) unsafe fn unchecked_add_zero(&self, count: usize) -> Self {
580572
match NonZero::new(count) {
581-
None => self.clone(),
573+
None => *self,
582574
// SAFETY: the caller ensures that the addition does not overflow
583575
Some(non_zero_count) => unsafe { self.unchecked_add(non_zero_count) },
584576
}
@@ -667,7 +659,7 @@ impl<const IS_USER: bool, T: Alignment> ValidImmutableVirtualPointer<IS_USER, T>
667659
///
668660
/// 1. User virtual reference if IS_USER == true
669661
/// 2. Kernel virtual reference if IS_USER == false
670-
pub unsafe fn new_from_ref<'a>(reference: &'a T) -> Self {
662+
pub unsafe fn new_from_ref(reference: &T) -> Self {
671663
let virtual_pointer = ImmutableVirtualPointer::new_from_ref(reference);
672664
// SAFETY: The caller ensures that `reference` is of the right type
673665
unsafe { Self::new(virtual_pointer) }
@@ -816,8 +808,8 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment> Ord
816808
}
817809
}
818810

819-
impl<'a, const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment> Sub
820-
for &'a ValidVirtualPointer<IS_USER, IS_MUTABLE, T>
811+
impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment> Sub
812+
for &ValidVirtualPointer<IS_USER, IS_MUTABLE, T>
821813
{
822814
type Output = isize;
823815

@@ -838,9 +830,7 @@ impl<const IS_USER: bool, const IS_MUTABLE: bool, T: Alignment> Clone
838830
for ValidVirtualPointer<IS_USER, IS_MUTABLE, T>
839831
{
840832
fn clone(&self) -> Self {
841-
let inner = self.as_virtual_pointer();
842-
// SAFETY: `inner` comes from `self`
843-
unsafe { Self::new(inner.clone()) }
833+
*self
844834
}
845835
}
846836

@@ -938,10 +928,7 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> Clone
938928
for NullablePointer<IS_VIRTUAL, IS_MUTABLE, T>
939929
{
940930
fn clone(&self) -> Self {
941-
match self {
942-
NullablePointer::Null => NullablePointer::Null,
943-
NullablePointer::NonNull(pointer) => NullablePointer::NonNull(pointer.clone()),
944-
}
931+
*self
945932
}
946933
}
947934

kernel/src/memory_management/regions.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment>
6060
Self(pointers)
6161
}
6262

63-
pub fn new<'a>(slice: Slice<'a, IS_VIRTUAL, IS_MUTABLE, T>) -> Self {
64-
let pointers = slice.to_pointers();
63+
pub fn new(slice: Slice<'_, IS_VIRTUAL, IS_MUTABLE, T>) -> Self {
64+
let pointers = slice.into_pointers();
6565
Self::new_start_end(pointers)
6666
}
6767

@@ -118,7 +118,7 @@ impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment>
118118
}
119119
}
120120

121-
impl<'a, const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> core::fmt::Display
121+
impl<const IS_VIRTUAL: bool, const IS_MUTABLE: bool, T: Alignment> core::fmt::Display
122122
for Region<IS_VIRTUAL, IS_MUTABLE, T>
123123
{
124124
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
@@ -132,7 +132,7 @@ pub struct AllocatedRegion<'a, const IS_VIRTUAL: bool, T: Alignment> {
132132
phantom_data: PhantomData<&'a ()>,
133133
}
134134

135-
impl<'a, const IS_VIRTUAL: bool, T: Alignment> AllocatedRegion<'a, IS_VIRTUAL, T> {
135+
impl<const IS_VIRTUAL: bool, T: Alignment> AllocatedRegion<'_, IS_VIRTUAL, T> {
136136
const fn as_region(&self) -> &MutableRegion<IS_VIRTUAL, T> {
137137
&self.region
138138
}
@@ -158,7 +158,7 @@ impl<'a, const IS_VIRTUAL: bool, T: Alignment> AllocatedRegion<'a, IS_VIRTUAL, T
158158
}
159159
}
160160

161-
impl<'a, const IS_USER: bool, T: Alignment> core::fmt::Display for AllocatedRegion<'a, IS_USER, T> {
161+
impl<const IS_USER: bool, T: Alignment> core::fmt::Display for AllocatedRegion<'_, IS_USER, T> {
162162
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
163163
write!(formatter, "{}", self.as_region())
164164
}
@@ -169,7 +169,7 @@ pub type PhysicalAllocatedRegion<'a, T> = AllocatedRegion<'a, false, T>;
169169

170170
impl<'a, T: Alignment> PhysicalAllocatedRegion<'a, T> {
171171
pub fn new(slice: MutablePhysicalSlice<'a, T>) -> Self {
172-
let pointers = slice.to_pointers();
172+
let pointers = slice.into_pointers();
173173
let region = MutablePhysicalRegion::new_start_end(pointers);
174174

175175
Self {
@@ -270,8 +270,8 @@ impl<'a, const IS_VIRTUAL: bool, T: Alignment> ProtectedAllocatedRegion<'a, IS_V
270270
}
271271
}
272272

273-
impl<'a, const IS_USER: bool, T: Alignment> core::fmt::Display
274-
for ProtectedAllocatedRegion<'a, IS_USER, T>
273+
impl<const IS_USER: bool, T: Alignment> core::fmt::Display
274+
for ProtectedAllocatedRegion<'_, IS_USER, T>
275275
{
276276
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
277277
write!(
@@ -732,8 +732,8 @@ impl<'a, const IS_USER: bool, T: Alignment> MappedProtectedAllocatedRegion<'a, I
732732
}
733733
}
734734

735-
impl<'a, const IS_USER: bool, T: Alignment> core::fmt::Display
736-
for MappedProtectedAllocatedRegion<'a, IS_USER, T>
735+
impl<const IS_USER: bool, T: Alignment> core::fmt::Display
736+
for MappedProtectedAllocatedRegion<'_, IS_USER, T>
737737
{
738738
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
739739
write!(
@@ -850,8 +850,8 @@ impl<'a, const IS_USER: bool, T: Alignment> DirtyMappedProtectedAllocatedRegion<
850850
}
851851
}
852852

853-
impl<'a, const IS_USER: bool, T: Alignment> core::fmt::Display
854-
for DirtyMappedProtectedAllocatedRegion<'a, IS_USER, T>
853+
impl<const IS_USER: bool, T: Alignment> core::fmt::Display
854+
for DirtyMappedProtectedAllocatedRegion<'_, IS_USER, T>
855855
{
856856
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
857857
write!(

0 commit comments

Comments
 (0)