Prechádzať zdrojové kódy

Fix addition overflow bug with BAR size.

Andrew Walbran 2 rokov pred
rodič
commit
b0185cbd64
1 zmenil súbory, kde vykonal 3 pridanie a 1 odobranie
  1. 3 1
      src/transport/pci/bus.rs

+ 3 - 1
src/transport/pci/bus.rs

@@ -255,7 +255,9 @@ impl PciRoot {
         // Get the size of the BAR.
         self.config_write_word(device_function, BAR0_OFFSET + 4 * bar_index, 0xffffffff);
         let size_mask = self.config_read_word(device_function, BAR0_OFFSET + 4 * bar_index);
-        let size = !(size_mask & 0xfffffff0) + 1;
+        // A wrapping add is necessary to correctly handle the case of unused BARs, which read back
+        // as 0, and should be treated as size 0.
+        let size = (!(size_mask & 0xfffffff0)).wrapping_add(1);
 
         // Restore the original value.
         self.config_write_word(device_function, BAR0_OFFSET + 4 * bar_index, bar_orig);