Skip to contentSkip to conversation

drm/virtio: Don't return error if virtio-gpu PCI dev is not found

PATCH Applied Vivek Kasireddy 2 participants 2 messages Jan 14, 2025 – Jan 19, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/virtio: Don't return error if virtio-gpu PCI dev is not found

While fixing a shared VGA resource ownership issue, commit 5dd8b536bb ("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 5dd8b536bb ("drm/virtio: Lock the VGA resources during initialization")
Cc Gerd Hoffmann <[email protected]>
Cc Gurchetan Singh <[email protected]>
Cc Chia-I Wu <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +11 -10
index d4309dba557b..2d88e390feb4 100644
@@ -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;
 }
Signature · 1 line
2.47.1
maintainer Applied
#1 lore raw
Quoted 16 lines · Vivek Kasireddy

While fixing a shared VGA resource ownership issue, commit 5dd8b536bb ("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 5dd8b536bb ("drm/virtio: Lock the VGA resources during initialization")
Cc Gerd Hoffmann <[email protected]>
Cc Gurchetan Singh <[email protected]>
Cc Chia-I Wu <[email protected]>
Quoted 3 lines
---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Applied to misc-next, thanks!

Signature · 2 lines
Best regards,
Dmitry