apic: do not dereference pointer before it is checked for NULL
PATCH 1/1 apic: do not dereference pointer before it is checked for NULL
Right now you only get to apic_init_reset if you have an APIC (do_cpu_init is reached only if CPU_INTERRUPT_INIT is set and that only happens in hw/intc/apic.c). However, this is wrong because for example a port 92 or keyboard controller reset is really an INIT, and that can happen also with no APIC. So keep the check and fix the error that Coverity reported.
--- hw/intc/apic_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
hw/intc/apic_common.c +5 -3
@@ -177,13 +177,14 @@ bool apic_next_timer(APICCommonState *s, int64_t current_time)void apic_init_reset (DeviceState *dev) { -APICCommonState *s =APIC_COMMON (dev); -APICCommonClass *info =APIC_COMMON_GET_CLASS (s); +APICCommonState *s; +APICCommonClass *info;int i; -if (!s) { +if (!dev) {return ; } + s =APIC_COMMON (dev); s->tpr =0 ; s->spurious_vec =0xff ; s->log_dest =0 ;
@@ -208,6 +209,7 @@ void apic_init_reset(DeviceState *dev) } s->timer_expiry =-1 ; + info =APIC_COMMON_GET_CLASS (s);if (info->reset) { info->reset (s); }
Signature · 1 line
1.8.3.1
Quoted 9 lines · Paolo Bonzini
Right now you only get to
apic_init_resetif you have an APIC (do_cpu_initis reached only ifCPU_INTERRUPT_INITis set and that only happens inhw/intc/apic.c). However, this is wrong because for example a port 92 or keyboard controller reset is really an INIT, and that can happen also with no APIC. So keep the check and fix the error that Coverity reported.Reported-by Markus Armbruster <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>