]> xenbits.xensource.com Git - people/pauldu/xen.git/commitdiff
libxl: add libxl_device_pci_assignable_list_free()...
authorPaul Durrant <pdurrant@amazon.com>
Wed, 21 Oct 2020 16:41:02 +0000 (16:41 +0000)
committerPaul Durrant <pdurrant@amazon.com>
Tue, 10 Nov 2020 16:52:00 +0000 (16:52 +0000)
... 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 implementation
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 <pdurrant@amazon.com>
---
Cc: Ian Jackson <iwj@xenproject.org>
Cc: Wei Liu <wl@xen.org>
Cc: Christian Lindig <christian.lindig@citrix.com>
Cc: David Scott <dave@recoil.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>
tools/include/libxl.h
tools/libs/light/libxl_pci.c
tools/ocaml/libs/xl/xenlight_stubs.c
tools/xl/xl_pci.c

index ee52d3cf7e7e6fc585280b4e25fef2b8e81b551b..8225809d94a88ce80ee3dc77fbdb286205244100 100644 (file)
  */
 #define LIBXL_HAVE_DEVICE_PCI_LIST_FREE 1
 
+/*
+ * 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
  *
@@ -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 *pci, int rebind);
 libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num);
+void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num);
 
 /* CPUID handling */
 int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str);
index a69cba793583ac028eafb4cea6fc6dbbe6c0a3a1..b87e121c4d5c969245141b567614fe2e5686420f 100644 (file)
@@ -438,7 +438,7 @@ libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num)
         pcis = new;
         new = pcis + *num;
 
-        memset(new, 0, sizeof(*new));
+        libxl_device_pci_init(new);
         pci_struct_fill(new, dom, bus, dev, func, 0);
 
         if (pci_info_xs_read(gc, new, "domid")) /* already assigned */
@@ -453,6 +453,16 @@ out:
     return pcis;
 }
 
+void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num)
+{
+    int i;
+
+    for (i = 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-NULL,
  * store the path to the original driver in it. */
 static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pci,
@@ -1471,7 +1481,7 @@ static int libxl_pci_assignable(libxl_ctx *ctx, libxl_device_pci *pci)
             pcis[i].func == pci->func)
             break;
     }
-    free(pcis);
+    libxl_device_pci_assignable_list_free(pcis, num);
     return i != num;
 }
 
index 1181971da4e7d59ec7bca53fd6fb4dab622648f5..352a00134d7084ed633f6d149558e97df198b1c5 100644 (file)
@@ -894,9 +894,8 @@ value stub_xl_device_pci_assignable_list(value ctx)
                Field(list, 1) = temp;
                temp = 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);
 
        CAMLreturn(list);
 }
index 7c0f102ac7b7b9566db184a4fdc65a1fe174fdd9..f71498cbb570dce48693ed32cedc4ab63f977761 100644 (file)
@@ -164,9 +164,8 @@ static void pciassignable_list(void)
     for (i = 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);
 }
 
 int main_pciassignable_list(int argc, char **argv)