diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2018-05-15 15:25:31 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-06-01 14:15:10 +0200 |
commit | 45641dba38f6f44c3ea44c2d1c37b31619276ce3 (patch) | |
tree | 5febfc35851a4aeedf05c68c1ee92655cf742e03 /hw | |
parent | e40077fd2ccbf4ffa8d07f186110fac240a45bf9 (diff) | |
download | qemu-45641dba38f6f44c3ea44c2d1c37b31619276ce3.zip qemu-45641dba38f6f44c3ea44c2d1c37b31619276ce3.tar.gz qemu-45641dba38f6f44c3ea44c2d1c37b31619276ce3.tar.bz2 |
virtio: free MemoryRegionCache when initialization fails
Diffstat (limited to 'hw')
-rw-r--r-- | hw/virtio/virtio.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 1debb01..d4e4d98 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; |