summary refs log tree commit diff stats
path: root/hw/mem/pc-dimm.c
diff options
context:
space:
mode:
authorDavid Hildenbrand <david@redhat.com>2018-04-27 14:05:15 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2018-05-11 14:33:40 +0200
commit3ff333effa319df6178f138d9cf32e3937419790 (patch)
tree2894b77989108a9136fe4ef70df3a822083fd42a /hw/mem/pc-dimm.c
parent814e1110d51f287f5616ffc04b788f6477519560 (diff)
downloadfocaccia-qemu-3ff333effa319df6178f138d9cf32e3937419790.tar.gz
focaccia-qemu-3ff333effa319df6178f138d9cf32e3937419790.zip
pc-dimm: fix error messages if no slots were defined
If no slots were defined we try to allocate an empty bitmap, which
fails.

Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20180427120515.24067-1-david@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/mem/pc-dimm.c')
-rw-r--r--hw/mem/pc-dimm.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 0119c68e01..12da89d562 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -118,9 +118,16 @@ static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 
 int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp)
 {
-    unsigned long *bitmap = bitmap_new(max_slots);
+    unsigned long *bitmap;
     int slot = 0;
 
+    if (max_slots <= 0) {
+        error_setg(errp, "no slots where allocated, please specify "
+                   "the 'slots' option");
+        return slot;
+    }
+
+    bitmap = bitmap_new(max_slots);
     object_child_foreach(qdev_get_machine(), pc_dimm_slot2bitmap, bitmap);
 
     /* check if requested slot is not occupied */