* [Qemu-devel] [PATCH for-1.1] target-arm: Fix crash when passed "-cpu foo"
@ 2012-05-09 14:54 Peter Maydell
2012-05-09 16:07 ` Andreas Färber
0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2012-05-09 14:54 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, patches
The macro definition of cpu_init meant that if cpu_arm_init()
returned NULL this wouldn't result in cpu_init() itself returning
NULL. This had the effect that "-cpu foo" for some unknown CPU
name 'foo' would cause ARM targets to segfault rather than
generating a useful error message. Fix this by making cpu_init
a simple inline function.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
I did a quick grep and I think ARM is the only target at the moment
where we've made this change to cpu_init -- is that right, Andreas?
target-arm/cpu.h | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 5eac070..d01285f 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -458,7 +458,15 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init(model) (&cpu_arm_init(model)->env)
+static inline CPUARMState *cpu_init(const char *cpu_model)
+{
+ ARMCPU *cpu = cpu_arm_init(cpu_model);
+ if (cpu) {
+ return &cpu->env;
+ }
+ return NULL;
+}
+
#define cpu_exec cpu_arm_exec
#define cpu_gen_code cpu_arm_gen_code
#define cpu_signal_handler cpu_arm_signal_handler
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH for-1.1] target-arm: Fix crash when passed "-cpu foo"
2012-05-09 14:54 [Qemu-devel] [PATCH for-1.1] target-arm: Fix crash when passed "-cpu foo" Peter Maydell
@ 2012-05-09 16:07 ` Andreas Färber
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Färber @ 2012-05-09 16:07 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel, patches
Am 09.05.2012 16:54, schrieb Peter Maydell:
> The macro definition of cpu_init meant that if cpu_arm_init()
> returned NULL this wouldn't result in cpu_init() itself returning
> NULL. This had the effect that "-cpu foo" for some unknown CPU
> name 'foo' would cause ARM targets to segfault rather than
> generating a useful error message. Fix this by making cpu_init
> a simple inline function.
Ouch.
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> I did a quick grep and I think ARM is the only target at the moment
> where we've made this change to cpu_init -- is that right, Andreas?
Affirmative for master. But I need to respin my qom-cpu-reset series
(QOM CPUState part 3) and the followups I have queued.
> target-arm/cpu.h | 10 +++++++++-
> 1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/target-arm/cpu.h b/target-arm/cpu.h
> index 5eac070..d01285f 100644
> --- a/target-arm/cpu.h
> +++ b/target-arm/cpu.h
> @@ -458,7 +458,15 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
> #define TARGET_PHYS_ADDR_SPACE_BITS 32
> #define TARGET_VIRT_ADDR_SPACE_BITS 32
>
> -#define cpu_init(model) (&cpu_arm_init(model)->env)
> +static inline CPUARMState *cpu_init(const char *cpu_model)
> +{
> + ARMCPU *cpu = cpu_arm_init(cpu_model);
> + if (cpu) {
Personally I prefer an explicit NULL check for pointers, but it's the
same either way.
> + return &cpu->env;
> + }
> + return NULL;
> +}
> +
> #define cpu_exec cpu_arm_exec
> #define cpu_gen_code cpu_arm_gen_code
> #define cpu_signal_handler cpu_arm_signal_handler
Acked-by: Andreas Färber <afaerber@suse.de>
Thanks,
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-09 16:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-09 14:54 [Qemu-devel] [PATCH for-1.1] target-arm: Fix crash when passed "-cpu foo" Peter Maydell
2012-05-09 16:07 ` Andreas Färber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).