X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=util%2Fvfio-helpers.c;h=2367fe8f7fe84dc8b68c33bfbcaa4a11cc0277b4;hb=f34edbc760b0f689deddd175fc08732ecb46665f;hp=f478b68400e922aa3e189d0fdf63deeba0461063;hpb=418026ca43bc2626db092d7558258f9594366f28;p=mirror_qemu.git diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index f478b68400..2367fe8f7f 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -104,7 +104,7 @@ static char *sysfs_find_group_file(const char *device, Error **errp) char *path = NULL; sysfs_link = g_strdup_printf("/sys/bus/pci/devices/%s/iommu_group", device); - sysfs_group = g_malloc(PATH_MAX); + sysfs_group = g_malloc0(PATH_MAX); if (readlink(sysfs_link, sysfs_group, PATH_MAX - 1) == -1) { error_setg_errno(errp, errno, "Failed to find iommu group sysfs path"); goto out; @@ -348,7 +348,7 @@ static int qemu_vfio_init_pci(QEMUVFIOState *s, const char *device, goto fail; } - for (i = 0; i < 6; i++) { + for (i = 0; i < ARRAY_SIZE(s->bar_region_info); i++) { ret = qemu_vfio_pci_init_bar(s, i, errp); if (ret) { goto fail; @@ -391,10 +391,10 @@ static void qemu_vfio_ram_block_removed(RAMBlockNotifier *n, } } -static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr, - ram_addr_t offset, ram_addr_t length, - void *opaque) +static int qemu_vfio_init_ramblock(RAMBlock *rb, void *opaque) { + void *host_addr = qemu_ram_get_host_addr(rb); + ram_addr_t length = qemu_ram_get_used_length(rb); int ret; QEMUVFIOState *s = opaque; @@ -411,13 +411,13 @@ static int qemu_vfio_init_ramblock(const char *block_name, void *host_addr, static void qemu_vfio_open_common(QEMUVFIOState *s) { + qemu_mutex_init(&s->lock); s->ram_notifier.ram_block_added = qemu_vfio_ram_block_added; s->ram_notifier.ram_block_removed = qemu_vfio_ram_block_removed; ram_block_notifier_add(&s->ram_notifier); s->low_water_mark = QEMU_VFIO_IOVA_MIN; s->high_water_mark = QEMU_VFIO_IOVA_MAX; qemu_ram_foreach_block(qemu_vfio_init_ramblock, s); - qemu_mutex_init(&s->lock); } /** @@ -522,8 +522,7 @@ static IOVAMapping *qemu_vfio_add_mapping(QEMUVFIOState *s, assert(index >= 0); s->nr_mappings++; - s->mappings = g_realloc_n(s->mappings, sizeof(s->mappings[0]), - s->nr_mappings); + s->mappings = g_renew(IOVAMapping, s->mappings, s->nr_mappings); insert = &s->mappings[index]; shift = s->nr_mappings - index - 1; if (shift) { @@ -577,8 +576,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping, memmove(mapping, &s->mappings[index + 1], sizeof(s->mappings[0]) * (s->nr_mappings - index - 1)); s->nr_mappings--; - s->mappings = g_realloc_n(s->mappings, sizeof(s->mappings[0]), - s->nr_mappings); + s->mappings = g_renew(IOVAMapping, s->mappings, s->nr_mappings); } /* Check if the mapping list is (ascending) ordered. */