From patchwork Thu Sep 4 14:32:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 385856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0FC0A140141 for ; Fri, 5 Sep 2014 00:33:35 +1000 (EST) Received: from localhost ([::1]:51428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPY6O-0003Wy-Jy for incoming@patchwork.ozlabs.org; Thu, 04 Sep 2014 10:33:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPY5z-0003DU-Gr for qemu-devel@nongnu.org; Thu, 04 Sep 2014 10:33:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPY5p-00059t-P3 for qemu-devel@nongnu.org; Thu, 04 Sep 2014 10:33:07 -0400 Received: from mail-pd0-x22b.google.com ([2607:f8b0:400e:c02::22b]:51222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPY5p-00059g-Gj; Thu, 04 Sep 2014 10:32:57 -0400 Received: by mail-pd0-f171.google.com with SMTP id y13so13683499pdi.16 for ; Thu, 04 Sep 2014 07:32:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=FmtxNKAlfPsfSL4USYS1gVwkqMZtpfITlYADgpERXSY=; b=eV+PgfWz6dQ0koRPcGx9oCtmBCTyzlJgioKn8isPdLbHQJfP061ttosWJ1obvsNVRv MOqglawH5C/QXiWWPEzpRUvYeDgxKjDvb7SSgZ1bPd1x882InJjO3CrVj7IptYEVbuT2 QYqsw61CJ8U496qHqmuFDSPSo2tqOIfeaunck/+0Oe02tRxt7U1cQydmkSn1Y1NDrlHd ghjqF3H27u7qJQHzDC1dQ4OvVBZqYy1kPVoJ2AXhu8MyXZ9Cz7/3a0H67qeOUbS+VAZJ gF0yXvdwp9DiRZhDWZ94BEhujX2cVvxGfhFpP9YuAnB9V6iwoWfxbcOownCjDaA1AKCr 5ZHw== X-Received: by 10.66.246.109 with SMTP id xv13mr9111491pac.144.1409841173569; Thu, 04 Sep 2014 07:32:53 -0700 (PDT) Received: from [192.168.1.103] ([223.72.65.17]) by mx.google.com with ESMTPSA id b9sm1831853pbu.91.2014.09.04.07.32.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 04 Sep 2014 07:32:52 -0700 (PDT) Message-ID: <5408780E.70607@gmail.com> Date: Thu, 04 Sep 2014 22:32:46 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: stefano.stabellini@eu.citrix.com X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::22b Cc: qemu-trivial@nongnu.org, xen-devel@lists.xenproject.org, qemu-devel Subject: [Qemu-devel] [PATCH v2] xen-hvm.c: Always return -1 when failure occurs in xen_hvm_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too. For simplify thinking, in xen_hvm_init(), also use '-1' instead of all '-errno', since all related upper callers always exit(1) for failure. It is not a normal function, it does not release related resources when return -1, so need give related comments for it. It passes common check: "./configure --enable-xen && make && make check" "echo $? == 0" Signed-off-by: Chen Gang Acked-by: Stefano Stabellini --- xen-hvm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/xen-hvm.c b/xen-hvm.c index 0d09940..2c6285d 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data) xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); } +/* return 0 means OK, or -1 means critical issue -- will exit(1) */ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, MemoryRegion **ram_memory) { @@ -991,15 +992,13 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, state->xce_handle = xen_xc_evtchn_open(NULL, 0); if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) { perror("xen: event channel open"); - g_free(state); - return -errno; + return -1; } state->xenstore = xs_daemon_open(); if (state->xenstore == NULL) { perror("xen: xenstore open"); - g_free(state); - return -errno; + return -1; } state->exit.notify = xen_exit_notifier; @@ -1069,7 +1068,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, /* Initialize backend core & drivers */ if (xen_be_init() != 0) { fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__); - exit(1); + return -1; } xen_be_register("console", &xen_console_ops); xen_be_register("vkbd", &xen_kbdmouse_ops);