[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 26/53] virtio: free MemoryRegionCache when initializa
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 26/53] virtio: free MemoryRegionCache when initialization fails |
Date: |
Thu, 31 May 2018 19:12:26 +0200 |
---
hw/virtio/virtio.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 1debb0147b..d4e4d98b59 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -123,11 +123,22 @@ static void
virtio_free_region_cache(VRingMemoryRegionCaches *caches)
g_free(caches);
}
+static void virtio_virtqueue_reset_region_cache(struct VirtQueue *vq)
+{
+ VRingMemoryRegionCaches *caches;
+
+ caches = atomic_read(&vq->vring.caches);
+ atomic_rcu_set(&vq->vring.caches, NULL);
+ if (caches) {
+ call_rcu(caches, virtio_free_region_cache, rcu);
+ }
+}
+
static void virtio_init_region_cache(VirtIODevice *vdev, int n)
{
VirtQueue *vq = &vdev->vq[n];
VRingMemoryRegionCaches *old = vq->vring.caches;
- VRingMemoryRegionCaches *new;
+ VRingMemoryRegionCaches *new = NULL;
hwaddr addr, size;
int event_size;
int64_t len;
@@ -136,7 +147,7 @@ static void virtio_init_region_cache(VirtIODevice *vdev,
int n)
addr = vq->vring.desc;
if (!addr) {
- return;
+ goto out_no_cache;
}
new = g_new0(VRingMemoryRegionCaches, 1);
size = virtio_queue_get_desc_size(vdev, n);
@@ -170,11 +181,14 @@ static void virtio_init_region_cache(VirtIODevice *vdev,
int n)
return;
err_avail:
- address_space_cache_destroy(&new->used);
+ address_space_cache_destroy(&new->avail);
err_used:
- address_space_cache_destroy(&new->desc);
+ address_space_cache_destroy(&new->used);
err_desc:
+ address_space_cache_destroy(&new->desc);
+out_no_cache:
g_free(new);
+ virtio_virtqueue_reset_region_cache(vq);
}
/* virt queue functions */
@@ -1168,17 +1182,6 @@ static enum virtio_device_endian
virtio_current_cpu_endian(void)
}
}
-static void virtio_virtqueue_reset_region_cache(struct VirtQueue *vq)
-{
- VRingMemoryRegionCaches *caches;
-
- caches = atomic_read(&vq->vring.caches);
- atomic_rcu_set(&vq->vring.caches, NULL);
- if (caches) {
- call_rcu(caches, virtio_free_region_cache, rcu);
- }
-}
-
void virtio_reset(void *opaque)
{
VirtIODevice *vdev = opaque;
--
2.17.0
- [Qemu-devel] [PULL 18/53] hw/misc/mips_itu: Cleanup includes, (continued)
- [Qemu-devel] [PULL 18/53] hw/misc/mips_itu: Cleanup includes, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 19/53] hw/misc/sga: Use the correct ISA include, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 17/53] hw/block/nvme: Include "qemu/cutils.h" directly in the source file, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 14/53] hw: Do not include "sysemu/block-backend.h" if it is not necessary, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 22/53] hw/ide: Remove unused include, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 21/53] hw/i386/pc: Remove unused include, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 20/53] hw/hppa: Remove unused include, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 23/53] hw: Clean "hw/devices.h" includes, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 24/53] qom: Document qom/device-list-properties implementation specific, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 25/53] qom: support orphan objects in object_get_canonical_path, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 26/53] virtio: free MemoryRegionCache when initialization fails,
Paolo Bonzini <=
- [Qemu-devel] [PULL 27/53] memory.h: Fix typo in documentation comment, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 28/53] memory: get rid of memory_region_init_reservation, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 30/53] hw/isa/superio: Fix inconsistent use of Chardev->be, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 31/53] mux: fix ctrl-a b again, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 32/53] memfd: Avoid Coverity warning about integer overflow, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 33/53] exec.c: Initialize sa_flags passed to sigaction(), Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 29/53] memory: delete struct AddressSpaceOps, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 36/53] qemu-options: Mark the non-functional -clock option as deprecated, Paolo Bonzini, 2018/05/31
- [Qemu-devel] [PULL 35/53] WHPX: fix some compiler warnings, Paolo Bonzini, 2018/05/31