From patchwork Fri Aug 2 15:35:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30CC41395 for ; Fri, 2 Aug 2019 15:59:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1ED7428613 for ; Fri, 2 Aug 2019 15:59:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1191C28872; Fri, 2 Aug 2019 15:59:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8671828613 for ; Fri, 2 Aug 2019 15:59:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwz-0006gm-Io; Fri, 02 Aug 2019 15:58:37 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwy-0006eI-EQ for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:36 +0000 X-Inumbo-ID: 61a2ee97-b53e-11e9-8980-bc764e045a96 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 61a2ee97-b53e-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 15:58:34 +0000 (UTC) Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 7EKsGSLKpzpsq5fIgsofCkQYL5rLoB/rMSkNSELfGw1BWZhynvVBgEufhrV1t8gyxnkNGBN6iA ck5lO2JDeogn+KxVNTo9QvSr2lY2PxA78pgOBNqM5FpEpRBlQytm/Zg6DNhRw3mgmzX2Dyhr3z k3gvHkeGZLVbEvgFLG+Aj9KPIMxQRWj+2Iz9S5OMJdzpt6RrtuONmTN9RQmp7anM9tTKK2KeeH 2rms9upg10sNu4wu6HH7iXkmVW7k+u6VQhcjvgUbFsvpdyFi1cZYeF1jq+UGbkDkm8UHAtob/U 5gQ= X-SBRS: 2.7 X-MesageID: 3826801 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3826801" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:35:56 +0100 Message-ID: <20190802153606.32061-26-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 25/35] libxl_pci: Coding style of do_pci_add X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP do_pci_add is going to be asynchronous, so we start by having a single path out of the function. All `return`s instead set rc and goto out. While here, some use of `rc' was used to store the return value of libxc calls, change them to store into `r'. Also, add the value of `r' in the error message of those calls. There were an `out' label that was use it seems to skip setting up the IRQ, the label has been renamed to `out_no_irq'. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_pci.c | 79 ++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 4b1aed1895..b9ca69f5f0 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -995,15 +995,19 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, uint32_t flag = XEN_DOMCTL_DEV_RDM_RELAXED; uint32_t domainid = domid; bool isstubdom = libxl_is_stubdom(ctx, domid, &domainid); + int r; - if (type == LIBXL_DOMAIN_TYPE_INVALID) - return ERROR_FAIL; + if (type == LIBXL_DOMAIN_TYPE_INVALID) { + rc = ERROR_FAIL; + goto out; + } if (type == LIBXL_DOMAIN_TYPE_HVM) { hvm = 1; if (libxl__wait_for_device_model_deprecated(gc, domid, "running", NULL, NULL, NULL) < 0) { - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } switch (libxl__device_model_version_running(gc, domid)) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: @@ -1013,10 +1017,10 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, rc = libxl__qmp_pci_add(gc, domid, pcidev); break; default: - return ERROR_INVAL; + rc = ERROR_INVAL; } if ( rc ) - return ERROR_FAIL; + goto out; } sysfs_path = GCSPRINTF(SYSFS_PCI_DEV"/"PCI_BDF"/resource", pcidev->domain, @@ -1027,7 +1031,8 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, if (f == NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) { if (fscanf(f, "0x%llx 0x%llx 0x%llx\n", &start, &end, &flags) != 3) @@ -1035,25 +1040,25 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, size = end - start + 1; if (start) { if (flags & PCI_BAR_IO) { - rc = xc_domain_ioport_permission(ctx->xch, domid, start, size, 1); - if (rc < 0) { + r = xc_domain_ioport_permission(ctx->xch, domid, start, size, 1); + if (r < 0) { LOGED(ERROR, domainid, - "Error: xc_domain_ioport_permission error 0x%llx/0x%llx", - start, - size); + "xc_domain_ioport_permission 0x%llx/0x%llx (error %d)", + start, size, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } else { - rc = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT, + r = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT, (size+(XC_PAGE_SIZE-1))>>XC_PAGE_SHIFT, 1); - if (rc < 0) { + if (r < 0) { LOGED(ERROR, domainid, - "Error: xc_domain_iomem_permission error 0x%llx/0x%llx", - start, - size); + "xc_domain_iomem_permission 0x%llx/0x%llx (error %d)", + start, size, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } } @@ -1064,20 +1069,24 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, f = fopen(sysfs_path, "r"); if (f == NULL) { LOGED(ERROR, domainid, "Couldn't open %s", sysfs_path); - goto out; + goto out_no_irq; } if ((fscanf(f, "%u", &irq) == 1) && irq) { - rc = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); - if (rc < 0) { - LOGED(ERROR, domainid, "Error: xc_physdev_map_pirq irq=%d", irq); + r = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); + if (r < 0) { + LOGED(ERROR, domainid, "xc_physdev_map_pirq irq=%d (error=%d)", + irq, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } - rc = xc_domain_irq_permission(ctx->xch, domid, irq, 1); - if (rc < 0) { - LOGED(ERROR, domainid, "Error: xc_domain_irq_permission irq=%d", irq); + r = xc_domain_irq_permission(ctx->xch, domid, irq, 1); + if (r < 0) { + LOGED(ERROR, domainid, + "xc_domain_irq_permission irq=%d (error=%d)", irq, r); fclose(f); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } fclose(f); @@ -1087,22 +1096,25 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive", pcidev) < 0 ) { LOGD(ERROR, domainid, "Setting permissive for device"); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } -out: +out_no_irq: if (!isstubdom) { if (pcidev->rdm_policy == LIBXL_RDM_RESERVE_POLICY_STRICT) { flag &= ~XEN_DOMCTL_DEV_RDM_RELAXED; } else if (pcidev->rdm_policy != LIBXL_RDM_RESERVE_POLICY_RELAXED) { LOGED(ERROR, domainid, "unknown rdm check flag."); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } - rc = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev), flag); - if (rc < 0 && (hvm || errno != ENOSYS)) { + r = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev), flag); + if (r < 0 && (hvm || errno != ENOSYS)) { LOGED(ERROR, domainid, "xc_assign_device failed"); - return ERROR_FAIL; + rc = ERROR_FAIL; + goto out; } } @@ -1110,6 +1122,7 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, rc = libxl__device_pci_add_xenstore(gc, domid, pcidev, starting); else rc = 0; +out: return rc; }