Skip to contentSkip to conversation

vgaarb: minor fixes on return value

PATCH New Abel Wu 1 participant 3 messages Jan 30, 2021

Subsystems (2)
lore
Share & tools
lore

Abel Wu

author
#0 lore raw

cover vgaarb: minor fixes on return value

Two minor fixes on return value, of which one for the pci notifer and the other for initcall.

Abel Wu (2):
vgaarb: Fix return value of notifier callback
vgaarb: Make initcall always return success

 drivers/gpu/vga/vgaarb.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)
Signature · 6 lines
2.27.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#1 lore raw

PATCH 1/2 vgaarb: Fix return value of notifier callback

If it's not a vga device, just don't care (NOTIFY_DONE). Otherwise return NOTIFY_OK after processing done.

---
 drivers/gpu/vga/vgaarb.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
drivers/gpu/vga/vgaarb.c +20 -11
index 5180c5687ee5..2879d4223bf1 100644
@@ -644,6 +644,11 @@ static void vga_arbiter_check_bridge_sharing(struct vga_device *vgadev)
 	}
 }
 
+static inline bool vga_class(struct pci_dev *pdev)
+{
+	return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
+}
+
 /*
  * Currently, we assume that the "initial" setup of the system is
  * not sane, that is we come up with conflicting devices and let
@@ -658,10 +663,6 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)
 	struct pci_dev *bridge;
 	u16 cmd;
 
-	/* Only deal with VGA class devices */
-	if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
-		return false;
-
 	/* Allocate structure */
 	vgadev = kzalloc(sizeof(struct vga_device), GFP_KERNEL);
 	if (vgadev == NULL) {
@@ -1420,6 +1421,9 @@ static int pci_notify(struct notifier_block *nb, unsigned long action,
 
 	vgaarb_dbg(dev, "%s\n", __func__);
 
+	if (!vga_class(pdev))
+		return NOTIFY_DONE;
+
 	/* For now we're only intereted in devices added and removed. I didn't
 	 * test this thing here, so someone needs to double check for the
 	 * cases of hotplugable vga cards. */
@@ -1430,7 +1434,8 @@ static int pci_notify(struct notifier_block *nb, unsigned long action,
 
 	if (notify)
 		vga_arbiter_notify_clients();
-	return 0;
+
+	return NOTIFY_OK;
 }
 
 static struct notifier_block pci_notifier = {
@@ -1533,7 +1538,7 @@ static void __init vga_arb_select_default_device(void)
 static int __init vga_arb_device_init(void)
 {
 	int rc;
-	struct pci_dev *pdev;
+	struct pci_dev *pdev = NULL;
 	struct vga_device *vgadev;
 
 	rc = misc_register(&vga_arb_device);
@@ -1544,11 +1549,15 @@ static int __init vga_arb_device_init(void)
 
 	/* We add all PCI devices satisfying VGA class in the arbiter by
 	 * default */
-	pdev = NULL;
-	while ((pdev =
-		pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
-			       PCI_ANY_ID, pdev)) != NULL)
-		vga_arbiter_add_pci_device(pdev);
+	while (1) {
+		pdev = pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
+				      PCI_ANY_ID, pdev);
+		if (!pdev)
+			break;
+
+		if (vga_class(pdev))
+			vga_arbiter_add_pci_device(pdev);
+	}
 
 	list_for_each_entry(vgadev, &vga_list, list) {
 		struct device *dev = &vgadev->pdev->dev;
Signature · 6 lines
2.27.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#2 lore raw

PATCH 2/2 vgaarb: Make initcall always return success

In reply to Abel Wu

Returning error usually implies failure, in which case anything that has done should be properly reverted. Thus if failed in registering /dev/vga_arbiter, it is better to just throw out a warning than returning error without unregistering pci_notifier.

---
 drivers/gpu/vga/vgaarb.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/vga/vgaarb.c +3 -5
index 2879d4223bf1..eff6b78e3372 100644
@@ -1537,13 +1537,11 @@ static void __init vga_arb_select_default_device(void)
 
 static int __init vga_arb_device_init(void)
 {
-	int rc;
 	struct pci_dev *pdev = NULL;
 	struct vga_device *vgadev;
 
-	rc = misc_register(&vga_arb_device);
-	if (rc < 0)
-		pr_err("error %d registering device\n", rc);
+	if (misc_register(&vga_arb_device))
+		pr_warn("failed registering /dev/vga_arbiter\n");
 
 	bus_register_notifier(&pci_bus_type, &pci_notifier);
 
@@ -1571,6 +1569,6 @@ static int __init vga_arb_device_init(void)
 	vga_arb_select_default_device();
 
 	pr_info("loaded\n");
-	return rc;
+	return 0;
 }
 subsys_initcall(vga_arb_device_init);
Signature · 6 lines
2.27.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel