From nobody Tue Feb 10 01:34:39 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=1606154539; cv=none; d=zohomail.com; s=zohoarc; b=JVhD9ozmh5XOj5lsbfdaOoeoVoAkR9WDpdruWc/aAOZZBr/ktrEvh5CZ4jWO5wn6Z2LZPF/VAK2MEM+KE06vSr5iZH3WWzQcy8IGrNKqhM2aaUtnYcdQT7vpvfJRwgKNPVbNo8DuYJyDggHAEolzhQ8I+jFpkbgEzvSw6M6igmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606154539; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Ni3v8rNOQnYX+FJEz4ZSjie9Y3E4/QZ6KFSYwE8qkX0=; b=oC+rEq+EHlLfwaC/gyL4/5/epPvPcOgNYbargk4bscsDGPm3rNj1ZoWwtVOtslWzQIct4UspAzi96Ah0ZcV9w3DCEkPwv0YOBRNlB8Sjy2Fqc+0muzVFbGm1CYi7oHmpgIh8SD9vhA0I2ldvYZ8VWAmI3GCNR+IM3wVHSpTApFE= 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 1606154538936110.3094009456214; Mon, 23 Nov 2020 10:02:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.35014.66462 (Exim 4.92) (envelope-from ) id 1khG91-0001B3-Qt; Mon, 23 Nov 2020 18:00:55 +0000 Received: by outflank-mailman (output) from mailman id 35014.66462; Mon, 23 Nov 2020 18:00:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khG91-0001A4-1O; Mon, 23 Nov 2020 18:00:55 +0000 Received: by outflank-mailman (input) for mailman id 35014; 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-0000n1-SV 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-000719-N8; 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-7A; 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-0000n1-SV 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-000719-N8; 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-7A; 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=Ni3v8rNOQnYX+FJEz4ZSjie9Y3E4/QZ6KFSYwE8qkX0=; b=HUbcLcri8euWWCAQek9iap8pf gb9/NsWal+w/ACsywDUUFgGvNEd77afn1hL3FXYDMABhIAAUL7f6O4K+zx69kluOvWtVulr7DQ4ig PtfOnRHlfWmW1kTtMMWq2RuyOTcPsk2pPIXWBbAzjDOh2Jw5SFv4HLe8LgbxIpS4VFM9g=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Ian Jackson , Wei Liu , Christian Lindig , David Scott , Anthony PERARD Subject: [PATCH v3 12/23] libxl: add libxl_device_pci_assignable_list_free()... Date: Mon, 23 Nov 2020 17:44:52 +0000 Message-Id: <20201123174503.6800-13-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 ... to be used by callers of libxl_device_pci_assignable_list(). Currently there is no API for callers of libxl_device_pci_assignable_list() to free the list. The xl function pciassignable_list() calls libxl_device_pci_dispose() on each element of the returned list, but libxl_pci_assignable() in libxl_pci.c does not. Neither does the implementa= tion of libxl_device_pci_assignable_list() call libxl_device_pci_init(). This patch adds the new API function, makes sure it is used everywhere and also modifies libxl_device_pci_assignable_list() to initialize list entries rather than just zeroing them. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu Cc: Christian Lindig Cc: David Scott Cc: Anthony PERARD --- tools/include/libxl.h | 7 +++++++ tools/libs/light/libxl_pci.c | 14 ++++++++++++-- tools/ocaml/libs/xl/xenlight_stubs.c | 3 +-- tools/xl/xl_pci.c | 3 +-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index ee52d3cf7e..8225809d94 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -458,6 +458,12 @@ #define LIBXL_HAVE_DEVICE_PCI_LIST_FREE 1 =20 /* + * LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE indicates that the + * libxl_device_pci_assignable_list_free() function is defined. + */ +#define LIBXL_HAVE_DEVICE_PCI_ASSIGNABLE_LIST_FREE 1 + +/* * libxl ABI compatibility * * The only guarantee which libxl makes regarding ABI compatibility @@ -2369,6 +2375,7 @@ int libxl_device_events_handler(libxl_ctx *ctx, int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci,= int rebind); int libxl_device_pci_assignable_remove(libxl_ctx *ctx, libxl_device_pci *p= ci, int rebind); libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *nu= m); +void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num= ); =20 /* CPUID handling */ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* s= tr); diff --git a/tools/libs/light/libxl_pci.c b/tools/libs/light/libxl_pci.c index 0f41939d1f..5a3352c2ec 100644 --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -457,7 +457,7 @@ libxl_device_pci *libxl_device_pci_assignable_list(libx= l_ctx *ctx, int *num) pcis =3D new; new =3D pcis + *num; =20 - memset(new, 0, sizeof(*new)); + libxl_device_pci_init(new); pci_struct_fill(new, dom, bus, dev, func, 0); =20 if (pci_info_xs_read(gc, new, "domid")) /* already assigned */ @@ -472,6 +472,16 @@ out: return pcis; } =20 +void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num) +{ + int i; + + for (i =3D 0; i < num; i++) + libxl_device_pci_dispose(&list[i]); + + free(list); +} + /* Unbind device from its current driver, if any. If driver_path is non-N= ULL, * store the path to the original driver in it. */ static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pci, @@ -1490,7 +1500,7 @@ static int libxl_pci_assignable(libxl_ctx *ctx, libxl= _device_pci *pci) pcis[i].func =3D=3D pci->func) break; } - free(pcis); + libxl_device_pci_assignable_list_free(pcis, num); return i !=3D num; } =20 diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xen= light_stubs.c index 1181971da4..352a00134d 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -894,9 +894,8 @@ value stub_xl_device_pci_assignable_list(value ctx) Field(list, 1) =3D temp; temp =3D list; Store_field(list, 0, Val_device_pci(&c_list[i])); - libxl_device_pci_dispose(&c_list[i]); } - free(c_list); + libxl_device_pci_assignable_list_free(c_list, nb); =20 CAMLreturn(list); } diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c index 7c0f102ac7..f71498cbb5 100644 --- a/tools/xl/xl_pci.c +++ b/tools/xl/xl_pci.c @@ -164,9 +164,8 @@ static void pciassignable_list(void) for (i =3D 0; i < num; i++) { printf("%04x:%02x:%02x.%01x\n", pcis[i].domain, pcis[i].bus, pcis[i].dev, pcis[i].func); - libxl_device_pci_dispose(&pcis[i]); } - free(pcis); + libxl_device_pci_assignable_list_free(pcis, num); } =20 int main_pciassignable_list(int argc, char **argv) --=20 2.11.0