Skip to content

Commit

Permalink
pci: Handle overflow on 32-bit PCI BAR size calculation
Browse files Browse the repository at this point in the history
The firmware panics if the calculated 32-bit BAR size overflows on debug
build.

Signed-off-by: Akira Moroo <[email protected]>
  • Loading branch information
retrage committed Mar 21, 2023
1 parent 37aaff9 commit 573f46c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ impl PciDevice {
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);
}
Expand Down

0 comments on commit 573f46c

Please sign in to comment.