From nobody Tue Feb 10 11:12:52 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=1606154476; cv=none; d=zohomail.com; s=zohoarc; b=lSpdtS0t0b/LeqppnAY2u/gNPM7fp9JA1U/mihQYP1DS2q+8q+6Jn6U0kX1FMUydDKaWYtqdOAJKQfs2INM0xtu6l2rfWoOFFQBxi2idZ9ib7glIjf5R/dzwYJ8zJ74jTGh4Y43IOPvR5GIDWPhhkd76T44QtUk3dd/zgEVh/x8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606154476; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=QgHDaVAQBuzu/wVXFL4ANbr3u6TzV6QgoeQN2pH/gEg=; b=cLzZprcnlsyQUU6XOTjnJm880U3n/wdy4HcUp2fwAQq3kUa3hF3cCYAN86UbOGX/1fVRulaJaghFz1r9r5TeXbzBnL3HEnJEHAPL31Ru9oqKvCJJGbiNuPv1/Gy6J4X5sV+2EB/76SPDiGn/od4tlVPGRZ7Uqr5S2oYLYhf+Z6k= 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 1606154476543532.6695992845017; Mon, 23 Nov 2020 10:01:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.35006.66360 (Exim 4.92) (envelope-from ) id 1khG8u-0000qC-1P; Mon, 23 Nov 2020 18:00:48 +0000 Received: by outflank-mailman (output) from mailman id 35006.66360; Mon, 23 Nov 2020 18:00:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khG8t-0000pp-RS; Mon, 23 Nov 2020 18:00:47 +0000 Received: by outflank-mailman (input) for mailman id 35006; Mon, 23 Nov 2020 18:00:45 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khG8r-0000mN-7q for xen-devel@lists.xenproject.org; Mon, 23 Nov 2020 18:00:45 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khG8q-000713-JQ; Mon, 23 Nov 2020 18:00:44 +0000 Received: from ec2-54-145-241-208.compute-1.amazonaws.com ([54.145.241.208] helo=ip-10-0-29-170.ec2.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1khFtl-0000at-DZ; Mon, 23 Nov 2020 17:45:09 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khG8r-0000mN-7q for xen-devel@lists.xenproject.org; Mon, 23 Nov 2020 18:00:45 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khG8q-000713-JQ; Mon, 23 Nov 2020 18:00:44 +0000 Received: from ec2-54-145-241-208.compute-1.amazonaws.com ([54.145.241.208] helo=ip-10-0-29-170.ec2.internal) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1khFtl-0000at-DZ; Mon, 23 Nov 2020 17:45:09 +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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=QgHDaVAQBuzu/wVXFL4ANbr3u6TzV6QgoeQN2pH/gEg=; b=5h8Sdvp0Wa16jCGuk2sR6KlGM dQHdHViUYRgn+5SPQwmPSWuNZwOLs1ueC2iW6zwHYaNDwpivdIIQArY3iaKyN9tC3qxy1pRZpjnqs EcIRVAQiIVJ5HZvsfAL+uaaGDOmaiD58Y3jpppzOYy+7N8qV2OmG/Hc9nLGedXfyLWsvU=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH v3 13/23] libxl: use COMPARE_PCI() macro is_pci_in_array()... Date: Mon, 23 Nov 2020 17:44:53 +0000 Message-Id: <20201123174503.6800-14-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201123174503.6800-1-paul@xen.org> References: <20201123174503.6800-1-paul@xen.org> X-ZohoMail-DKIM: pass (identity @xen.org) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 ecee61b541..02f8a3179c 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4746,9 +4746,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 5a3352c2ec..e0b616fe18 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -336,24 +336,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. */ @@ -1487,21 +1480,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, @@ -1834,8 +1823,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.11.0