Skip to content

Commit 49f4b08

Browse files
Gavin Shanmpe
authored andcommitted
pci/hotplug/pnv-php: Disable MSI and PCI device properly
pnv_php_disable_irq() can be called in two paths: Bailing path in pnv_php_enable_irq() or releasing slot. The MSI (or MSIx) interrupts is disabled unconditionally in pnv_php_disable_irq(). It's wrong because that might be enabled by drivers other than pnv-php. This disables MSI (or MSIx) interrupts and the PCI device only if it was enabled by pnv-php. In the error path of pnv_php_enable_irq(), we rely on the newly added parameter @disable_device. In the path of releasing slot, @pnv_php->irq is checked. Cc: <stable@vger.kernel.org> # v4.9+ Fixes: 360aebd ("drivers/pci/hotplug: Support surprise hotplug in powernv driver") Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 303529d commit 49f4b08

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎drivers/pci/hotplug/pnv_php.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ static void pnv_php_register(struct device_node *dn);
3535
static void pnv_php_unregister_one(struct device_node *dn);
3636
static void pnv_php_unregister(struct device_node *dn);
3737

38-
static void pnv_php_disable_irq(struct pnv_php_slot *php_slot)
38+
static void pnv_php_disable_irq(struct pnv_php_slot *php_slot,
39+
bool disable_device)
3940
{
4041
struct pci_dev *pdev = php_slot->pdev;
42+
int irq = php_slot->irq;
4143
u16 ctrl;
4244

4345
if (php_slot->irq > 0) {
@@ -56,10 +58,14 @@ static void pnv_php_disable_irq(struct pnv_php_slot *php_slot)
5658
php_slot->wq = NULL;
5759
}
5860

59-
if (pdev->msix_enabled)
60-
pci_disable_msix(pdev);
61-
else if (pdev->msi_enabled)
62-
pci_disable_msi(pdev);
61+
if (disable_device || irq > 0) {
62+
if (pdev->msix_enabled)
63+
pci_disable_msix(pdev);
64+
else if (pdev->msi_enabled)
65+
pci_disable_msi(pdev);
66+
67+
pci_disable_device(pdev);
68+
}
6369
}
6470

6571
static void pnv_php_free_slot(struct kref *kref)
@@ -68,7 +74,7 @@ static void pnv_php_free_slot(struct kref *kref)
6874
struct pnv_php_slot, kref);
6975

7076
WARN_ON(!list_empty(&php_slot->children));
71-
pnv_php_disable_irq(php_slot);
77+
pnv_php_disable_irq(php_slot, false);
7278
kfree(php_slot->name);
7379
kfree(php_slot);
7480
}
@@ -777,7 +783,7 @@ static void pnv_php_init_irq(struct pnv_php_slot *php_slot, int irq)
777783
php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name);
778784
if (!php_slot->wq) {
779785
dev_warn(&pdev->dev, "Cannot alloc workqueue\n");
780-
pnv_php_disable_irq(php_slot);
786+
pnv_php_disable_irq(php_slot, true);
781787
return;
782788
}
783789

@@ -799,7 +805,7 @@ static void pnv_php_init_irq(struct pnv_php_slot *php_slot, int irq)
799805
ret = request_irq(irq, pnv_php_interrupt, IRQF_SHARED,
800806
php_slot->name, php_slot);
801807
if (ret) {
802-
pnv_php_disable_irq(php_slot);
808+
pnv_php_disable_irq(php_slot, true);
803809
dev_warn(&pdev->dev, "Error %d enabling IRQ %d\n", ret, irq);
804810
return;
805811
}

0 commit comments

Comments
 (0)