Commit 051bab81 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼

refactor malloc()/free() by new/delete

parent afe61e5f
......@@ -576,17 +576,17 @@ VfioDevice::pciHotReset()
if (not isVfioPciDevice())
return false;
const size_t reset_infolen = sizeof(struct vfio_pci_hot_reset_info) +
const size_t reset_info_len = sizeof(struct vfio_pci_hot_reset_info) +
sizeof(struct vfio_pci_dependent_device) * 64;
auto reset_info = reinterpret_cast<struct vfio_pci_hot_reset_info *>
(calloc(1, reset_infolen));
auto *reset_info_buf = new char[reset_info_len];
auto *reset_info = reinterpret_cast<struct vfio_pci_hot_reset_info *>(reset_info_buf);
reset_info->argsz = reset_infolen;
reset_info->argsz = reset_info_len;
if (ioctl(this->fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, reset_info) != 0) {
free(reset_info);
delete[] reset_info_buf;
return false;
}
......@@ -598,26 +598,26 @@ VfioDevice::pciHotReset()
PCI_SLOT(dd->devfn), PCI_FUNC(dd->devfn), dd->group_id);
if (static_cast<int>(dd->group_id) != this->group.index) {
free(reset_info);
delete[] reset_info_buf;
return false;
}
}
free(reset_info);
delete[] reset_info_buf;
const size_t resetlen = sizeof(struct vfio_pci_hot_reset) +
const size_t reset_len = sizeof(struct vfio_pci_hot_reset) +
sizeof(int32_t) * 1;
auto reset = reinterpret_cast<struct vfio_pci_hot_reset*>
(calloc(1, resetlen));
auto *reset_buf = new char[reset_len];
auto *reset = reinterpret_cast<struct vfio_pci_hot_reset*>(reset_buf);
reset->argsz = resetlen;
reset->argsz = reset_len;
reset->count = 1;
reset->group_fds[0] = this->group.fd;
int ret = ioctl(this->fd, VFIO_DEVICE_PCI_HOT_RESET, reset);
const bool success = (ret == 0);
free(reset);
delete[] reset_buf;
if(not success and not group.container->isIommuEnabled()) {
logger->info("PCI hot reset failed, but this is expected without IOMMU");
......@@ -639,7 +639,8 @@ VfioDevice::pciMsiInit(int efds[])
const size_t irqSetSize = sizeof(struct vfio_irq_set) +
sizeof(int) * irqCount;
auto irqSet = reinterpret_cast<struct vfio_irq_set*>(calloc(1, irqSetSize));
auto *irqSetBuf = new char[irqSetSize];
auto *irqSet = reinterpret_cast<struct vfio_irq_set*>(irqSetBuf);
if(irqSet == nullptr)
return -1;
......@@ -653,7 +654,7 @@ VfioDevice::pciMsiInit(int efds[])
for (size_t i = 0; i < irqCount; i++) {
efds[i] = eventfd(0, 0);
if (efds[i] < 0) {
free(irqSet);
delete[] irqSetBuf;
return -1;
}
}
......@@ -661,11 +662,11 @@ VfioDevice::pciMsiInit(int efds[])
memcpy(irqSet->data, efds, sizeof(int) * irqCount);
if(ioctl(fd, VFIO_DEVICE_SET_IRQS, irqSet) != 0) {
free(irqSet);
delete[] irqSetBuf;
return -1;
}
free(irqSet);
delete[] irqSetBuf;
return irqCount;
}
......@@ -682,7 +683,8 @@ VfioDevice::pciMsiDeinit(int efds[])
const size_t irqSetSize = sizeof(struct vfio_irq_set) +
sizeof(int) * irqCount;
auto irqSet = reinterpret_cast<struct vfio_irq_set*>(calloc(1, irqSetSize));
auto *irqSetBuf = new char[irqSetSize];
auto *irqSet = reinterpret_cast<struct vfio_irq_set*>(irqSetBuf);
if(irqSet == nullptr)
return -1;
......@@ -700,11 +702,11 @@ VfioDevice::pciMsiDeinit(int efds[])
memcpy(irqSet->data, efds, sizeof(int) * irqCount);
if (ioctl(fd, VFIO_DEVICE_SET_IRQS, irqSet) != 0) {
free(irqSet);
delete[] irqSetBuf;
return -1;
}
free(irqSet);
delete[] irqSetBuf;
return irqCount;
}
......
......@@ -318,14 +318,14 @@ int vfio_pci_reset(struct vfio_device *d)
if (!(d->info.flags & VFIO_DEVICE_FLAGS_PCI))
return -1;
size_t reset_infolen = sizeof(struct vfio_pci_hot_reset_info) + sizeof(struct vfio_pci_dependent_device) * 64;
size_t resetlen = sizeof(struct vfio_pci_hot_reset) + sizeof(int32_t) * 1;
size_t reset_info_len = sizeof(struct vfio_pci_hot_reset_info) + sizeof(struct vfio_pci_dependent_device) * 64;
size_t reset_len = sizeof(struct vfio_pci_hot_reset) + sizeof(int32_t) * 1;
struct vfio_pci_hot_reset_info *reset_info = new char[reset_infolen];
struct vfio_pci_hot_reset *reset = new char[resetlen];
struct vfio_pci_hot_reset_info *reset_info = new char[reset_info_len];
struct vfio_pci_hot_reset *reset = new char[reset_len];
reset_info->argsz = reset_infolen;
reset->argsz = resetlen;
reset_info->argsz = reset_info_len;
reset->argsz = reset_len;
ret = ioctl(d->fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, reset_info);
if (ret)
......@@ -345,7 +345,7 @@ int vfio_pci_reset(struct vfio_device *d)
ret = ioctl(d->fd, VFIO_DEVICE_PCI_HOT_RESET, reset);
free(reset_info);
delete[] reset_info;
return ret;
}
......@@ -419,7 +419,7 @@ int vfio_pci_msi_deinit(struct vfio_device *d, int efds[32])
if (ret)
return -4;
free(irq_set);
delete[] irq_set;
return irq_count;
}
......@@ -454,7 +454,7 @@ int vfio_pci_msi_init(struct vfio_device *d, int efds[32])
if (ret)
return -4;
free(irq_set);
delete[] irq_set;
return irq_count;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment