hw/display: fail early when multiple virgl devices are requested
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Mon, 5 Jul 2021 10:42:18 +0000 (14:42 +0400)
committerGerd Hoffmann <kraxel@redhat.com>
Thu, 22 Jul 2021 13:46:47 +0000 (15:46 +0200)
This avoids failing to initialize virgl and crashing later on, and clear
the user expectations.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20210705104218.1161101-1-marcandre.lureau@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/display/virtio-gpu-gl.c

index 7ab93bf8c829a21a51a25fde341a867ae5c8e3bf..b1035e119c3b4700c57956da612def7729e77b8d 100644 (file)
@@ -113,6 +113,11 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
     return;
 #endif
 
+    if (!object_resolve_path_type("", TYPE_VIRTIO_GPU_GL, NULL)) {
+        error_setg(errp, "at most one %s device is permitted", TYPE_VIRTIO_GPU_GL);
+        return;
+    }
+
     if (!display_opengl) {
         error_setg(errp, "opengl is not available");
         return;