mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: clippy: add needless_pass_by_value
This is a follow-up of [0].
# Advantages
- This saves dozens of unneeded clone()s across the whole code base
- Makes it much easier to reason about how parameters are used
(often we passed owned Arc/Rc versions without actually needing
ownership)
# Exceptions
For certain code paths, the alternatives would require awkward or overly
complex code, and in some cases the functions are the logical owners of
the values they take. In those cases, I've added
#[allow(clippy::needless_pass_by_value)].
This does not mean that one should not improve this in the future.
[0] 6a86c157af
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
ed4af3a005
commit
c53781bf5f
@@ -262,7 +262,7 @@ impl KvmGicV3Its {
|
||||
}
|
||||
|
||||
/// Method to initialize the GIC device
|
||||
pub fn new(vm: &dyn Vm, config: VgicConfig) -> Result<KvmGicV3Its> {
|
||||
pub fn new(vm: &dyn Vm, config: &VgicConfig) -> Result<KvmGicV3Its> {
|
||||
// This is inside KVM module
|
||||
let vm = vm.as_any().downcast_ref::<KvmVm>().expect("Wrong VM type?");
|
||||
|
||||
@@ -509,7 +509,7 @@ mod unit_tests {
|
||||
let hv = crate::new().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
|
||||
KvmGicV3Its::new(&*vm, create_test_vgic_config()).unwrap();
|
||||
KvmGicV3Its::new(&*vm, &create_test_vgic_config()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -517,7 +517,7 @@ mod unit_tests {
|
||||
let hv = crate::new().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let _ = vm.create_vcpu(0, None).unwrap();
|
||||
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
|
||||
let gic = KvmGicV3Its::new(&*vm, &create_test_vgic_config()).expect("Cannot create gic");
|
||||
|
||||
let state = get_dist_regs(&gic.device).unwrap();
|
||||
assert_eq!(state.len(), 568);
|
||||
@@ -530,7 +530,7 @@ mod unit_tests {
|
||||
let hv = crate::new().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let _ = vm.create_vcpu(0, None).unwrap();
|
||||
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
|
||||
let gic = KvmGicV3Its::new(&*vm, &create_test_vgic_config()).expect("Cannot create gic");
|
||||
|
||||
let gicr_typer = vec![123];
|
||||
let state = get_redist_regs(&gic.device, &gicr_typer).unwrap();
|
||||
@@ -545,7 +545,7 @@ mod unit_tests {
|
||||
let hv = crate::new().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let _ = vm.create_vcpu(0, None).unwrap();
|
||||
let gic = KvmGicV3Its::new(&*vm, create_test_vgic_config()).expect("Cannot create gic");
|
||||
let gic = KvmGicV3Its::new(&*vm, &create_test_vgic_config()).expect("Cannot create gic");
|
||||
|
||||
let gicr_typer = vec![123];
|
||||
let state = get_icc_regs(&gic.device, &gicr_typer).unwrap();
|
||||
@@ -560,9 +560,8 @@ mod unit_tests {
|
||||
let hv = crate::new().unwrap();
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let _ = vm.create_vcpu(0, None).unwrap();
|
||||
let gic = vm
|
||||
.create_vgic(create_test_vgic_config())
|
||||
.expect("Cannot create gic");
|
||||
let vgic_config = create_test_vgic_config();
|
||||
let gic = vm.create_vgic(&vgic_config).expect("Cannot create gic");
|
||||
|
||||
gic.lock().unwrap().save_data_tables().unwrap();
|
||||
}
|
||||
|
||||
@@ -579,7 +579,7 @@ impl vm::Vm for KvmVm {
|
||||
///
|
||||
/// Creates a virtual GIC device.
|
||||
///
|
||||
fn create_vgic(&self, config: VgicConfig) -> vm::Result<Arc<Mutex<dyn Vgic>>> {
|
||||
fn create_vgic(&self, config: &VgicConfig) -> vm::Result<Arc<Mutex<dyn Vgic>>> {
|
||||
let gic_device = KvmGicV3Its::new(self, config)
|
||||
.map_err(|e| vm::HypervisorVmError::CreateVgic(anyhow!("Vgic error {e:?}")))?;
|
||||
Ok(Arc::new(Mutex::new(gic_device)))
|
||||
@@ -589,7 +589,7 @@ impl vm::Vm for KvmVm {
|
||||
///
|
||||
/// Creates a virtual AIA device.
|
||||
///
|
||||
fn create_vaia(&self, config: VaiaConfig) -> vm::Result<Arc<Mutex<dyn Vaia>>> {
|
||||
fn create_vaia(&self, config: &VaiaConfig) -> vm::Result<Arc<Mutex<dyn Vaia>>> {
|
||||
let aia_device = KvmAiaImsics::new(self, config)
|
||||
.map_err(|e| vm::HypervisorVmError::CreateVaia(anyhow!("Vaia error {e:?}")))?;
|
||||
Ok(Arc::new(Mutex::new(aia_device)))
|
||||
|
||||
@@ -180,7 +180,7 @@ impl KvmAiaImsics {
|
||||
}
|
||||
|
||||
/// Method to initialize the AIA device
|
||||
pub fn new(vm: &dyn Vm, config: VaiaConfig) -> Result<KvmAiaImsics> {
|
||||
pub fn new(vm: &dyn Vm, config: &VaiaConfig) -> Result<KvmAiaImsics> {
|
||||
// This is inside KVM module
|
||||
let vm = vm.as_any().downcast_ref::<KvmVm>().expect("Wrong VM type?");
|
||||
|
||||
@@ -270,6 +270,7 @@ mod unit_tests {
|
||||
let vm = hv.create_vm(HypervisorVmConfig::default()).unwrap();
|
||||
let _vcpu = vm.create_vcpu(0, None).unwrap();
|
||||
|
||||
assert!(KvmAiaImsics::new(&*vm, create_test_vaia_config()).is_ok());
|
||||
let vaia_config = create_test_vaia_config();
|
||||
assert!(KvmAiaImsics::new(&*vm, &vaia_config).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ impl From<MshvGicV2MState> for GicState {
|
||||
|
||||
impl MshvGicV2M {
|
||||
/// Create a new GICv2m device
|
||||
pub fn new(_vm: &dyn Vm, config: VgicConfig) -> Result<MshvGicV2M> {
|
||||
pub fn new(_vm: &dyn Vm, config: &VgicConfig) -> Result<MshvGicV2M> {
|
||||
let gic_device = MshvGicV2M {
|
||||
dist_addr: config.dist_addr,
|
||||
dist_size: config.dist_size,
|
||||
|
||||
@@ -2193,7 +2193,7 @@ impl vm::Vm for MshvVm {
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn create_vgic(&self, config: VgicConfig) -> vm::Result<Arc<Mutex<dyn Vgic>>> {
|
||||
fn create_vgic(&self, config: &VgicConfig) -> vm::Result<Arc<Mutex<dyn Vgic>>> {
|
||||
let gic_device = MshvGicV2M::new(self, config)
|
||||
.map_err(|e| vm::HypervisorVmError::CreateVgic(anyhow!("Vgic error {e:?}")))?;
|
||||
|
||||
|
||||
@@ -318,9 +318,9 @@ pub trait Vm: Send + Sync + Any {
|
||||
/// Creates a new KVM vCPU file descriptor and maps the memory corresponding
|
||||
fn create_vcpu(&self, id: u32, vm_ops: Option<Arc<dyn VmOps>>) -> Result<Box<dyn Vcpu>>;
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
fn create_vgic(&self, config: VgicConfig) -> Result<Arc<Mutex<dyn Vgic>>>;
|
||||
fn create_vgic(&self, config: &VgicConfig) -> Result<Arc<Mutex<dyn Vgic>>>;
|
||||
#[cfg(target_arch = "riscv64")]
|
||||
fn create_vaia(&self, config: VaiaConfig) -> Result<Arc<Mutex<dyn Vaia>>>;
|
||||
fn create_vaia(&self, config: &VaiaConfig) -> Result<Arc<Mutex<dyn Vaia>>>;
|
||||
|
||||
/// Registers an event to be signaled whenever a certain address is written to.
|
||||
fn register_ioevent(
|
||||
|
||||
Reference in New Issue
Block a user