]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
ui/gtk: Check if fence_fd is equal to or greater than 0
authorDongwon Kim <dongwon.kim@intel.com>
Wed, 8 May 2024 17:53:58 +0000 (10:53 -0700)
committerMichael Tokarev <mjt@tls.msk.ru>
Mon, 27 May 2024 04:30:35 +0000 (07:30 +0300)
'fence_fd' needs to be validated always before being referenced
And the passing condition should include '== 0' as 0 is a valid
value for the file descriptor.

Suggested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: Daniel P. Berrangé <berrange@redhat.com>
Cc: Vivek Kasireddy <vivek.kasireddy@intel.com>
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
Message-Id: <20240508175403.3399895-2-dongwon.kim@intel.com>
(cherry picked from commit e4e62514e3cc2fc9dbae44af8b80f61c730beab4)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
ui/gtk-egl.c
ui/gtk-gl-area.c
ui/gtk.c

index 7ff9f1648c626a0214d6179231bffa0c8aaf44e1..b3d035484525e1967d127d40124ccbdfdd49b155 100644 (file)
@@ -96,7 +96,7 @@ void gd_egl_draw(VirtualConsole *vc)
 #ifdef CONFIG_GBM
         if (dmabuf) {
             egl_dmabuf_create_fence(dmabuf);
-            if (dmabuf->fence_fd > 0) {
+            if (dmabuf->fence_fd >= 0) {
                 qemu_set_fd_handler(dmabuf->fence_fd, gd_hw_gl_flushed, NULL, vc);
                 return;
             }
index 1605818bd1c6deb8fdbb989c72a862799a95fa73..c65e2a0d0cf5adb1018ec54dc304736d8a5ba158 100644 (file)
@@ -85,7 +85,7 @@ void gd_gl_area_draw(VirtualConsole *vc)
 #ifdef CONFIG_GBM
         if (dmabuf) {
             egl_dmabuf_create_fence(dmabuf);
-            if (dmabuf->fence_fd > 0) {
+            if (dmabuf->fence_fd >= 0) {
                 qemu_set_fd_handler(dmabuf->fence_fd, gd_hw_gl_flushed, NULL, vc);
                 return;
             }
index 8d740fae8365c984e3f23a6c7fa9d2331b7a1606..17a34d37d9951a9abce40545614344e5e456f5ce 100644 (file)
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -589,10 +589,12 @@ void gd_hw_gl_flushed(void *vcon)
     VirtualConsole *vc = vcon;
     QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
 
-    qemu_set_fd_handler(dmabuf->fence_fd, NULL, NULL, NULL);
-    close(dmabuf->fence_fd);
-    dmabuf->fence_fd = -1;
-    graphic_hw_gl_block(vc->gfx.dcl.con, false);
+    if (dmabuf->fence_fd >= 0) {
+        qemu_set_fd_handler(dmabuf->fence_fd, NULL, NULL, NULL);
+        close(dmabuf->fence_fd);
+        dmabuf->fence_fd = -1;
+        graphic_hw_gl_block(vc->gfx.dcl.con, false);
+    }
 }
 
 /** DisplayState Callbacks (opengl version) **/