Skip to contentSkip to conversation

uio: do not use PCI resources before pci_enable_device()

PATCH In review Kulikov Vasiliy 3 participants 3 messages Aug 3, 2010

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

PATCH 10/11 uio: do not use PCI resources before pci_enable_device()

IRQ and resource[] may not have correct values until after PCI hotplug setup occurs at pci_enable_device() time.

The semantic match that finds this problem is as follows:

// <smpl>
@@
identifier x;
identifier request ~= "pci_request.*|pci_resource.*"; @@

(
* x->irq
|
* x->resource
|
* request(x, ...)
)
...
*pci_enable_device(x)
// </smpl>

---
 drivers/uio/uio_pci_generic.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/uio/uio_pci_generic.c +7 -6
index 85c9884..fc22e1e 100644
@@ -128,12 +128,6 @@ static int __devinit probe(struct pci_dev *pdev,
 	struct uio_pci_generic_dev *gdev;
 	int err;
 
-	if (!pdev->irq) {
-		dev_warn(&pdev->dev, "No IRQ assigned to device: "
-			 "no support for interrupts?\n");
-		return -ENODEV;
-	}
-
 	err = pci_enable_device(pdev);
 	if (err) {
 		dev_err(&pdev->dev, "%s: pci_enable_device failed: %d\n",
@@ -141,6 +135,13 @@ static int __devinit probe(struct pci_dev *pdev,
 		return err;
 	}
 
+	if (!pdev->irq) {
+		dev_warn(&pdev->dev, "No IRQ assigned to device: "
+			 "no support for interrupts?\n");
+		pci_disable_device(pdev);
+		return -ENODEV;
+	}
+
 	err = verify_pci_2_3(pdev);
 	if (err)
 		goto err_verify;
Signature · 1 line
1.7.0.4
maintainer Acked-by on v1 10/11
#1 lore raw
Quoted 22 lines · Kulikov Vasiliy

IRQ and resource[] may not have correct values until after PCI hotplug setup occurs at pci_enable_device() time.

The semantic match that finds this problem is as follows:

// <smpl>
@@
identifier x;
identifier request ~= "pci_request.*|pci_resource.*"; @@

(
* x->irq
|
* x->resource
|
* request(x, ...)
)
...
*pci_enable_device(x)
// </smpl>

Quoted 1 line

Looks sane.

Quoted 37 lines
---
 drivers/uio/uio_pci_generic.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/uio/uio_pci_generic.c +7 -6
index 85c9884..fc22e1e 100644
@@ -128,12 +128,6 @@ static int __devinit probe(struct pci_dev *pdev,
 	struct uio_pci_generic_dev *gdev;
 	int err;
 
-	if (!pdev->irq) {
-		dev_warn(&pdev->dev, "No IRQ assigned to device: "
-			 "no support for interrupts?\n");
-		return -ENODEV;
-	}
-
 	err = pci_enable_device(pdev);
 	if (err) {
 		dev_err(&pdev->dev, "%s: pci_enable_device failed: %d\n",
@@ -141,6 +135,13 @@ static int __devinit probe(struct pci_dev *pdev,
 		return err;
 	}
 
+	if (!pdev->irq) {
+		dev_warn(&pdev->dev, "No IRQ assigned to device: "
+			 "no support for interrupts?\n");
+		pci_disable_device(pdev);
+		return -ENODEV;
+	}
+
 	err = verify_pci_2_3(pdev);
 	if (err)
 		goto err_verify;
Signature · 1 line
1.7.0.4
#2 lore raw
In reply to Kulikov Vasiliy
Quoted 22 lines · Kulikov Vasiliy

IRQ and resource[] may not have correct values until after PCI hotplug setup occurs at pci_enable_device() time.

The semantic match that finds this problem is as follows:

// <smpl>
@@
identifier x;
identifier request ~= "pci_request.*|pci_resource.*"; @@

(
* x->irq
|
* x->resource
|
* request(x, ...)
)
...
*pci_enable_device(x)
// </smpl>

Quoted 1 line

Looks alright to me, thanks!

Quoted 37 lines
---
 drivers/uio/uio_pci_generic.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/uio/uio_pci_generic.c +7 -6
index 85c9884..fc22e1e 100644
@@ -128,12 +128,6 @@ static int __devinit probe(struct pci_dev *pdev,
 	struct uio_pci_generic_dev *gdev;
 	int err;
 
-	if (!pdev->irq) {
-		dev_warn(&pdev->dev, "No IRQ assigned to device: "
-			 "no support for interrupts?\n");
-		return -ENODEV;
-	}
-
 	err = pci_enable_device(pdev);
 	if (err) {
 		dev_err(&pdev->dev, "%s: pci_enable_device failed: %d\n",
@@ -141,6 +135,13 @@ static int __devinit probe(struct pci_dev *pdev,
 		return err;
 	}
 
+	if (!pdev->irq) {
+		dev_warn(&pdev->dev, "No IRQ assigned to device: "
+			 "no support for interrupts?\n");
+		pci_disable_device(pdev);
+		return -ENODEV;
+	}
+
 	err = verify_pci_2_3(pdev);
 	if (err)
 		goto err_verify;
Signature · 1 line
1.7.0.4