Error handling in cpu_x86_create
Hi Igor,
just noticed by chance that error handling in cpu_x86_create is likely broken after your changes. Any error after cpu = ...object_new() will not properly release the CPU object again nor report NULL to the caller. That means errors should slip through, no? And cpu_x86_init looks similar.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Quoted 6 lines · On Tue, 30 Jul 2013 13:00:40 +0200 Jan Kiszka <[email protected]> wrote:
Hi Igor,
just noticed by chance that error handling in
cpu_x86_createis likely broken after your changes. Any error after cpu = ...object_new() will not properly release the CPU object again nor report NULL to the caller. That means errors should slip through, no? Andcpu_x86_initlooks similar.
Failure of object_new() in cpu_x86_create() is not checked since it should never fail.
As for following error handling caller of cpu_x86_create(..., errp) should use errp to check for errors and release failed cpu.
cpu_x86_init() that calls it has:
===
out:
if (error) {
fprintf(stderr, "%s\n", error_get_pretty(error));
error_free(error);
if (cpu != NULL) {
object_unref(OBJECT(cpu));===
similar code-path exists in pc_new_cpu()
end goal is to replace cpu_x86_create() with just object_new(FOO_CPU), but that needs to x86 CPU subclasses and properties in place so we could remove/isolate legacy stuff to legacy hook.
Did you hit any particular problem with current code?
Quoted 3 lines
Jan
Quoted 18 lines · Igor Mammedov
Quoted 6 lines · On Tue, 30 Jul 2013 13:00:40 +0200 Jan Kiszka <[email protected]> wrote:
Hi Igor,
just noticed by chance that error handling in
cpu_x86_createis likely broken after your changes. Any error after cpu = ...object_new() will not properly release the CPU object again nor report NULL to the caller. That means errors should slip through, no? Andcpu_x86_initlooks similar.Failure of
object_new()incpu_x86_create()is not checked since it should never fail.As for following error handling caller of
cpu_x86_create(..., errp)should use errp to check for errors and release failed cpu.
cpu_x86_init()that calls it has:
===
out:
Quoted 7 lines
if (error) { fprintf(stderr, "%s\n", error_get_pretty(error)); error_free(error); if (cpu != NULL) { object_unref(OBJECT(cpu));===
similar code-path exists inpc_new_cpu()
Not truly:
cpu = cpu_x86_create(cpu_model, icc_bridge, errp);
if (!cpu) {
return cpu;
}
object_property_set_int(OBJECT(cpu), apic_id, "apic-id", &local_err);
object_property_set_bool(OBJECT(cpu), true, "realized", &local_err);
if (local_err) {
if (cpu != NULL) {
object_unref(OBJECT(cpu));
cpu = NULL;
}That's what made me think the error is supposed to be derived from cpu == NULL, rather than from errp. So the actual uncleanness is here: errp should be checked instead of cpu, right?
Jan
Quoted 11 lines
end goal is to replace
cpu_x86_create()with justobject_new(FOO_CPU), but that needs to x86 CPU subclasses and properties in place so we could remove/isolate legacy stuff to legacy hook.Did you hit any particular problem with current code?
Quoted 3 lines
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
PATCH 1/1 target-i386: Fix X86CPU error handling
In reply to Jan KiszkaError **errp argument is not for emitting warnings, it means an error has occurred and the caller should not make any assumptions about the state of other return values (unless otherwise documented).
Therefore cpu_x86_create() must unref the new X86CPU itself, and pc_new_cpu() must check for an Error rather than NULL return value.
While at it, clean up a superfluous NULL check.
--- hw/i386/pc.c | 13 ++++++------- target-i386/cpu.c | 6 +++++- 2 files changed, 11 insertions(+), 8 deletions(-)
hw/i386/pc.c +6 -7
@@ -912,20 +912,19 @@ static X86CPU *pc_new_cpu(const char *cpu_model, int64_t apic_id,X86CPU *cpu;Error *local_err =NULL ; - cpu =cpu_x86_create (cpu_model, icc_bridge, errp); -if (!cpu) { -return cpu; + cpu =cpu_x86_create (cpu_model, icc_bridge, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return NULL ; }object_property_set_int (OBJECT (cpu), apic_id,"apic-id" , &local_err);object_property_set_bool (OBJECT (cpu), true,"realized" , &local_err);if (local_err) { -if (cpu !=NULL ) { -object_unref (OBJECT (cpu)); - cpu =NULL ; - }error_propagate (errp, local_err); +object_unref (OBJECT (cpu)); + cpu =NULL ; }return cpu; }
target-i386/cpu.c +5 -1
@@ -1824,7 +1824,11 @@ X86CPU *cpu_x86_create(const char *cpu_model, DeviceState *icc_bridge, } out: -error_propagate (errp, error); +if (error !=NULL ) { +error_propagate (errp, error); +object_unref (OBJECT (cpu)); + cpu =NULL ; + }g_strfreev (model_pieces);return cpu; }
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH for-1.6] target-i386: Fix X86CPU error handling
Am 02.08.2013 19:22, schrieb Andreas Färber:
Quoted 7 lines
Error **errp argument is not for emitting warnings, it means an error has occurred and the caller should not make any assumptions about the state of other return values (unless otherwise documented).
Therefore
cpu_x86_create()must unref the new X86CPU itself, andpc_new_cpu()must check for an Error rather than NULL return value.
Quoted 6 lines
While at it, clean up a superfluous NULL check.
Reported-by Jan Kiszka <[email protected]>Cc Igor Mammedov <[email protected]>Signed-off-by Andreas Färber <[email protected]>
Ping! Jan, does this address your concerns / use cases? -rc2 is on Wednesday.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH for-1.6] target-i386: Fix X86CPU error handling
Quoted 10 lines · Andreas Färber
Am 02.08.2013 19:22, schrieb Andreas Färber:
Quoted 9 lines
Error **errp argument is not for emitting warnings, it means an error has occurred and the caller should not make any assumptions about the state of other return values (unless otherwise documented).
Therefore
cpu_x86_create()must unref the new X86CPU itself, andpc_new_cpu()must check for an Error rather than NULL return value.While at it, clean up a superfluous NULL check.
Quoted 7 lines
Quoted 4 lines
Reported-by Jan Kiszka <[email protected]>Cc Igor Mammedov <[email protected]>Signed-off-by Andreas Färber <[email protected]>Ping! Jan, does this address your concerns / use cases? -rc2 is on Wednesday.
Yes, thanks, this looks good.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux