pc-dimm: fix error messages if no slots were defined
authorDavid Hildenbrand <david@redhat.com>
Fri, 27 Apr 2018 12:05:15 +0000 (14:05 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 11 May 2018 12:33:40 +0000 (14:33 +0200)
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>
hw/mem/pc-dimm.c

index 0119c68e0107380f70cd6cf4900add2c8217f7bc..12da89d5626e2d2544c8930a44c961ae814a3d6b 100644 (file)
@@ -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 */