From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoGKo-00075v-7L for qemu-devel@nongnu.org; Mon, 19 Oct 2015 15:43:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoGKj-0003zW-Bc for qemu-devel@nongnu.org; Mon, 19 Oct 2015 15:43:04 -0400 Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235]:34848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoGKj-0003zR-6U for qemu-devel@nongnu.org; Mon, 19 Oct 2015 15:43:01 -0400 Received: by qkbl190 with SMTP id l190so28198747qkb.2 for ; Mon, 19 Oct 2015 12:43:00 -0700 (PDT) Sender: Paolo Bonzini References: <1445279965-19667-1-git-send-email-ehabkost@redhat.com> From: Paolo Bonzini Message-ID: <562547C2.2070803@redhat.com> Date: Mon, 19 Oct 2015 21:42:58 +0200 MIME-Version: 1.0 In-Reply-To: <1445279965-19667-1-git-send-email-ehabkost@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] xen-platform: Replace assert() with appropriate error reporting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost , Stefano Stabellini Cc: qemu-devel@nongnu.org On 19/10/2015 20:39, Eduardo Habkost wrote: > Commit dbb7405d8caad0814ceddd568cb49f163a847561 made it possible to > trigger an assert using "-device xen-platform". Replace it with > appropriate error reporting. > > Before: > > $ qemu-system-x86_64 -device xen-platform > qemu-system-x86_64: hw/i386/xen/xen_platform.c:391: xen_platform_initfn: Assertion `xen_enabled()' failed. > Aborted (core dumped) > $ > > After: > > $ qemu-system-x86_64 -device xen-platform > qemu-system-x86_64: -device xen-platform: xen-platform device requires the Xen accelerator > qemu-system-x86_64: -device xen-platform: Device initialization failed > $ > > Signed-off-by: Eduardo Habkost > --- > hw/i386/xen/xen_platform.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c > index 8682c42..5667f29 100644 > --- a/hw/i386/xen/xen_platform.c > +++ b/hw/i386/xen/xen_platform.c > @@ -33,6 +33,7 @@ > #include "trace.h" > #include "exec/address-spaces.h" > #include "sysemu/block-backend.h" > +#include "qemu/error-report.h" > > #include > > @@ -388,7 +389,10 @@ static int xen_platform_initfn(PCIDevice *dev) > uint8_t *pci_conf; > > /* Device will crash on reset if xen is not initialized */ > - assert(xen_enabled()); > + if (!xen_enabled()) { > + error_report("xen-platform device requires the Xen accelerator"); You can use PCIDeviceClass's realize (see Stefano's http://thread.gmane.org/gmane.comp.emulators.qemu/369998) to achieve better error propagation. Paolo > + return -1; > + } > > pci_conf = dev->config; > >