Skip to contentSkip to conversation

pc-dimm: fix error messages if no slots were defined

PATCH Applied David Hildenbrand 4 participants 4 messages Apr 27, 2018 – May 2, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pc-dimm: fix error messages if no slots were defined

If no slots were defined we try to allocate an empty bitmap, which fails.

---

v1 -> v2: more detailed error message

 hw/mem/pc-dimm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
hw/mem/pc-dimm.c +8 -1
index 0119c68e01..12da89d562 100644
@@ -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 */
Signature · 1 line
2.14.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 24 lines · David Hildenbrand

If no slots were defined we try to allocate an empty bitmap, which fails.

---

v1 -> v2: more detailed error message

 hw/mem/pc-dimm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
hw/mem/pc-dimm.c +1 -1
index 0119c68e01..12da89d562 100644
@@ -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;
 

hw/mem/pc-dimm.c static int pc_dimm_slot2bitmap(Object *obj, void *opaque) · line 133

Quoted 10 lines
hw/mem/pc-dimm.c +7 -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 */

Thanks,
Marcel

Reviewed-by on v2 1/1
#2 lore raw
In reply to David Hildenbrand
Quoted 17 lines · David Hildenbrand

If no slots were defined we try to allocate an empty bitmap, which fails.

---

v1 -> v2: more detailed error message

 hw/mem/pc-dimm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
hw/mem/pc-dimm.c +0 -0
index 0119c68e01..12da89d562 100644
@@ -118,9 +118,16 @@ static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 

hw/mem/pc-dimm.c static int pc_dimm_slot2bitmap(Object *obj, void *opaque) · line 127

Quoted 10 lines
hw/mem/pc-dimm.c +5 -1
 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;

In case you respin, I'd maybe rather return -1 here.

But since this is not used by the caller anyway in case of errors:

#3 lore raw
Quoted 31 lines · Thomas Huth
Quoted 17 lines · David Hildenbrand

If no slots were defined we try to allocate an empty bitmap, which fails.

---

v1 -> v2: more detailed error message

 hw/mem/pc-dimm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
hw/mem/pc-dimm.c +0 -0
index 0119c68e01..12da89d562 100644
@@ -118,9 +118,16 @@ static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
 

hw/mem/pc-dimm.c static int pc_dimm_slot2bitmap(Object *obj, void *opaque) · line 127

Quoted 10 lines
hw/mem/pc-dimm.c +5 -1
 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;

In case you respin, I'd maybe rather return -1 here.

Quoted 4 lines

But since this is not used by the caller anyway in case of errors:

Queued, thanks all.

Paolo