target-i386: Clean up misuse of qdev_init() in realize method
PATCH 1/1 target-i386: Clean up misuse of qdev_init() in realize method
x86_cpu_apic_realize() calls qdev_init() to realize the APIC. qdev_init()'s error handling has unwanted side effects: it unparents the device, and it calls qerror_report_err().
qerror_report_err() is always inappropriate in realize methods, because it doesn't return the Error object. It either reports the error to stderr or the human monitor, or it stores it in the QMP monitor, where it makes the QMP command fail even though the realize method succeeded.
Fortunately, qdev_init() can't actually fail here, because realize can't fail for any of the three possible APIC device models.
Clean up by cutting out the qdev_init() middle-man: set property "realized" directly.
--- target-i386/cpu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
target-i386/cpu.c +2 -6
@@ -2752,12 +2752,8 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)if (cpu->apic_state ==NULL ) {return ; } - -if (qdev_init (cpu->apic_state)) { -error_setg (errp,"APIC device '%s' could not be initialized" , -object_get_typename (OBJECT (cpu->apic_state))); -return ; - } +object_property_set_bool (OBJECT (cpu->apic_state), true,"realized" , + errp); }#else static void x86_cpu_apic_realize (X86CPU *cpu,Error **errp)
Signature · 1 line
1.9.3
Quoted 30 lines · On Thu, 5 Feb 2015 10:29:15 +0100 Markus Armbruster <[email protected]> wrote:
x86_cpu_apic_realize()callsqdev_init()to realize the APIC. qdev_init()'s error handling has unwanted side effects: it unparents the device, and it callsqerror_report_err().
qerror_report_err()is always inappropriate in realize methods, because it doesn't return the Error object. It either reports the error to stderr or the human monitor, or it stores it in the QMP monitor, where it makes the QMP command fail even though the realize method succeeded.Fortunately,
qdev_init()can't actually fail here, because realize can't fail for any of the three possible APIC device models.Clean up by cutting out the
qdev_init()middle-man: set property "realized" directly.Signed-off-by Markus Armbruster <[email protected]>--- target-i386/cpu.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)target-i386/cpu.c +0
-1@@ -2752,12 +2752,8 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)if (cpu->apic_state ==NULL ) {return ; } -
target-i386/cpu.c static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) · line 2759
Quoted 10 lines
target-i386/cpu.c +2
-5-if (qdev_init (cpu->apic_state)) { -error_setg (errp,"APIC device '%s' could not be initialized" , -object_get_typename (OBJECT (cpu->apic_state))); -return ; - } +object_property_set_bool (OBJECT (cpu->apic_state), true,"realized" , + errp); }#else static void x86_cpu_apic_realize (X86CPU *cpu,Error **errp)
Andreas Färber
AppliedAm 05.02.2015 um 13:51 schrieb Igor Mammedov:
Quoted 16 lines
Quoted 13 lines · On Thu, 5 Feb 2015 10:29:15 +0100 Markus Armbruster <[email protected]> wrote:
x86_cpu_apic_realize()callsqdev_init()to realize the APIC. qdev_init()'s error handling has unwanted side effects: it unparents the device, and it callsqerror_report_err().
qerror_report_err()is always inappropriate in realize methods, because it doesn't return the Error object. It either reports the error to stderr or the human monitor, or it stores it in the QMP monitor, where it makes the QMP command fail even though the realize method succeeded.Fortunately,
qdev_init()can't actually fail here, because realize can't fail for any of the three possible APIC device models.
Quoted 6 lines
Quoted 4 lines
Clean up by cutting out the
qdev_init()middle-man: set property "realized" directly.Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Igor Mammedov <[email protected]>
Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu
Andreas
Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu, Graham Norton; HRB 21284 (AG Nürnberg)