From 92d56752bac86346dd532f0ec05873e897c36ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20Yi=C4=9Fit=20=C5=9Eahin?= Date: Tue, 24 Oct 2023 17:32:32 +0200 Subject: [PATCH] use pointer address formatter instead of casting To print addresses of objects, use address pointer formatter directly instead of casting to other types to print. --- src/arch/aarch64/kernel/interrupts.rs | 2 +- src/arch/x86_64/kernel/mmio.rs | 11 ++++------- src/mm/freelist.rs | 16 +++++----------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/arch/aarch64/kernel/interrupts.rs b/src/arch/aarch64/kernel/interrupts.rs index 591cc5a64b..683d3dc7b3 100644 --- a/src/arch/aarch64/kernel/interrupts.rs +++ b/src/arch/aarch64/kernel/interrupts.rs @@ -190,7 +190,7 @@ pub(crate) extern "C" fn do_sync(state: &State) { // add page fault handler - error!("Current stack pointer {:#x}", state as *const _ as u64); + error!("Current stack pointer {state:p}"); error!("Unable to handle page fault at {:#x}", far); error!("Exception return address {:#x}", ELR_EL1.get()); error!("Thread ID register {:#x}", TPIDR_EL0.get()); diff --git a/src/arch/x86_64/kernel/mmio.rs b/src/arch/x86_64/kernel/mmio.rs index f3cdda926a..4f6d4c98c2 100644 --- a/src/arch/x86_64/kernel/mmio.rs +++ b/src/arch/x86_64/kernel/mmio.rs @@ -74,7 +74,7 @@ pub fn detect_network() -> Result<&'static mut MmioRegisterLayout, &'static str> let version = mmio.get_version(); if magic != MAGIC_VALUE { - trace!("It's not a MMIO-device at {:#X}", mmio as *const _ as usize); + trace!("It's not a MMIO-device at {mmio:p}"); continue; } @@ -84,20 +84,17 @@ pub fn detect_network() -> Result<&'static mut MmioRegisterLayout, &'static str> } // We found a MMIO-device (whose 512-bit address in this structure). - trace!("Found a MMIO-device at {:#X}", mmio as *const _ as usize); + trace!("Found a MMIO-device at {mmio:p}"); // Verify the device-ID to find the network card let id = mmio.get_device_id(); if id != DevId::VIRTIO_DEV_ID_NET { - trace!( - "It's not a network card at {:#X}", - mmio as *const _ as usize - ); + trace!("It's not a network card at {mmio:p}"); continue; } - info!("Found network card at {:#X}", mmio as *const _ as usize); + info!("Found network card at {mmio:p}"); crate::arch::mm::physicalmem::reserve( PhysAddr::from(current_address.align_down(BasePageSize::SIZE as usize)), diff --git a/src/mm/freelist.rs b/src/mm/freelist.rs index 3102754589..2b11721976 100644 --- a/src/mm/freelist.rs +++ b/src/mm/freelist.rs @@ -33,11 +33,7 @@ impl FreeList { } pub fn allocate(&mut self, size: usize, alignment: Option) -> Result { - trace!( - "Allocating {} bytes from Free List {:#X}", - size, - self as *const Self as usize - ); + trace!("Allocating {} bytes from Free List {self:p}", size); let new_size = if let Some(align) = alignment { size + align @@ -90,10 +86,9 @@ impl FreeList { #[cfg(all(target_arch = "x86_64", not(feature = "pci")))] pub fn reserve(&mut self, address: usize, size: usize) -> Result<(), AllocError> { trace!( - "Try to reserve {} bytes at {:#X} from Free List {:#X}", + "Try to reserve {} bytes at {:#X} from Free List {self:p}", size, - address, - self as *const Self as usize + address ); // Find a region in the Free List that has at least the requested size. @@ -119,10 +114,9 @@ impl FreeList { pub fn deallocate(&mut self, address: usize, size: usize) { trace!( - "Deallocating {} bytes at {:#X} from Free List {:#X}", + "Deallocating {} bytes at {:#X} from Free List {self:p}", size, - address, - self as *const Self as usize + address ); let end = address + size;