Skip to content

Commit

Permalink
Don't assume that misaligned address in error is virtual.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Nov 26, 2024
1 parent 48ef54f commit a88f30e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ fn get_bar_region<H: Hal, T, C: ConfigurationAccess>(
let vaddr = unsafe { H::mmio_phys_to_virt(paddr, struct_info.length as usize) };
if vaddr.as_ptr() as usize % align_of::<T>() != 0 {
return Err(VirtioPciError::Misaligned {
vaddr,
address: vaddr.as_ptr() as usize,
alignment: align_of::<T>(),
});
}
Expand Down Expand Up @@ -489,13 +489,11 @@ pub enum VirtioPciError {
/// The offset for some capability was greater than the length of the BAR.
#[error("Capability offset greater than BAR length.")]
BarOffsetOutOfRange,
/// The virtual address was not aligned as expected.
#[error(
"Virtual address {vaddr:#018?} was not aligned to a {alignment} byte boundary as expected."
)]
/// The address was not aligned as expected.
#[error("Address {address:#018} was not aligned to a {alignment} byte boundary as expected.")]
Misaligned {
/// The virtual address in question.
vaddr: NonNull<u8>,
/// The address in question.
address: usize,
/// The expected alignment in bytes.
alignment: usize,
},
Expand Down

0 comments on commit a88f30e

Please sign in to comment.