On 9/10/26 16:29, Marc-André Lureau wrote:
All allocation sites used g_new0() which zero-initializes fields.
However share_handle must be SHAREABLE_NONE (-1 on Unix, NULL on
Windows) and dmabuf_fd must be -1, not 0. Centralize allocation and
field initialization in new constructors fix this and reduce code
duplication.
This fixes -display dbus with virtio-gpu blob resources. The other
end is currently receiving qemu fd 0.
Fixes: 5f899c34af1d (“virtio-gpu: allocate shareable 2d resources on !win32”)
Reviewed-by: Akihiko Odaki <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
+static struct virtio_gpu_virgl_resource *
+virtio_gpu_virgl_resource_new_blob(uint32_t resource_id...
@@ -853,10 +872,7 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g,
return;
}
- res = g_new0(struct virtio_gpu_virgl_resource, 1);
- res->base.resource_id = cblob.resource_id;
- res->base.blob_size = cblob.size;
- res->base.dmabuf_fd = -1;
+ res = virtio_gpu_virgl_resource_new_blob(cblob.resource_id, cblob.size);
if (cblob.blob_mem != VIRTIO_GPU_BLOB_MEM_HOST3D) {
ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries,
sizeof(cblob),
The newly introduced virtio_gpu_virgl_resource_new_blob() (static) has just one
user,
in virgl_cmd_resource_create_blob(). And the latter is guarded with
#if VIRGL_VERSION_MAJOR >= 1
#endif
So if this condition is unmet, there's a build failure:
hw/display/virtio-gpu-virgl.c:328:1: error:
‘virtio_gpu_virgl_resource_new_blob’ defined but not used
So we either should not move this single place of code into its own function,
or we should guard this function with the same #if.
Thanks,
/mjt