[Mesa-dev] [PATCH] pipe-loader: add a dup() in pipe_loader_sw_probe_kms

Emil Velikov emil.l.velikov at gmail.com
Thu Aug 30 16:24:16 UTC 2018


From: Emil Velikov <emil.velikov at collabora.com>

The pipe_loader_release API closes the fd given, even if the pipe-loader
should _not_ take ownership of it.

With earlier commit we fixed pipe_loader_drm_probe_fd, and now with
cover the final piece.

Note that unlike the DRM case, here the caller _did_ forget to dup
before using it ... most likely leading to all sorts of fun.

Don't forget the close in the error path. Seems like the things are a
bit leaky/asymmetrical with the semi-recent config work. But we can shave
that yak another day ;-)

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
Strictly speaking we could add the dup() in st/dri sending that for stable.
Since there aren't that many users of kms_swarast to actually notice the
problem, I went with only one patch ;-)

Can rework if people prefer.
---
 src/gallium/auxiliary/pipe-loader/pipe_loader.h    |  3 +++
 src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c | 11 +++++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.h b/src/gallium/auxiliary/pipe-loader/pipe_loader.h
index cbc9f3af9b1..be40f98d5fc 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_sw.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c
index 84894c0caf6..d387ce90d32 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c
@@ -25,6 +25,10 @@
  *
  **************************************************************************/
 
+#ifdef HAVE_PIPE_LOADER_KMS
+#include <fcntl.h>
+#endif
+
 #include "pipe_loader_priv.h"
 
 #include "util/u_memory.h"
@@ -171,11 +175,12 @@ pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
    if (!pipe_loader_sw_probe_init_common(sdev))
       goto fail;
 
-   sdev->fd = fd;
+   if (fd < 0 || (sdev->fd = fcntl(fd, F_DUPFD_CLOEXEC, 3)) < 0)
+      goto fail;
 
    for (i = 0; sdev->dd->winsys[i].name; i++) {
       if (strcmp(sdev->dd->winsys[i].name, "kms_dri") == 0) {
-         sdev->ws = sdev->dd->winsys[i].create_winsys(fd);
+         sdev->ws = sdev->dd->winsys[i].create_winsys(sdev->fd);
          break;
       }
    }
@@ -187,6 +192,8 @@ pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
 
 fail:
    pipe_loader_sw_probe_teardown_common(sdev);
+   if (sdev->fd != -1)
+      close(sdev->fd);
    FREE(sdev);
    return false;
 }
-- 
2.18.0



More information about the mesa-dev mailing list