mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 15:01:16 +00:00
pci, virtio-devices: Fix rust 1.48 clippy warnings
Unnecessary closure used to substitute value for `Option::None` See https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
a406d90059
commit
72bb255ff6
@ -570,7 +570,7 @@ impl PciConfiguration {
|
|||||||
let end_addr = config
|
let end_addr = config
|
||||||
.addr
|
.addr
|
||||||
.checked_add(config.size - 1)
|
.checked_add(config.size - 1)
|
||||||
.ok_or_else(|| 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_value()) {
|
||||||
@ -642,7 +642,7 @@ impl PciConfiguration {
|
|||||||
let end_addr = config
|
let end_addr = config
|
||||||
.addr
|
.addr
|
||||||
.checked_add(config.size - 1)
|
.checked_add(config.size - 1)
|
||||||
.ok_or_else(|| 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_value()) {
|
||||||
return Err(Error::RomBarAddressInvalid(config.addr, config.size));
|
return Err(Error::RomBarAddressInvalid(config.addr, config.size));
|
||||||
@ -698,7 +698,7 @@ impl PciConfiguration {
|
|||||||
};
|
};
|
||||||
let end_offset = cap_offset
|
let end_offset = cap_offset
|
||||||
.checked_add(total_len)
|
.checked_add(total_len)
|
||||||
.ok_or_else(|| Error::CapabilitySpaceFull(total_len))?;
|
.ok_or(Error::CapabilitySpaceFull(total_len))?;
|
||||||
if end_offset > CAPABILITY_MAX_OFFSET {
|
if end_offset > CAPABILITY_MAX_OFFSET {
|
||||||
return Err(Error::CapabilitySpaceFull(total_len));
|
return Err(Error::CapabilitySpaceFull(total_len));
|
||||||
}
|
}
|
||||||
|
@ -750,7 +750,7 @@ impl PciDevice for VfioPciDevice {
|
|||||||
// The address needs to be 4 bytes aligned.
|
// The address needs to be 4 bytes aligned.
|
||||||
bar_addr = allocator
|
bar_addr = allocator
|
||||||
.allocate_io_addresses(None, region_size, Some(0x4))
|
.allocate_io_addresses(None, region_size, Some(0x4))
|
||||||
.ok_or_else(|| PciDeviceError::IoAllocationFailed(region_size))?;
|
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?;
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
@ -797,11 +797,11 @@ impl PciDevice for VfioPciDevice {
|
|||||||
if is_64bit_bar {
|
if is_64bit_bar {
|
||||||
bar_addr = allocator
|
bar_addr = allocator
|
||||||
.allocate_mmio_addresses(None, region_size, Some(bar_alignment))
|
.allocate_mmio_addresses(None, region_size, Some(bar_alignment))
|
||||||
.ok_or_else(|| PciDeviceError::IoAllocationFailed(region_size))?;
|
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?;
|
||||||
} else {
|
} else {
|
||||||
bar_addr = allocator
|
bar_addr = allocator
|
||||||
.allocate_mmio_hole_addresses(None, region_size, Some(bar_alignment))
|
.allocate_mmio_hole_addresses(None, region_size, Some(bar_alignment))
|
||||||
.ok_or_else(|| PciDeviceError::IoAllocationFailed(region_size))?;
|
.ok_or(PciDeviceError::IoAllocationFailed(region_size))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,15 +77,15 @@ pub fn setup_vhost_user_vring(
|
|||||||
queue.desc_table,
|
queue.desc_table,
|
||||||
actual_size * std::mem::size_of::<Descriptor>(),
|
actual_size * std::mem::size_of::<Descriptor>(),
|
||||||
)
|
)
|
||||||
.ok_or_else(|| Error::DescriptorTableAddress)? as u64,
|
.ok_or(Error::DescriptorTableAddress)? as u64,
|
||||||
// The used ring is {flags: u16; idx: u16; virtq_used_elem [{id: u16, len: u16}; actual_size]},
|
// The used ring is {flags: u16; idx: u16; virtq_used_elem [{id: u16, len: u16}; actual_size]},
|
||||||
// i.e. 4 + (4 + 4) * actual_size.
|
// i.e. 4 + (4 + 4) * actual_size.
|
||||||
used_ring_addr: get_host_address_range(mem, queue.used_ring, 4 + actual_size * 8)
|
used_ring_addr: get_host_address_range(mem, queue.used_ring, 4 + actual_size * 8)
|
||||||
.ok_or_else(|| Error::UsedAddress)? as u64,
|
.ok_or(Error::UsedAddress)? as u64,
|
||||||
// The used ring is {flags: u16; idx: u16; elem [u16; actual_size]},
|
// The used ring is {flags: u16; idx: u16; elem [u16; actual_size]},
|
||||||
// i.e. 4 + (2) * actual_size.
|
// i.e. 4 + (2) * actual_size.
|
||||||
avail_ring_addr: get_host_address_range(mem, queue.avail_ring, 4 + actual_size * 2)
|
avail_ring_addr: get_host_address_range(mem, queue.avail_ring, 4 + actual_size * 2)
|
||||||
.ok_or_else(|| Error::AvailAddress)? as u64,
|
.ok_or(Error::AvailAddress)? as u64,
|
||||||
log_addr: None,
|
log_addr: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ impl VsockPacket {
|
|||||||
|
|
||||||
let mut pkt = Self {
|
let mut pkt = Self {
|
||||||
hdr: get_host_address_range(head.mem, head.addr, VSOCK_PKT_HDR_SIZE)
|
hdr: get_host_address_range(head.mem, head.addr, VSOCK_PKT_HDR_SIZE)
|
||||||
.ok_or_else(|| VsockError::GuestMemory)? as *mut u8,
|
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||||
buf: None,
|
buf: None,
|
||||||
buf_size: 0,
|
buf_size: 0,
|
||||||
};
|
};
|
||||||
@ -151,7 +151,7 @@ impl VsockPacket {
|
|||||||
pkt.buf_size = buf_desc.len as usize;
|
pkt.buf_size = buf_desc.len as usize;
|
||||||
pkt.buf = Some(
|
pkt.buf = Some(
|
||||||
get_host_address_range(buf_desc.mem, buf_desc.addr, pkt.buf_size)
|
get_host_address_range(buf_desc.mem, buf_desc.addr, pkt.buf_size)
|
||||||
.ok_or_else(|| VsockError::GuestMemory)? as *mut u8,
|
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(pkt)
|
Ok(pkt)
|
||||||
@ -183,10 +183,10 @@ impl VsockPacket {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
hdr: get_host_address_range(head.mem, head.addr, VSOCK_PKT_HDR_SIZE)
|
hdr: get_host_address_range(head.mem, head.addr, VSOCK_PKT_HDR_SIZE)
|
||||||
.ok_or_else(|| VsockError::GuestMemory)? as *mut u8,
|
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||||
buf: Some(
|
buf: Some(
|
||||||
get_host_address_range(buf_desc.mem, buf_desc.addr, buf_size)
|
get_host_address_range(buf_desc.mem, buf_desc.addr, buf_size)
|
||||||
.ok_or_else(|| VsockError::GuestMemory)? as *mut u8,
|
.ok_or(VsockError::GuestMemory)? as *mut u8,
|
||||||
),
|
),
|
||||||
buf_size,
|
buf_size,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user