aboutsummaryrefslogtreecommitdiff
path: root/render/allocator/drm_dumb.c
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-09-01 19:05:18 +0200
committerSimon Zeni <simon@bl4ckb0ne.ca>2021-09-01 15:17:05 -0400
commitd9d8fc1ab9b77d5696f8ed79de0568bf25d31500 (patch)
tree804c9ceb2c0b51f0c5adfed2f341c22c2ca2e83f /render/allocator/drm_dumb.c
parentc8d97e27916e1a1df6d103fa957a56829af6add3 (diff)
render/allocator: re-open GBM FD
Using the same DRM file description for the DRM backend and for the GBM allocator will result in GEM handle ref'counting issues [1]. Re-open the DRM FD to fix these issues. [1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
Diffstat (limited to 'render/allocator/drm_dumb.c')
-rw-r--r--render/allocator/drm_dumb.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/render/allocator/drm_dumb.c b/render/allocator/drm_dumb.c
index a47df624..ea982a03 100644
--- a/render/allocator/drm_dumb.c
+++ b/render/allocator/drm_dumb.c
@@ -199,41 +199,25 @@ static const struct wlr_allocator_interface allocator_impl = {
.destroy = allocator_destroy,
};
-struct wlr_allocator *wlr_drm_dumb_allocator_create(int fd) {
- if (!drmIsMaster(fd)) {
- wlr_log(WLR_ERROR, "Cannot use DRM dumb buffers with non-master DRM FD");
- return NULL;
- }
-
- /* Re-open the DRM node to avoid GEM handle ref'counting issues. See:
- * https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
- * TODO: don't assume we have the permission to just open the DRM node,
- * find another way to re-open it.
- */
- char *path = drmGetDeviceNameFromFd2(fd);
- int drm_fd = open(path, O_RDWR | O_CLOEXEC);
- if (drm_fd < 0) {
- wlr_log_errno(WLR_ERROR, "Failed to open DRM node %s", path);
- free(path);
+struct wlr_allocator *wlr_drm_dumb_allocator_create(int drm_fd) {
+ if (drmGetNodeTypeFromFd(drm_fd) != DRM_NODE_PRIMARY) {
+ wlr_log(WLR_ERROR, "Cannot use DRM dumb buffers with non-primary DRM FD");
return NULL;
}
uint64_t has_dumb = 0;
if (drmGetCap(drm_fd, DRM_CAP_DUMB_BUFFER, &has_dumb) < 0) {
wlr_log(WLR_ERROR, "Failed to get DRM capabilities");
- free(path);
return NULL;
}
if (has_dumb == 0) {
wlr_log(WLR_ERROR, "DRM dumb buffers not supported");
- free(path);
return NULL;
}
struct wlr_drm_dumb_allocator *alloc = calloc(1, sizeof(*alloc));
if (alloc == NULL) {
- free(path);
return NULL;
}
wlr_allocator_init(&alloc->base, &allocator_impl,
@@ -242,7 +226,6 @@ struct wlr_allocator *wlr_drm_dumb_allocator_create(int fd) {
alloc->drm_fd = drm_fd;
wl_list_init(&alloc->buffers);
- wlr_log(WLR_DEBUG, "Created DRM dumb allocator with node %s", path);
- free(path);
+ wlr_log(WLR_DEBUG, "Created DRM dumb allocator");
return &alloc->base;
}