From nobody Tue Feb 10 02:43:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1605031272; cv=none; d=zohomail.com; s=zohoarc; b=T/BI5sR0RdWEefQIlatpJDUorlHY/zNFlWjq8czXaPU2mdBN76llLiyrZUFxXvoTmtGenST8BmEIr9dRKAEzsstsXHLKVToDtuCUZc0R96YiYrsg9X3Nr/J8XWZTI1W410MlnV/dutCP573r4xCu9XLe9nrbqIl5PA/ghheBtQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605031272; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PtqM9YxtE81a3JL1qMtcUPTsYA1jEFS78iQFWeC5eZA=; b=i9quvdNndJ0B6etXO8c3gS1P1xhrhCfao6YNdYKDLWHNpJF4QreZyIziZIAQ4hfkz6PruAzomG5apEh6y26dH5jSvNvXBSfOo8uIHgN3KpfbJACkkwQ/bMsgb31yE5WAsYNa9krXBxEVgHXNQSgBd2sSj9eVqWWMYqFpCGr2Y08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1605031272074165.2719517456644; Tue, 10 Nov 2020 10:01:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.23645.50511 (Exim 4.92) (envelope-from ) id 1kcXwk-00059f-GH; Tue, 10 Nov 2020 18:00:46 +0000 Received: by outflank-mailman (output) from mailman id 23645.50511; Tue, 10 Nov 2020 18:00:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcXwk-00059Y-B3; Tue, 10 Nov 2020 18:00:46 +0000 Received: by outflank-mailman (input) for mailman id 23645; Tue, 10 Nov 2020 18:00:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcXwi-00059I-Ig for xen-devel@lists.xenproject.org; Tue, 10 Nov 2020 18:00:44 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a66384d9-06e1-4c39-98cb-d06930aa6aec; Tue, 10 Nov 2020 18:00:43 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcXwh-0006qT-02; Tue, 10 Nov 2020 18:00:43 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcXoH-0007RC-Jy; Tue, 10 Nov 2020 17:52:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcXwi-00059I-Ig for xen-devel@lists.xenproject.org; Tue, 10 Nov 2020 18:00:44 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id a66384d9-06e1-4c39-98cb-d06930aa6aec; Tue, 10 Nov 2020 18:00:43 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcXwh-0006qT-02; Tue, 10 Nov 2020 18:00:43 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcXoH-0007RC-Jy; Tue, 10 Nov 2020 17:52:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a66384d9-06e1-4c39-98cb-d06930aa6aec DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=PtqM9YxtE81a3JL1qMtcUPTsYA1jEFS78iQFWeC5eZA=; b=cLGh52QeUqzLm/p2O6ihQl3rSd JTtdIwqy8pIvY1KJC+JiDMemyI6uGenYnO6+QoURLOWa7WIN7oo98hVXMeCTc66mzRqZ4brOq6gTz 5xWWROFpfMQUKV6El+mpBJw2ILeqq2t0waul1FExyIYkBwlQ+4JlxSE2yRHhawRx8E6U=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH v2 12/24] libxl: use COMPARE_PCI() macro is_pci_in_array()... Date: Tue, 10 Nov 2020 17:51:35 +0000 Message-Id: <20201110175147.7067-13-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201110175147.7067-1-paul@xen.org> References: <20201110175147.7067-1-paul@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) Content-Type: text/plain; charset="utf-8" From: Paul Durrant ... rather than an open-coded equivalent. This patch tidies up the is_pci_in_array() function, making it take a single 'libxl_device_pci' argument rather than separate domain, bus, device and function arguments. The already-available COMPARE_PCI() macro can then be used and it is also modified to return 'bool' rather than 'int'. The patch also modifies libxl_pci_assignable() to use is_pci_in_array() rat= her than a separate open-coded equivalent, and also modifies it to return a 'bool' rather than an 'int'. NOTE: The COMPARE_PCI() macro is also fixed to include the 'domain' in its comparison, which should always have been the case. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu --- tools/libs/light/libxl_internal.h | 7 +++--- tools/libs/light/libxl_pci.c | 38 +++++++++++-------------------- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 3e70ff639b3c..80d798862229 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4744,9 +4744,10 @@ void libxl__xcinfo2xlinfo(libxl_ctx *ctx, * devices have same identifier. */ #define COMPARE_DEVID(a, b) ((a)->devid =3D=3D (b)->devid) #define COMPARE_DISK(a, b) (!strcmp((a)->vdev, (b)->vdev)) -#define COMPARE_PCI(a, b) ((a)->func =3D=3D (b)->func && \ - (a)->bus =3D=3D (b)->bus && \ - (a)->dev =3D=3D (b)->dev) +#define COMPARE_PCI(a, b) ((a)->domain =3D=3D (b)->domain && \ + (a)->bus =3D=3D (b)->bus && \ + (a)->dev =3D=3D (b)->dev && \ + (a)->func =3D=3D (b)->func) #define COMPARE_USB(a, b) ((a)->ctrl =3D=3D (b)->ctrl && \ (a)->port =3D=3D (b)->port) #define COMPARE_USBCTRL(a, b) ((a)->devid =3D=3D (b)->devid) diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index b87e121c4d5c..278ebd9f561b 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -317,24 +317,17 @@ retry_transaction2: return 0; } =20 -static int is_pci_in_array(libxl_device_pci *assigned, int num_assigned, - int dom, int bus, int dev, int func) +static bool is_pci_in_array(libxl_device_pci *pcis, int num, + libxl_device_pci *pci) { int i; =20 - for(i =3D 0; i < num_assigned; i++) { - if ( assigned[i].domain !=3D dom ) - continue; - if ( assigned[i].bus !=3D bus ) - continue; - if ( assigned[i].dev !=3D dev ) - continue; - if ( assigned[i].func !=3D func ) - continue; - return 1; + for (i =3D 0; i < num; i++) { + if (COMPARE_PCI(pci, &pcis[i])) + break; } =20 - return 0; + return i < num; } =20 /* Write the standard BDF into the sysfs path given by sysfs_path. */ @@ -1468,21 +1461,17 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t d= omid, return AO_INPROGRESS; } =20 -static int libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci) +static bool libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci) { libxl_device_pci *pcis; - int num, i; + int num; + bool assignable; =20 pcis =3D libxl_device_pci_assignable_list(ctx, &num); - for (i =3D 0; i < num; i++) { - if (pcis[i].domain =3D=3D pci->domain && - pcis[i].bus =3D=3D pci->bus && - pcis[i].dev =3D=3D pci->dev && - pcis[i].func =3D=3D pci->func) - break; - } + assignable =3D is_pci_in_array(pcis, num, pci); libxl_device_pci_assignable_list_free(pcis, num); - return i !=3D num; + + return assignable; } =20 static void device_pci_add_stubdom_wait(libxl__egc *egc, @@ -1831,8 +1820,7 @@ static void do_pci_remove(libxl__egc *egc, pci_remove= _state *prs) goto out_fail; } =20 - attached =3D is_pci_in_array(pcis, num, pci->domain, - pci->bus, pci->dev, pci->func); + attached =3D is_pci_in_array(pcis, num, pci); libxl_device_pci_list_free(pcis, num); =20 rc =3D ERROR_INVAL; --=20 2.20.1