]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/virtio: Fix missed dmabuf unpinning in error path of prepare_fb()
authorDmitry Osipenko <dmitry.osipenko@collabora.com>
Tue, 1 Apr 2025 12:38:42 +0000 (15:38 +0300)
committerDmitry Osipenko <dmitry.osipenko@collabora.com>
Tue, 1 Apr 2025 20:11:55 +0000 (23:11 +0300)
Correct error handling in prepare_fb() to fix leaking resources when
error happens.

Fixes: 4a696a2ee646 ("drm/virtio: Add prepare and cleanup routines for imported dmabuf obj")
Cc: <stable@vger.kernel.org> # v6.14+
Acked-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://lore.kernel.org/r/20250401123842.2232205-2-dmitry.osipenko@collabora.com
drivers/gpu/drm/virtio/virtgpu_plane.c

index 42aa554eca9fef9f9f6b043cbd41f57a1b059987..26abe3d1b122b4cc5c95c1251679fc8a8980fee7 100644 (file)
@@ -322,12 +322,6 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
                return 0;
 
        obj = new_state->fb->obj[0];
-       if (obj->import_attach) {
-               ret = virtio_gpu_prepare_imported_obj(plane, new_state, obj);
-               if (ret)
-                       return ret;
-       }
-
        if (bo->dumb || obj->import_attach) {
                vgplane_st->fence = virtio_gpu_fence_alloc(vgdev,
                                                     vgdev->fence_drv.context,
@@ -336,7 +330,21 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
                        return -ENOMEM;
        }
 
+       if (obj->import_attach) {
+               ret = virtio_gpu_prepare_imported_obj(plane, new_state, obj);
+               if (ret)
+                       goto err_fence;
+       }
+
        return 0;
+
+err_fence:
+       if (vgplane_st->fence) {
+               dma_fence_put(&vgplane_st->fence->f);
+               vgplane_st->fence = NULL;
+       }
+
+       return ret;
 }
 
 static void virtio_gpu_cleanup_imported_obj(struct drm_gem_object *obj)