Received: from eggs.gnu.org ([2001:4830:134:3::10]:51799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFfuo-0007hi-Jc for qemu-devel@nongnu.org; Mon, 26 Jan 2015 04:25:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFfun-0005zE-RM for qemu-devel@nongnu.org; Mon, 26 Jan 2015 04:25:02 -0500 Received: from mail-wi0-x234.google.com ([2a00:1450:400c:c05::234]:56248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFfun-0005vJ-Jg for qemu-devel@nongnu.org; Mon, 26 Jan 2015 04:25:01 -0500 Received: by mail-wi0-f180.google.com with SMTP id h11so8363099wiw.1 for ; Mon, 26 Jan 2015 01:25:01 -0800 (PST) Received: from playground.station (net-2-35-193-154.cust.vodafonedsl.it. [2.35.193.154]) by mx.google.com with ESMTPSA id 7sm13482382wjq.29.2015.01.26.01.24.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Jan 2015 01:25:00 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 26 Jan 2015 10:24:25 +0100 Message-Id: <1422264270-19278-15-git-send-email-pbonzini@redhat.com> In-Reply-To: <1422264270-19278-1-git-send-email-pbonzini@redhat.com> References: <1422264270-19278-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 14/19] apic: do not dereference pointer before it is checked for NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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. Reported-by: Markus Armbruster Reviewed-by: Markus Armbruster Signed-off-by: Paolo Bonzini --- hw/intc/apic_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index d9bb188..0858b45 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -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); } -- 1.8.3.1