From ea0dce26e0991e7fcf04cb1fecb2d9ae6b2955f4 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 11 Aug 2023 17:50:23 +0800 Subject: [PATCH] kmssink: Do not close the DRM prime handle twice The prime_fds for multi planes may be the same. For example, on Intel's platform, the NV12 surface may have the same FD for the plane0 and the plane1. Then, the DRM_IOCTL_GEM_CLOSE will close the same handle twice and get an "Invalid argument 22" error the second time. Part-of: --- subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c b/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c index fefea31f4f..3ec2fdb32d 100644 --- a/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c +++ b/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c @@ -427,7 +427,7 @@ gst_kms_allocator_dmabuf_import (GstAllocator * allocator, gint * prime_fds, GstKMSAllocator *alloc; GstKMSMemory *kmsmem; GstMemory *mem; - gint i, ret; + gint i, j, ret; guint32 gem_handle[4] = { 0, }; g_return_val_if_fail (n_planes <= GST_VIDEO_MAX_PLANES, FALSE); @@ -456,6 +456,14 @@ done: if (!gem_handle[i]) continue; + /* Do not close the same handle twice. */ + for (j = 0; j < i; j++) { + if (gem_handle[j] == gem_handle[i]) + break; + } + if (j < i) + continue; + err = drmIoctl (alloc->priv->fd, DRM_IOCTL_GEM_CLOSE, &arg); if (err) GST_WARNING_OBJECT (allocator,