Skip to content

Commit 10fc44e

Browse files
kernel: minor cleanups
Suggested by clippy :) Signed-off-by: Anhad Singh <[email protected]>
1 parent 94e01d2 commit 10fc44e

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

src/aero_kernel/src/acpi/rsdp.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,10 @@ pub(super) unsafe fn validate_checksum(ptr: *const u8, size: usize) -> bool {
3939
sum == 0
4040
}
4141

42-
pub(super) trait RsdtTyp {
43-
fn as_usize(self) -> usize;
44-
}
45-
46-
impl RsdtTyp for u32 {
47-
fn as_usize(self) -> usize {
48-
self as _
49-
}
50-
}
42+
pub(super) trait RsdtTyp {}
5143

52-
impl RsdtTyp for u64 {
53-
fn as_usize(self) -> usize {
54-
self as _
55-
}
56-
}
44+
impl RsdtTyp for u32 {}
45+
impl RsdtTyp for u64 {}
5746

5847
pub(super) trait RsdtHeader {
5948
fn signature(&self) -> &[u8];
@@ -103,7 +92,7 @@ pub(super) struct Rsdt<T: RsdtTyp + core::marker::Sized> {
10392

10493
impl Rsdt<u32> {
10594
pub fn new(address: VirtAddr) -> &'static Self {
106-
let this = unsafe { &*(address.as_ptr() as *const Self) };
95+
let this = unsafe { &*address.as_ptr::<Self>() };
10796

10897
let valid_checksum = this.header.is_valid();
10998
let valid_signature = this.header.signature() == b"RSDT";
@@ -144,7 +133,7 @@ impl Rsdt<u32> {
144133

145134
impl Rsdt<u64> {
146135
pub fn new(address: VirtAddr) -> &'static Self {
147-
let this = unsafe { &*(address.as_ptr() as *const Self) };
136+
let this = unsafe { &*address.as_ptr::<Self>() };
148137

149138
let valid_checksum = this.header.is_valid();
150139
let valid_signature = this.header.signature() == b"XSDT";
@@ -191,7 +180,7 @@ pub(super) enum RsdtAddress {
191180

192181
pub(super) fn find_rsdt_address(rsdp_address: VirtAddr) -> RsdtAddress {
193182
// Look for RSDP v2 header, and if it does not exists, look for RSDP v1 header.
194-
let v20 = unsafe { &*(rsdp_address.as_ptr() as *const Rsdp20) };
183+
let v20 = unsafe { &*rsdp_address.as_ptr::<Rsdp20>() };
195184
let is_v20 = v20.revision >= 2 && v20.xsdt_address != 0;
196185

197186
if is_v20 {
@@ -201,7 +190,7 @@ pub(super) fn find_rsdt_address(rsdp_address: VirtAddr) -> RsdtAddress {
201190
let xsdt_address = PhysAddr::new(v20.xsdt_address).as_hhdm_virt();
202191
RsdtAddress::Xsdt(xsdt_address)
203192
} else {
204-
let v10 = unsafe { &*(rsdp_address.as_ptr() as *const Rsdp10) };
193+
let v10 = unsafe { &*rsdp_address.as_ptr::<Rsdp10>() };
205194
let valid = validate_rsdt_checksum(v10);
206195

207196
assert!(valid, "rsdp: failed to validate RSDP v10 checksum");

src/aero_kernel/src/mem/paging/addr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl VirtAddr {
122122
/// ```
123123
pub fn read_mut<'a, T: Sized>(&self) -> Result<&'a mut T, ReadErr> {
124124
self.validate_read::<T>()?;
125-
Ok(unsafe { &mut *(self.as_mut_ptr() as *mut T) })
125+
Ok(unsafe { &mut *self.as_mut_ptr() })
126126
}
127127

128128
pub fn as_bytes_mut(&self, size_bytes: usize) -> &mut [u8] {

src/aero_kernel/src/utils/dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ unsafe impl Allocator for DmaAllocator {
3737
let virt = phys.as_hhdm_virt();
3838

3939
// SAFETY: The frame is aligned and non-null.
40-
let ptr = unsafe { NonNull::new_unchecked(virt.as_mut_ptr() as *mut u8) };
40+
let ptr = unsafe { NonNull::new_unchecked(virt.as_mut_ptr()) };
4141
Ok(NonNull::slice_from_raw_parts(ptr, size_bytes))
4242
}
4343

src/aero_syscall/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#![no_std]
1919
#![feature(decl_macro)]
20+
// cc <https://github.com/bitflags/bitflags/issues/110>
21+
#![allow(clippy::bad_bit_mask)]
2022

2123
#[macro_use]
2224
extern crate num_derive;

0 commit comments

Comments
 (0)