From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BF62C63777 for ; Tue, 24 Nov 2020 08:31:18 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB8B720708 for ; Tue, 24 Nov 2020 08:31:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="Zx1VNNU9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB8B720708 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.35514.67181 (Exim 4.92) (envelope-from ) id 1khTiu-0003fy-H5; Tue, 24 Nov 2020 08:30:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 35514.67181; Tue, 24 Nov 2020 08:30:52 +0000 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" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khTit-0003ez-Ne; Tue, 24 Nov 2020 08:30:51 +0000 Received: by outflank-mailman (input) for mailman id 35514; Tue, 24 Nov 2020 08:30:45 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khTin-0003Q8-CF for xen-devel@lists.xenproject.org; Tue, 24 Nov 2020 08:30:45 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khTim-0006az-Fk; Tue, 24 Nov 2020 08:30: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 1khTH3-0001hp-Ex; Tue, 24 Nov 2020 08:02:05 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khTin-0003Q8-CF for xen-devel@lists.xenproject.org; Tue, 24 Nov 2020 08:30:45 +0000 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=Zx1VNNU929L1xSDx9gjZx0iUu FYHvlt/uy6PH7f6lx4mUQpdi1/w+OavQEJC9MP/3CJRDz6ecWFy3HQJiZPTEIdv9ULCNspnQ+55YD miZQapD87cICX1XoOmaOiQ9JNhXY+d2qC4M/CRybvl+LDHUw91jFJ3oE7fQjbGHLY4cYk=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khTim-0006az-Fk; Tue, 24 Nov 2020 08:30: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 1khTH3-0001hp-Ex; Tue, 24 Nov 2020 08:02:05 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu Subject: [PATCH v4 13/23] libxl: use COMPARE_PCI() macro is_pci_in_array()... Date: Tue, 24 Nov 2020 08:01:49 +0000 Message-Id: <20201124080159.11912-14-paul@xen.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20201124080159.11912-1-paul@xen.org> References: <20201124080159.11912-1-paul@xen.org> 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() rather 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_internal.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 == (b)->devid) #define COMPARE_DISK(a, b) (!strcmp((a)->vdev, (b)->vdev)) -#define COMPARE_PCI(a, b) ((a)->func == (b)->func && \ - (a)->bus == (b)->bus && \ - (a)->dev == (b)->dev) +#define COMPARE_PCI(a, b) ((a)->domain == (b)->domain && \ + (a)->bus == (b)->bus && \ + (a)->dev == (b)->dev && \ + (a)->func == (b)->func) #define COMPARE_USB(a, b) ((a)->ctrl == (b)->ctrl && \ (a)->port == (b)->port) #define COMPARE_USBCTRL(a, b) ((a)->devid == (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; } -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; - for(i = 0; i < num_assigned; i++) { - if ( assigned[i].domain != dom ) - continue; - if ( assigned[i].bus != bus ) - continue; - if ( assigned[i].dev != dev ) - continue; - if ( assigned[i].func != func ) - continue; - return 1; + for (i = 0; i < num; i++) { + if (COMPARE_PCI(pci, &pcis[i])) + break; } - return 0; + return i < num; } /* 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 domid, return AO_INPROGRESS; } -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; pcis = libxl_device_pci_assignable_list(ctx, &num); - for (i = 0; i < num; i++) { - if (pcis[i].domain == pci->domain && - pcis[i].bus == pci->bus && - pcis[i].dev == pci->dev && - pcis[i].func == pci->func) - break; - } + assignable = is_pci_in_array(pcis, num, pci); libxl_device_pci_assignable_list_free(pcis, num); - return i != num; + + return assignable; } 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; } - attached = is_pci_in_array(pcis, num, pci->domain, - pci->bus, pci->dev, pci->func); + attached = is_pci_in_array(pcis, num, pci); libxl_device_pci_list_free(pcis, num); rc = ERROR_INVAL; -- 2.11.0