]> xenbits.xensource.com Git - qemu-upstream-4.6-testing.git/commitdiff
memory: Lazy init name from QOM name as needed
authorPeter Crosthwaite <peter.crosthwaite@xilinx.com>
Tue, 26 Aug 2014 03:10:24 +0000 (20:10 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 28 Aug 2014 14:09:44 +0000 (16:09 +0200)
To support name retrieval of MemoryRegions that were created
dynamically (that is, not via memory_region_init and friends). We
cache the name in MemoryRegion's state as
object_get_canonical_path_component mallocs the returned value
so it's not suitable for direct return to callers. Memory already
frees the name field, so this will be garbage collected along with
the MR object.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
memory.c

index 42317a216d0e8c55881eb9219ec3be280a337a9e..ef0be1c3aac7a4c2ce41686e04bfb9cd4d6bc1e8 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -1309,6 +1309,10 @@ uint64_t memory_region_size(MemoryRegion *mr)
 
 const char *memory_region_name(const MemoryRegion *mr)
 {
+    if (!mr->name) {
+        ((MemoryRegion *)mr)->name =
+            object_get_canonical_path_component(OBJECT(mr));
+    }
     return mr->name;
 }