nouveau/ws: dup the fd
authorKarol Herbst <kherbst@redhat.com>
Fri, 20 May 2022 13:22:58 +0000 (15:22 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:52 +0000 (21:31 +0000)
We do the same in gallium

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/vulkan/nvk_physical_device.c
src/nouveau/winsys/nouveau_device.c

index 1d2a0ee..0dc4c3a 100644 (file)
@@ -199,6 +199,7 @@ nvk_physical_device_try_create(struct nvk_instance *instance,
 
    *device_out = device;
 
+   close(fd);
    return VK_SUCCESS;
 
 fail_alloc:
index 098f887..a3060e9 100644 (file)
@@ -6,6 +6,7 @@
 #include <nvif/cl0080.h>
 #include <nvif/class.h>
 
+#include "util/os_file.h"
 #include "util/os_misc.h"
 
 struct nouveau_ws_device *
@@ -15,8 +16,9 @@ nouveau_ws_device_new(int fd)
    uint64_t device_id = 0;
    struct nouveau_drm *drm;
    struct nouveau_device *dev;
+   int dup_fd = os_dupfd_cloexec(fd);
 
-   if (nouveau_drm_new(fd, &drm)) {
+   if (nouveau_drm_new(dup_fd, &drm)) {
       return NULL;
    }
 
@@ -41,7 +43,7 @@ nouveau_ws_device_new(int fd)
    device->base.is_integrated = dev->vram_size == 0;
    device->drm = drm;
    device->dev = dev;
-   device->fd = fd;
+   device->fd = dup_fd;
 
    return &device->base;
 
@@ -49,6 +51,7 @@ out_dev:
    nouveau_device_del(&dev);
 out_drm:
    nouveau_drm_del(&drm);
+   close(dup_fd);
    return NULL;
 }