drm/virtio: Don't return error if virtio-gpu PCI dev is not found
authorVivek Kasireddy <vivek.kasireddy@intel.com>
Tue, 14 Jan 2025 07:57:59 +0000 (23:57 -0800)
committerDmitry Osipenko <dmitry.osipenko@collabora.com>
Sun, 19 Jan 2025 12:24:27 +0000 (15:24 +0300)
While fixing a shared VGA resource ownership issue, commit 5dd8b536bbda
("drm/virtio: Lock the VGA resources during initialization") wrongly
assumed that there is always a PCI device associated with virtio-gpu
and it would return error if this device is not found during init.

This is incorrect, as virtio-gpu can be operated in MMIO mode (M68K)
where a PCI device would probably not be created for it. Therefore,
fix this issue by not erroring out if the associated PCI device is
not found during initialization.

Fixes: 5dd8b536bbda ("drm/virtio: Lock the VGA resources during initialization")
Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Chia-I Wu <olvaffe@gmail.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250114075759.2616551-1-vivek.kasireddy@intel.com
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250114075759.2616551-1-vivek.kasireddy@intel.com
drivers/gpu/drm/virtio/virtgpu_drv.c

index d4309dba557bf1a7561591f550215c7b410483f6..2d88e390feb468bf8783f13d90d0c4759dff0dcf 100644 (file)
@@ -173,23 +173,24 @@ static int __init virtio_gpu_driver_init(void)
        pdev = pci_get_device(PCI_VENDOR_ID_REDHAT_QUMRANET,
                              PCI_DEVICE_ID_VIRTIO_GPU,
                              NULL);
-       if (!pdev)
-               return -ENODEV;
-
-       if (pci_is_vga(pdev)) {
+       if (pdev && pci_is_vga(pdev)) {
                ret = vga_get_interruptible(pdev,
                        VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM);
-               if (ret)
-                       goto error;
+               if (ret) {
+                       pci_dev_put(pdev);
+                       return ret;
+               }
        }
 
        ret = register_virtio_driver(&virtio_gpu_driver);
 
-       if (pci_is_vga(pdev))
-               vga_put(pdev, VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM);
+       if (pdev) {
+               if (pci_is_vga(pdev))
+                       vga_put(pdev,
+                               VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM);
 
-error:
-       pci_dev_put(pdev);
+               pci_dev_put(pdev);
+       }
 
        return ret;
 }