Module: Mesa
Branch: main
Commit: 3ca5f3bf00ed11017022685346ed002b2e3f179c
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3ca5f3bf00ed11017022685346ed002b2e3f179c

Author: Rob Clark <robdcl...@chromium.org>
Date:   Sun Nov 12 11:07:33 2023 -0800

freedreno/drm: Fix mmap leak

In the fd_bo_upload() path, we don't want to trigger duplicate mmap's.

Fixes: 53ccb421a272 ("freedreno/drm: Simplify backend mmap impl")
Signed-off-by: Rob Clark <robdcl...@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26162>

---

 src/freedreno/drm/freedreno_bo.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c
index 293a9744fd5..efde63ec73f 100644
--- a/src/freedreno/drm/freedreno_bo.c
+++ b/src/freedreno/drm/freedreno_bo.c
@@ -606,15 +606,9 @@ fd_bo_map_os_mmap(struct fd_bo *bo)
                   bo->dev->fd, offset);
 }
 
-void *
-fd_bo_map(struct fd_bo *bo)
+static void *
+__fd_bo_map(struct fd_bo *bo)
 {
-   /* don't allow mmap'ing something allocated with FD_BO_NOMAP
-    * for sanity
-    */
-   if (bo->alloc_flags & FD_BO_NOMAP)
-      return NULL;
-
    if (!bo->map) {
       bo->map = bo->funcs->map(bo);
       if (bo->map == MAP_FAILED) {
@@ -626,6 +620,18 @@ fd_bo_map(struct fd_bo *bo)
    return bo->map;
 }
 
+void *
+fd_bo_map(struct fd_bo *bo)
+{
+   /* don't allow mmap'ing something allocated with FD_BO_NOMAP
+    * for sanity
+    */
+   if (bo->alloc_flags & FD_BO_NOMAP)
+      return NULL;
+
+   return __fd_bo_map(bo);
+}
+
 void
 fd_bo_upload(struct fd_bo *bo, void *src, unsigned off, unsigned len)
 {
@@ -634,7 +640,7 @@ fd_bo_upload(struct fd_bo *bo, void *src, unsigned off, 
unsigned len)
       return;
    }
 
-   memcpy((uint8_t *)bo->funcs->map(bo) + off, src, len);
+   memcpy((uint8_t *)__fd_bo_map(bo) + off, src, len);
 }
 
 bool

Reply via email to