diff options
author | Emil Velikov <[email protected]> | 2018-08-29 18:13:14 +0100 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2018-10-03 13:38:05 +0100 |
commit | 6ccc435e7ad92bb0ba77d3fdb48c7127ba71239e (patch) | |
tree | 6ca059b425d4b452bcfe76a634d4d852bed0f6d8 /src/gallium/state_trackers | |
parent | 7b8d1b313cd01bb916898d8bb92a566534e37677 (diff) |
pipe-loader: move dup(fd) within pipe_loader_drm_probe_fd
Currently pipe_loader_drm_probe_fd takes ownership of the fd given.
To match that, pipe_loader_release closes it.
Yet we have many instances which do not want the change of ownership,
and thus duplicate the fd before passing it to the pipe-loader.
Move the dup() within pipe-loader, explicitly document that and document
all the cases through the codebase.
A trivial git grep -2 pipe_loader_release makes things as obvious as it
gets ;-)
Cc: Leo Liu <[email protected]>
Cc: Thomas Hellstrom <[email protected]>
Cc: Axel Davy <[email protected]>
Cc: Patrick Rudolph <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
Reviewed-by: Thomas Hellstrom <[email protected]>
Reviewed-by: Axel Davy <[email protected]> (for nine)
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r-- | src/gallium/state_trackers/dri/dri2.c | 19 | ||||
-rw-r--r-- | src/gallium/state_trackers/dri/dri_screen.c | 1 | ||||
-rw-r--r-- | src/gallium/state_trackers/xa/xa_tracker.c | 12 |
3 files changed, 6 insertions, 26 deletions
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index 20540e39881..b17c5e16ede 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -29,7 +29,6 @@ */ #include <xf86drm.h> -#include <fcntl.h> #include "GL/mesa_glinterop.h" #include "util/u_memory.h" #include "util/u_inlines.h" @@ -2103,7 +2102,6 @@ dri2_init_screen(__DRIscreen * sPriv) struct pipe_screen *pscreen = NULL; const struct drm_conf_ret *throttle_ret; const struct drm_conf_ret *dmabuf_ret; - int fd; screen = CALLOC_STRUCT(dri_screen); if (!screen) @@ -2115,11 +2113,7 @@ dri2_init_screen(__DRIscreen * sPriv) sPriv->driverPrivate = (void *)screen; - if (screen->fd < 0 || (fd = fcntl(screen->fd, F_DUPFD_CLOEXEC, 3)) < 0) - goto free_screen; - - - if (pipe_loader_drm_probe_fd(&screen->dev, fd)) { + if (pipe_loader_drm_probe_fd(&screen->dev, screen->fd)) { dri_init_options(screen); pscreen = pipe_loader_create_screen(screen->dev); @@ -2180,10 +2174,7 @@ destroy_screen: release_pipe: if (screen->dev) pipe_loader_release(&screen->dev, 1); - else - close(fd); -free_screen: FREE(screen); return NULL; } @@ -2212,10 +2203,7 @@ dri_kms_init_screen(__DRIscreen * sPriv) sPriv->driverPrivate = (void *)screen; - if (screen->fd < 0 || (fd = fcntl(screen->fd, F_DUPFD_CLOEXEC, 3)) < 0) - goto free_screen; - - if (pipe_loader_sw_probe_kms(&screen->dev, fd)) { + if (pipe_loader_sw_probe_kms(&screen->dev, screen->fd)) { dri_init_options(screen); pscreen = pipe_loader_create_screen(screen->dev); } @@ -2257,10 +2245,7 @@ destroy_screen: release_pipe: if (screen->dev) pipe_loader_release(&screen->dev, 1); - else - close(fd); -free_screen: FREE(screen); #endif // GALLIUM_SOFTPIPE return NULL; diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 308e23685e8..82a0988a634 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -488,6 +488,7 @@ dri_destroy_screen(__DRIscreen * sPriv) pipe_loader_release(&screen->dev, 1); + /* The caller in dri_util preserves the fd ownership */ free(screen); sPriv->driverPrivate = NULL; sPriv->extensions = NULL; diff --git a/src/gallium/state_trackers/xa/xa_tracker.c b/src/gallium/state_trackers/xa/xa_tracker.c index c046a3a7097..d07cd146af9 100644 --- a/src/gallium/state_trackers/xa/xa_tracker.c +++ b/src/gallium/state_trackers/xa/xa_tracker.c @@ -27,7 +27,6 @@ */ #include <unistd.h> -#include <fcntl.h> #include "xa_tracker.h" #include "xa_priv.h" #include "pipe/p_state.h" @@ -153,15 +152,11 @@ xa_tracker_create(int drm_fd) struct xa_tracker *xa = calloc(1, sizeof(struct xa_tracker)); enum xa_surface_type stype; unsigned int num_formats; - int fd; if (!xa) return NULL; - if (drm_fd < 0 || (fd = fcntl(drm_fd, F_DUPFD_CLOEXEC, 3)) < 0) - goto out_no_fd; - - if (pipe_loader_drm_probe_fd(&xa->dev, fd)) + if (pipe_loader_drm_probe_fd(&xa->dev, drm_fd)) xa->screen = pipe_loader_create_screen(xa->dev); if (!xa->screen) @@ -213,9 +208,7 @@ xa_tracker_create(int drm_fd) out_no_screen: if (xa->dev) pipe_loader_release(&xa->dev, 1); - else - close(fd); - out_no_fd: + free(xa); return NULL; } @@ -227,6 +220,7 @@ xa_tracker_destroy(struct xa_tracker *xa) xa_context_destroy(xa->default_ctx); xa->screen->destroy(xa->screen); pipe_loader_release(&xa->dev, 1); + /* CHECK: The XA API user preserves ownership of the original fd */ free(xa); } |