From e2d619d6f028bd4ce11a7565b907f876a3983a7f Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 1 Jul 2024 14:24:12 -0700 Subject: [PATCH] hypervisor: kvm: avoid unnecessary PathBuf allocation Create a Path directly in Kvm::new() rather than constructing a PathBuf and borrowing it. BUG=None TEST=tools/dev_container tools/presubmit Change-Id: Icf46c48dc2dde3548cc796fc0162d5b57d4ad9bd Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5671064 Commit-Queue: Daniel Verkamp Reviewed-by: Frederick Mayle --- hypervisor/src/kvm/mod.rs | 5 ++--- kvm/src/lib.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index bf63d1c1ab..e600183216 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -27,7 +27,6 @@ use std::os::raw::c_ulong; use std::os::raw::c_void; use std::os::unix::prelude::OsStrExt; use std::path::Path; -use std::path::PathBuf; use std::ptr::copy_nonoverlapping; use std::sync::Arc; @@ -190,9 +189,9 @@ impl Kvm { }) } - /// Opens `/dev/kvm/` and returns a Kvm object on success. + /// Opens `/dev/kvm` and returns a Kvm object on success. pub fn new() -> Result { - Kvm::new_with_path(&PathBuf::from("/dev/kvm")) + Kvm::new_with_path(Path::new("/dev/kvm")) } } diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index ca71f6c11f..5edcf37b1b 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -23,7 +23,6 @@ use std::ops::DerefMut; use std::os::raw::*; use std::os::unix::prelude::OsStrExt; use std::path::Path; -use std::path::PathBuf; use std::ptr::copy_nonoverlapping; use std::sync::Arc; @@ -141,9 +140,9 @@ pub struct Kvm { } impl Kvm { - /// Opens `/dev/kvm/` and returns a Kvm object on success. + /// Opens `/dev/kvm` and returns a Kvm object on success. pub fn new() -> Result { - Kvm::new_with_path(&PathBuf::from("/dev/kvm")) + Kvm::new_with_path(Path::new("/dev/kvm")) } /// Opens a KVM device at `device_path` and returns a Kvm object on success.