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 <leo.liu@amd.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Axel Davy <davyaxel0@gmail.com>
Cc: Patrick Rudolph <siro@das-labor.org>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Axel Davy <davyaxel0@gmail.com> (for nine)
*
* 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
#include <string.h>
#include <xf86drm.h>
#include <unistd.h>
+#include <fcntl.h>
#include "loader.h"
#include "target-helpers/drm_helper_public.h"
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;
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)
{
if (fd < 0)
continue;
- if (!pipe_loader_drm_probe_fd(&dev, fd)) {
+ if (!pipe_loader_drm_probe_fd_nodup(&dev, fd)) {
close(fd);
continue;
}
#include <sys/types.h>
#include <sys/stat.h>
-#include <fcntl.h>
#include <X11/Xlib-xcb.h>
#include <X11/extensions/dri2tokens.h>
vl_compositor_reset_dirty_area(&scrn->dirty_areas[0]);
vl_compositor_reset_dirty_area(&scrn->dirty_areas[1]);
+ /* The pipe loader duplicates the fd */
+ close(fd);
free(authenticate);
free(connect);
free(dri2_query);
return &scrn->base;
release_pipe:
- if (scrn->base.dev) {
+ if (scrn->base.dev)
pipe_loader_release(&scrn->base.dev, 1);
- fd = -1;
- }
free_authenticate:
free(authenticate);
close_fd:
- if (fd != -1)
- close(fd);
+ close(fd);
free_connect:
free(connect);
free_query:
vl_dri2_destroy_drawable(scrn);
scrn->base.pscreen->destroy(scrn->base.pscreen);
pipe_loader_release(&scrn->base.dev, 1);
+ /* There is no user provided fd */
FREE(scrn);
}
**************************************************************************/
#include <assert.h>
-#include <fcntl.h>
#include "pipe/p_screen.h"
#include "pipe-loader/pipe_loader.h"
if (!vscreen)
return NULL;
- if (fd < 0 || (new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3)) < 0)
- goto free_screen;
-
- if (pipe_loader_drm_probe_fd(&vscreen->dev, new_fd))
+ if (pipe_loader_drm_probe_fd(&vscreen->dev, fd))
vscreen->pscreen = pipe_loader_create_screen(vscreen->dev);
if (!vscreen->pscreen)
release_pipe:
if (vscreen->dev)
pipe_loader_release(&vscreen->dev, 1);
- else
- close(new_fd);
-free_screen:
FREE(vscreen);
return NULL;
}
vscreen->pscreen->destroy(vscreen->pscreen);
pipe_loader_release(&vscreen->dev, 1);
+ /* CHECK: The VAAPI loader/user preserves ownership of the original fd */
FREE(vscreen);
}
*/
#include <xf86drm.h>
-#include <fcntl.h>
#include "GL/mesa_glinterop.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
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)
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);
release_pipe:
if (screen->dev)
pipe_loader_release(&screen->dev, 1);
- else
- close(fd);
-free_screen:
FREE(screen);
return NULL;
}
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);
}
release_pipe:
if (screen->dev)
pipe_loader_release(&screen->dev, 1);
- else
- close(fd);
-free_screen:
FREE(screen);
#endif // GALLIUM_SOFTPIPE
return NULL;
pipe_loader_release(&screen->dev, 1);
+ /* The caller in dri_util preserves the fd ownership */
free(screen);
sPriv->driverPrivate = NULL;
sPriv->extensions = NULL;
*/
#include <unistd.h>
-#include <fcntl.h>
#include "xa_tracker.h"
#include "xa_priv.h"
#include "pipe/p_state.h"
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)
out_no_screen:
if (xa->dev)
pipe_loader_release(&xa->dev, 1);
- else
- close(fd);
- out_no_fd:
+
free(xa);
return NULL;
}
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);
}
if (drm->dev)
pipe_loader_release(&drm->dev, 1);
- /* The pipe loader takes ownership of the fd */
+ close(drm->fd);
FREE(ctx);
}