diff mbox

[for-2.0,1/2] hw/arm/highbank: Don't segfault on unknown CPU names

Message ID 1396533388-12069-2-git-send-email-peter.maydell@linaro.org
State Accepted
Headers show

Commit Message

Peter Maydell April 3, 2014, 1:56 p.m. UTC
If the user passes an unknown CPU name via the '-cpu' option, exit
with an error message rather than segfaulting.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/arm/highbank.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Andreas Färber April 3, 2014, 3:48 p.m. UTC | #1
Am 03.04.2014 15:56, schrieb Peter Maydell:
> If the user passes an unknown CPU name via the '-cpu' option, exit
> with an error message rather than segfaulting.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  hw/arm/highbank.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
> index f66d57b..03545aa 100644
> --- a/hw/arm/highbank.c
> +++ b/hw/arm/highbank.c
> @@ -233,6 +233,11 @@ static void calxeda_init(QEMUMachineInitArgs *args, enum cxmachines machine)
>          ARMCPU *cpu;
>          Error *err = NULL;
>  
> +        if (!oc) {
> +            fprintf(stderr, "Unable to find CPU definition\n");

Old habits die hard... error_report() please.

Otherwise looks good.

One side effect of the cpu_arm_init() inlining here is that it didn't
get the properties support for -cpu, I note.

Regards,
Andreas

> +            exit(1);
> +        }
> +
>          cpu = ARM_CPU(object_new(object_class_get_name(oc)));
>  
>          object_property_set_int(OBJECT(cpu), MPCORE_PERIPHBASE, "reset-cbar",
>
diff mbox

Patch

diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
index f66d57b..03545aa 100644
--- a/hw/arm/highbank.c
+++ b/hw/arm/highbank.c
@@ -233,6 +233,11 @@  static void calxeda_init(QEMUMachineInitArgs *args, enum cxmachines machine)
         ARMCPU *cpu;
         Error *err = NULL;
 
+        if (!oc) {
+            fprintf(stderr, "Unable to find CPU definition\n");
+            exit(1);
+        }
+
         cpu = ARM_CPU(object_new(object_class_get_name(oc)));
 
         object_property_set_int(OBJECT(cpu), MPCORE_PERIPHBASE, "reset-cbar",