diff mbox

[PULL,8/8] memory: Lazy init name from QOM name as needed

Message ID 1409235205-21376-9-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Aug. 28, 2014, 2:13 p.m. UTC
From: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

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 | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox

Patch

diff --git a/memory.c b/memory.c
index 42317a2..ef0be1c 100644
--- 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;
 }