block, pci, rate_limiter, vm-allocator: drop legacy numeric constants

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2024-04-29 03:47:15 +00:00 committed by Rob Bradford
parent 0816c8292f
commit f6cd3bd86d
7 changed files with 12 additions and 16 deletions

View File

@ -1631,7 +1631,7 @@ impl PunchHole for QcowFile {
let mut remaining = length; let mut remaining = length;
let mut offset = offset; let mut offset = offset;
while remaining > 0 { while remaining > 0 {
let chunk_length = min(remaining, std::usize::MAX as u64) as usize; let chunk_length = min(remaining, usize::MAX as u64) as usize;
self.deallocate_bytes(offset, chunk_length)?; self.deallocate_bytes(offset, chunk_length)?;
remaining -= chunk_length as u64; remaining -= chunk_length as u64;
offset += chunk_length as u64; offset += chunk_length as u64;

View File

@ -409,7 +409,7 @@ impl BusDevice for PciConfigMmio {
// Only allow reads to the register boundary. // Only allow reads to the register boundary.
let start = offset as usize % 4; let start = offset as usize % 4;
let end = start + data.len(); let end = start + data.len();
if end > 4 || offset > u64::from(u32::max_value()) { if end > 4 || offset > u64::from(u32::MAX) {
for d in data { for d in data {
*d = 0xff; *d = 0xff;
} }
@ -423,7 +423,7 @@ impl BusDevice for PciConfigMmio {
} }
fn write(&mut self, _base: u64, offset: u64, data: &[u8]) -> Option<Arc<Barrier>> { fn write(&mut self, _base: u64, offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
if offset > u64::from(u32::max_value()) { if offset > u64::from(u32::MAX) {
return None; return None;
} }
self.config_space_write(offset as u32, offset % 4, data); self.config_space_write(offset as u32, offset % 4, data);

View File

@ -743,7 +743,7 @@ impl PciConfiguration {
.ok_or(Error::BarAddressInvalid(config.addr, config.size))?; .ok_or(Error::BarAddressInvalid(config.addr, config.size))?;
match config.region_type { match config.region_type {
PciBarRegionType::Memory32BitRegion | PciBarRegionType::IoRegion => { PciBarRegionType::Memory32BitRegion | PciBarRegionType::IoRegion => {
if end_addr > u64::from(u32::max_value()) { if end_addr > u64::from(u32::MAX) {
return Err(Error::BarAddressInvalid(config.addr, config.size)); return Err(Error::BarAddressInvalid(config.addr, config.size));
} }
@ -814,7 +814,7 @@ impl PciConfiguration {
.checked_add(config.size - 1) .checked_add(config.size - 1)
.ok_or(Error::RomBarAddressInvalid(config.addr, config.size))?; .ok_or(Error::RomBarAddressInvalid(config.addr, config.size))?;
if end_addr > u64::from(u32::max_value()) { if end_addr > u64::from(u32::MAX) {
return Err(Error::RomBarAddressInvalid(config.addr, config.size)); return Err(Error::RomBarAddressInvalid(config.addr, config.size));
} }

View File

@ -11,7 +11,6 @@ use std::any::Any;
use std::os::unix::prelude::AsRawFd; use std::os::unix::prelude::AsRawFd;
use std::ptr::null_mut; use std::ptr::null_mut;
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::u32;
use thiserror::Error; use thiserror::Error;
use vfio_bindings::bindings::vfio::*; use vfio_bindings::bindings::vfio::*;
use vfio_ioctls::VfioIrq; use vfio_ioctls::VfioIrq;

View File

@ -367,7 +367,7 @@ pub(crate) mod tests {
assert!(h.as_raw_fd() > 0); assert!(h.as_raw_fd() > 0);
// ops/s limiter should be disabled so consume(whatever) should work // ops/s limiter should be disabled so consume(whatever) should work
assert!(h.consume(u64::max_value(), TokenType::Ops)); assert!(h.consume(u64::MAX, TokenType::Ops));
// do full 1000 bytes // do full 1000 bytes
assert!(h.consume(1000, TokenType::Bytes)); assert!(h.consume(1000, TokenType::Bytes));
@ -403,7 +403,7 @@ pub(crate) mod tests {
assert!(h.as_raw_fd() > 0); assert!(h.as_raw_fd() > 0);
// bytes/s limiter should be disabled so consume(whatever) should work // bytes/s limiter should be disabled so consume(whatever) should work
assert!(h.consume(u64::max_value(), TokenType::Bytes)); assert!(h.consume(u64::MAX, TokenType::Bytes));
// do full 1000 ops // do full 1000 ops
assert!(h.consume(1000, TokenType::Ops)); assert!(h.consume(1000, TokenType::Ops));

View File

@ -662,8 +662,8 @@ pub(crate) mod tests {
// limiter should not be blocked // limiter should not be blocked
assert!(!l.is_blocked()); assert!(!l.is_blocked());
// limiter should be disabled so consume(whatever) should work // limiter should be disabled so consume(whatever) should work
assert!(l.consume(u64::max_value(), TokenType::Ops)); assert!(l.consume(u64::MAX, TokenType::Ops));
assert!(l.consume(u64::max_value(), TokenType::Bytes)); assert!(l.consume(u64::MAX, TokenType::Bytes));
// calling the handler without there having been an event should error // calling the handler without there having been an event should error
assert!(l.event_handler().is_err()); assert!(l.event_handler().is_err());
assert_eq!( assert_eq!(
@ -721,7 +721,7 @@ pub(crate) mod tests {
assert!(l.as_raw_fd() > 0); assert!(l.as_raw_fd() > 0);
// ops/s limiter should be disabled so consume(whatever) should work // ops/s limiter should be disabled so consume(whatever) should work
assert!(l.consume(u64::max_value(), TokenType::Ops)); assert!(l.consume(u64::MAX, TokenType::Ops));
// do full 1000 bytes // do full 1000 bytes
assert!(l.consume(1000, TokenType::Bytes)); assert!(l.consume(1000, TokenType::Bytes));
@ -754,7 +754,7 @@ pub(crate) mod tests {
assert!(l.as_raw_fd() > 0); assert!(l.as_raw_fd() > 0);
// bytes/s limiter should be disabled so consume(whatever) should work // bytes/s limiter should be disabled so consume(whatever) should work
assert!(l.consume(u64::max_value(), TokenType::Bytes)); assert!(l.consume(u64::MAX, TokenType::Bytes));
// do full 1000 ops // do full 1000 ops
assert!(l.consume(1000, TokenType::Ops)); assert!(l.consume(1000, TokenType::Ops));

View File

@ -219,10 +219,7 @@ mod tests {
#[test] #[test]
fn new_fails_overflow() { fn new_fails_overflow() {
assert_eq!( assert_eq!(AddressAllocator::new(GuestAddress(u64::MAX), 0x100), None);
AddressAllocator::new(GuestAddress(u64::max_value()), 0x100),
None
);
} }
#[test] #[test]