summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/pipe-loader
diff options
context:
space:
mode:
authorEmil Velikov <[email protected]>2018-08-29 18:13:14 +0100
committerEmil Velikov <[email protected]>2018-10-03 13:38:05 +0100
commit6ccc435e7ad92bb0ba77d3fdb48c7127ba71239e (patch)
tree6ca059b425d4b452bcfe76a634d4d852bed0f6d8 /src/gallium/auxiliary/pipe-loader
parent7b8d1b313cd01bb916898d8bb92a566534e37677 (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/auxiliary/pipe-loader')
-rw-r--r--src/gallium/auxiliary/pipe-loader/pipe_loader.h3
-rw-r--r--src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c23
2 files changed, 23 insertions, 3 deletions
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.h b/src/gallium/auxiliary/pipe-loader/pipe_loader.h
index b50114310b4..be7e25afb02 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader.h
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.h
@@ -146,6 +146,9 @@ pipe_loader_sw_probe_dri(struct pipe_loader_device **devs,
*
* This function is platform-specific.
*
+ * Function does not take ownership of the fd, but duplicates it locally.
+ * The local fd is closed during pipe_loader_release.
+ *
* \sa pipe_loader_probe
*/
bool
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
index 6d2ed6e76f8..5a88a2ac2f0 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -35,6 +35,7 @@
#include <string.h>
#include <xf86drm.h>
#include <unistd.h>
+#include <fcntl.h>
#include "loader.h"
#include "target-helpers/drm_helper_public.h"
@@ -168,8 +169,8 @@ get_driver_descriptor(const char *driver_name, struct util_dl_library **plib)
return NULL;
}
-bool
-pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
+static bool
+pipe_loader_drm_probe_fd_nodup(struct pipe_loader_device **dev, int fd)
{
struct pipe_loader_drm_device *ddev = CALLOC_STRUCT(pipe_loader_drm_device);
int vendor_id, chip_id;
@@ -212,6 +213,22 @@ pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
return false;
}
+bool
+pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd)
+{
+ bool ret;
+ int new_fd;
+
+ if (fd < 0 || (new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3)) < 0)
+ return false;
+
+ ret = pipe_loader_drm_probe_fd_nodup(dev, new_fd);
+ if (!ret)
+ close(new_fd);
+
+ return ret;
+}
+
static int
open_drm_render_node_minor(int minor)
{
@@ -234,7 +251,7 @@ pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev)
if (fd < 0)
continue;
- if (!pipe_loader_drm_probe_fd(&dev, fd)) {
+ if (!pipe_loader_drm_probe_fd_nodup(&dev, fd)) {
close(fd);
continue;
}