From 48d1729e2f5b7bd46ae54197b51f5034d5e36455 Mon Sep 17 00:00:00 2001 From: Camilo Jacomet Date: Wed, 9 Dec 2020 19:42:27 +0000 Subject: [PATCH] Fixed or_fun_call warnings in kvm/ BUG=chromium:1111728 TEST=cargo clippy -- -A clippy::all -W clippy::or_fun_call passes under kvm directory Change-Id: I7677856f2944f3d4e1c92d2f6ec75763faa5ee42 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2582942 Tested-by: Camilo Jacomet Commit-Queue: Camilo Jacomet Reviewed-by: Dylan Reid Reviewed-by: Zach Reizner --- base/src/mmap.rs | 8 ++++---- kvm/src/lib.rs | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/base/src/mmap.rs b/base/src/mmap.rs index e62f0744a8..85b6acd1b6 100644 --- a/base/src/mmap.rs +++ b/base/src/mmap.rs @@ -128,7 +128,7 @@ impl<'a> MemoryMappingBuilder<'a> { } MemoryMappingBuilder::wrap(SysUtilMmap::new_protection( self.size, - self.protection.unwrap_or(Protection::read_write()), + self.protection.unwrap_or_else(Protection::read_write), )) } Some(descriptor) => { @@ -136,7 +136,7 @@ impl<'a> MemoryMappingBuilder<'a> { &wrap_descriptor(descriptor), self.size, self.offset.unwrap_or(0), - self.protection.unwrap_or(Protection::read_write()), + self.protection.unwrap_or_else(Protection::read_write), self.populate, )) } @@ -161,7 +161,7 @@ impl<'a> MemoryMappingBuilder<'a> { None => MemoryMappingBuilder::wrap(SysUtilMmap::new_protection_fixed( addr, self.size, - self.protection.unwrap_or(Protection::read_write()), + self.protection.unwrap_or_else(Protection::read_write), )), Some(descriptor) => { MemoryMappingBuilder::wrap(SysUtilMmap::from_fd_offset_protection_fixed( @@ -169,7 +169,7 @@ impl<'a> MemoryMappingBuilder<'a> { &wrap_descriptor(descriptor), self.size, self.offset.unwrap_or(0), - self.protection.unwrap_or(Protection::read_write()), + self.protection.unwrap_or_else(Protection::read_write), )) } } diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index c2ac848cdc..c38c3af2e3 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -330,7 +330,9 @@ impl Vm { log_dirty_pages: bool, ) -> Result { let size = mem.size() as u64; - let end_addr = guest_addr.checked_add(size).ok_or(Error::new(EOVERFLOW))?; + let end_addr = guest_addr + .checked_add(size) + .ok_or_else(|| Error::new(EOVERFLOW))?; if self.guest_mem.range_overlap(guest_addr, end_addr) { return Err(Error::new(ENOSPC)); }