diff --git a/include/render/gbm_allocator.h b/include/render/gbm_allocator.h index b4f40039..df6b5e39 100644 --- a/include/render/gbm_allocator.h +++ b/include/render/gbm_allocator.h @@ -26,7 +26,7 @@ struct wlr_gbm_allocator { /** * Creates a new GBM allocator from a DRM FD. * - * Takes ownership over the FD. + * Does not take ownership over the FD. */ struct wlr_allocator *wlr_gbm_allocator_create(int drm_fd); diff --git a/render/allocator.c b/render/allocator.c index 46d7b2de..6dd8592b 100644 --- a/render/allocator.c +++ b/render/allocator.c @@ -1,6 +1,5 @@ #define _POSIX_C_SOURCE 200809L #include -#include #include #include #include @@ -29,10 +28,7 @@ struct wlr_allocator *allocator_autocreate_with_drm_fd( if ((backend_caps & gbm_caps) && (renderer_caps & gbm_caps) && drm_fd != -1) { wlr_log(WLR_DEBUG, "Trying to create gbm allocator"); - int fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 0); - if (fd < 0) { - wlr_log(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed"); - } else if ((alloc = wlr_gbm_allocator_create(fd)) != NULL) { + if ((alloc = wlr_gbm_allocator_create(drm_fd)) != NULL) { return alloc; } wlr_log(WLR_DEBUG, "Failed to create gbm allocator"); diff --git a/render/gbm_allocator.c b/render/gbm_allocator.c index 33fbf954..4006b66d 100644 --- a/render/gbm_allocator.c +++ b/render/gbm_allocator.c @@ -159,7 +159,13 @@ static struct wlr_gbm_allocator *get_gbm_alloc_from_alloc( return (struct wlr_gbm_allocator *)alloc; } -struct wlr_allocator *wlr_gbm_allocator_create(int fd) { +struct wlr_allocator *wlr_gbm_allocator_create(int drm_fd) { + int fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 0); + if (fd < 0) { + wlr_log(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed"); + return NULL; + } + uint64_t cap; if (drmGetCap(fd, DRM_CAP_PRIME, &cap) || !(cap & DRM_PRIME_CAP_EXPORT)) {