devices: vfio: take a slice instead of Vec for irq_enable

Generalize the irq_enable() interface to accept a slice instead of a
Vec.  This also fixes a few instances of the new clippy warning about
calling Vec::new() immediately followed by inserting items.

BUG=None
TEST=bin/clippy

Change-Id: If4c66999a245f340f54c96ccafc904c99bedf1ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2864364
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2021-04-30 13:15:46 -07:00 committed by Commit Bot
parent 87ca23156d
commit 19a12403cf
2 changed files with 10 additions and 8 deletions

View file

@ -547,9 +547,10 @@ impl VfioPciDevice {
}
if let Some(ref interrupt_evt) = self.interrupt_evt {
let mut fds = Vec::new();
fds.push(interrupt_evt);
if let Err(e) = self.device.irq_enable(fds, VFIO_PCI_INTX_IRQ_INDEX) {
if let Err(e) = self
.device
.irq_enable(&[interrupt_evt], VFIO_PCI_INTX_IRQ_INDEX)
{
error!("Intx enable failed: {}", e);
return;
}
@ -617,9 +618,7 @@ impl VfioPciDevice {
}
};
let mut fds = Vec::new();
fds.push(irqfd);
if let Err(e) = self.device.irq_enable(fds, VFIO_PCI_MSI_IRQ_INDEX) {
if let Err(e) = self.device.irq_enable(&[irqfd], VFIO_PCI_MSI_IRQ_INDEX) {
error!("failed to enable msi: {}", e);
self.enable_intx();
return;
@ -646,7 +645,10 @@ impl VfioPciDevice {
};
if let Some(descriptors) = irqfds {
if let Err(e) = self.device.irq_enable(descriptors, VFIO_PCI_MSIX_IRQ_INDEX) {
if let Err(e) = self
.device
.irq_enable(&descriptors, VFIO_PCI_MSIX_IRQ_INDEX)
{
error!("failed to enable msix: {}", e);
self.enable_intx();
return;

View file

@ -391,7 +391,7 @@ impl VfioDevice {
/// Enable vfio device's irq and associate Irqfd Event with device.
/// When MSIx is enabled, multi vectors will be supported, so descriptors is vector and the vector
/// length is the num of MSIx vectors
pub fn irq_enable(&self, descriptors: Vec<&Event>, index: u32) -> Result<(), VfioError> {
pub fn irq_enable(&self, descriptors: &[&Event], index: u32) -> Result<(), VfioError> {
let count = descriptors.len();
let u32_size = mem::size_of::<u32>();
let mut irq_set = vec_with_array_field::<vfio_irq_set, u32>(count);