hypervisor: kvm: aarch64: remove repetition in offset_of

The repetition served no purpose.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-12-16 15:52:34 +00:00 committed by Rob Bradford
parent cd83d258b8
commit 3a232ef31a

View File

@ -25,7 +25,7 @@ pub use {kvm_ioctls::Cap, kvm_ioctls::Kvm};
// an instance of that structure. // an instance of that structure.
#[macro_export] #[macro_export]
macro_rules! offset_of { macro_rules! offset_of {
($str:ty, $($field:ident)+) => ({ ($str:ty, $field:ident) => {{
let tmp: std::mem::MaybeUninit<$str> = std::mem::MaybeUninit::uninit(); let tmp: std::mem::MaybeUninit<$str> = std::mem::MaybeUninit::uninit();
let base = tmp.as_ptr(); let base = tmp.as_ptr();
@ -34,14 +34,16 @@ macro_rules! offset_of {
// SAFETY: The pointer is valid and aligned, just not initialised. Using `addr_of` ensures // SAFETY: The pointer is valid and aligned, just not initialised. Using `addr_of` ensures
// that we don't actually read from `base` (which would be UB) nor create an intermediate // that we don't actually read from `base` (which would be UB) nor create an intermediate
// reference. // reference.
let member = unsafe { core::ptr::addr_of!((*base).$($field)*) } as *const u8; let member = unsafe { core::ptr::addr_of!((*base).$field) } as *const u8;
// Avoid warnings when nesting `unsafe` blocks. // Avoid warnings when nesting `unsafe` blocks.
#[allow(unused_unsafe)] #[allow(unused_unsafe)]
// SAFETY: The two pointers are within the same allocated object `tmp`. All requirements // SAFETY: The two pointers are within the same allocated object `tmp`. All requirements
// from offset_from are upheld. // from offset_from are upheld.
unsafe { member.offset_from(base as *const u8) as usize } unsafe {
}); member.offset_from(base as *const u8) as usize
}
}};
} }
// Following are macros that help with getting the ID of a aarch64 core register. // Following are macros that help with getting the ID of a aarch64 core register.