diff --git a/src/pci.rs b/src/pci.rs index 8e02bde4..4495bf99 100644 --- a/src/pci.rs +++ b/src/pci.rs @@ -295,14 +295,16 @@ impl PciDevice { panic!("I/O BARs are not supported on this platform"); } } else { - // bits 2-1 are the type 0 is 32-but, 2 is 64 bit + // bits 2-1 are the type 0 is 32-bit, 2 is 64 bit match bar >> 1 & 3 { 0 => { self.bars[current_bar].bar_type = PciBarType::MemorySpace32; self.bars[current_bar].address = u64::from(bar & 0xffff_fff0); self.write_u32(current_bar_offset, 0xffff_ffff); - let size = !(self.read_u32(current_bar_offset) & 0xffff_fff0) + 1; + let size = (!(self.read_u32(current_bar_offset) & 0xffff_fff0)) + .checked_add(1) + .unwrap_or(0); self.bars[current_bar].size = u64::from(size); self.write_u32(current_bar_offset, bar); }