[PATCH v2 6/7] hw/intc/openpic: Improve errors for out of bounds property values

Markus Armbruster posted 7 patches 1 month, 2 weeks ago
[PATCH v2 6/7] hw/intc/openpic: Improve errors for out of bounds property values
Posted by Markus Armbruster 1 month, 2 weeks ago
The error message doesn't matter much, as the "openpic" device isn't
user-creatable.  But it's the last use of
QERR_PROPERTY_VALUE_OUT_OF_RANGE, which has to go.  Change the message
just like the previous commit did for x86 CPUs.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/intc/openpic.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
index 32bd880dfa..cd3d87768e 100644
--- a/hw/intc/openpic.c
+++ b/hw/intc/openpic.c
@@ -41,7 +41,6 @@
 #include "hw/pci/msi.h"
 #include "qapi/error.h"
 #include "qemu/bitops.h"
-#include "qapi/qmp/qerror.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
 #include "qemu/error-report.h"
@@ -1535,9 +1534,7 @@ static void openpic_realize(DeviceState *dev, Error **errp)
     };
 
     if (opp->nb_cpus > MAX_CPU) {
-        error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-                   TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus,
-                   (uint64_t)0, (uint64_t)MAX_CPU);
+        error_setg(errp, "property 'nb_cpus' can be at most %d", MAX_CPU);
         return;
     }
 
-- 
2.46.0
Re: [PATCH v2 6/7] hw/intc/openpic: Improve errors for out of bounds property values
Posted by Philippe Mathieu-Daudé 1 month, 2 weeks ago
On 10/10/24 12:01, Markus Armbruster wrote:
> The error message doesn't matter much, as the "openpic" device isn't
> user-creatable.  But it's the last use of
> QERR_PROPERTY_VALUE_OUT_OF_RANGE, which has to go.  Change the message
> just like the previous commit did for x86 CPUs.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>   hw/intc/openpic.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
> index 32bd880dfa..cd3d87768e 100644
> --- a/hw/intc/openpic.c
> +++ b/hw/intc/openpic.c
> @@ -41,7 +41,6 @@
>   #include "hw/pci/msi.h"
>   #include "qapi/error.h"
>   #include "qemu/bitops.h"
> -#include "qapi/qmp/qerror.h"
>   #include "qemu/module.h"
>   #include "qemu/timer.h"
>   #include "qemu/error-report.h"
> @@ -1535,9 +1534,7 @@ static void openpic_realize(DeviceState *dev, Error **errp)
>       };
>   
>       if (opp->nb_cpus > MAX_CPU) {
> -        error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
> -                   TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus,
> -                   (uint64_t)0, (uint64_t)MAX_CPU);
> +        error_setg(errp, "property 'nb_cpus' can be at most %d", MAX_CPU);
>           return;
>       }
>   

As another cleanup we could convert MAX_CPU to unsigned.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Re: [PATCH v2 6/7] hw/intc/openpic: Improve errors for out of bounds property values
Posted by Markus Armbruster 1 month, 1 week ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> On 10/10/24 12:01, Markus Armbruster wrote:
>> The error message doesn't matter much, as the "openpic" device isn't
>> user-creatable.  But it's the last use of
>> QERR_PROPERTY_VALUE_OUT_OF_RANGE, which has to go.  Change the message
>> just like the previous commit did for x86 CPUs.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>   hw/intc/openpic.c | 5 +----
>>   1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
>> index 32bd880dfa..cd3d87768e 100644
>> --- a/hw/intc/openpic.c
>> +++ b/hw/intc/openpic.c
>> @@ -41,7 +41,6 @@
>>  #include "hw/pci/msi.h"
>>  #include "qapi/error.h"
>>  #include "qemu/bitops.h"
>> -#include "qapi/qmp/qerror.h"
>>  #include "qemu/module.h"
>>  #include "qemu/timer.h"
>>  #include "qemu/error-report.h"
>> @@ -1535,9 +1534,7 @@ static void openpic_realize(DeviceState *dev, Error **errp)
>>      };
>>
>>      if (opp->nb_cpus > MAX_CPU) {
>> -        error_setg(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
>> -                   TYPE_OPENPIC, "nb_cpus", (uint64_t)opp->nb_cpus,
>> -                   (uint64_t)0, (uint64_t)MAX_CPU);
>> +        error_setg(errp, "property 'nb_cpus' can be at most %d", MAX_CPU);
>>          return;
>>      }
>>   
>
> As another cleanup we could convert MAX_CPU to unsigned.

Existing uses are all fine as is.  Perhaps the maintainer has a
preference.

> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks!