[Qemu-devel] [PATCH v2] pc-dimm: fix error messages if no slots were defined

David Hildenbrand posted 1 patch 7 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180427120515.24067-1-david@redhat.com
Test checkpatch passed
Test docker-build@min-glib passed
Test docker-mingw@fedora passed
Test s390x passed
hw/mem/pc-dimm.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
[Qemu-devel] [PATCH v2] pc-dimm: fix error messages if no slots were defined
Posted by David Hildenbrand 7 years, 6 months ago
If no slots were defined we try to allocate an empty bitmap, which
fails.

Signed-off-by: David Hildenbrand <david@redhat.com>
---

v1 -> v2: more detailed error message

 hw/mem/pc-dimm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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 */
-- 
2.14.3


Re: [Qemu-devel] [PATCH v2] pc-dimm: fix error messages if no slots were defined
Posted by Marcel Apfelbaum 7 years, 6 months ago
On 27/04/2018 15:05, David Hildenbrand wrote:
> If no slots were defined we try to allocate an empty bitmap, which
> fails.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> 
> v1 -> v2: more detailed error message
> 
>  hw/mem/pc-dimm.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> 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 */
> 

Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>

Thanks,
Marcel

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2] pc-dimm: fix error messages if no slots were defined
Posted by Thomas Huth 7 years, 6 months ago
On 27.04.2018 14:05, David Hildenbrand wrote:
> If no slots were defined we try to allocate an empty bitmap, which
> fails.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> 
> v1 -> v2: more detailed error message
> 
>  hw/mem/pc-dimm.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> 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;

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:

Reviewed-by: Thomas Huth <thuth@redhat.com>

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2] pc-dimm: fix error messages if no slots were defined
Posted by Paolo Bonzini 7 years, 5 months ago
On 27/04/2018 18:25, Thomas Huth wrote:
> On 27.04.2018 14:05, David Hildenbrand wrote:
>> If no slots were defined we try to allocate an empty bitmap, which
>> fails.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>
>> v1 -> v2: more detailed error message
>>
>>  hw/mem/pc-dimm.c | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> 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;
> 
> 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:
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> 

Queued, thanks all.

Paolo