summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2017-01-27 16:40:12 +0100
committerMichael S. Tsirkin <mst@redhat.com>2017-02-17 21:52:30 +0200
commit1d8280c18f96f0cd96d1e7acd62f7250c4da1a84 (patch)
tree7aa34e23a97db23c79cb369519cecd309e2fc964
parent79c0f397feaea37992500eafd933e301c2306410 (diff)
downloadfocaccia-qemu-1d8280c18f96f0cd96d1e7acd62f7250c4da1a84.tar.gz
focaccia-qemu-1d8280c18f96f0cd96d1e7acd62f7250c4da1a84.zip
memory: make memory_listener_unregister idempotent
Make it easy to unregister a MemoryListener without tracking whether it
had been registered before.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--memory.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/memory.c b/memory.c
index 6c58373422..ed8b5aa83e 100644
--- a/memory.c
+++ b/memory.c
@@ -2371,8 +2371,13 @@ void memory_listener_register(MemoryListener *listener, AddressSpace *as)
 
 void memory_listener_unregister(MemoryListener *listener)
 {
+    if (!listener->address_space) {
+        return;
+    }
+
     QTAILQ_REMOVE(&memory_listeners, listener, link);
     QTAILQ_REMOVE(&listener->address_space->listeners, listener, link_as);
+    listener->address_space = NULL;
 }
 
 void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)