If not slots were defined we try to allocate an empty bitmap, which
fails.
Signed-off-by: David Hildenbrand <[email protected]>
---
This fixes the queued patch "exec: Allow memory regions with size 0"
hw/mem/pc-dimm.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 0119c68e01..f2c140947d 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -118,9 +118,15 @@ 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 free slots available");
+ return slot;
+ }
+
+ bitmap = bitmap_new(max_slots);
object_child_foreach(qdev_get_machine(), pc_dimm_slot2bitmap, bitmap);
/* check if requested slot is not occupied */
--
2.14.3