lkml.org 
[lkml]   [2012]   [Aug]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v1 18/22] PCI/acpiphp: use PCI bus lock to avoid race conditions
Date
From: Jiang Liu <liuj97@gmail.com>

This patch uses PCI bus lock mechanism to avoid race conditions when doing
PCI device/host bridge hotplug by acpiphp driver.

Signed-off-by: Jiang Liu <liuj97@gmail.com>
---
drivers/pci/hotplug/acpiphp_glue.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 73af337..0ea7ab1 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -800,11 +800,14 @@ static int __ref enable_device(struct acpiphp_slot *slot)
if (slot->flags & SLOT_ENABLED)
goto err_exit;

+ if (pci_bus_lock_states(bus, PCI_BUS_STATE_WORKING) < 0)
+ return -EINVAL;
+
num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
if (num == 0) {
/* Maybe only part of funcs are added. */
dbg("No new device found\n");
- goto err_exit;
+ goto out_unlock;
}

max = acpiphp_max_busnr(bus);
@@ -862,8 +865,10 @@ static int __ref enable_device(struct acpiphp_slot *slot)
pci_dev_put(dev);
}

+out_unlock:
+ pci_bus_unlock(bus);

- err_exit:
+err_exit:
return retval;
}

@@ -906,6 +911,9 @@ static int disable_device(struct acpiphp_slot *slot)
struct pci_dev *pdev;
struct pci_bus *bus = slot->bridge->pci_bus;

+ if (pci_bus_lock_states(bus, PCI_BUS_STATE_WORKING) < 0)
+ goto err_exit;
+
/* The slot will be enabled when func 0 is added, so check
func 0 before disable the slot. */
pdev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
@@ -943,6 +951,7 @@ static int disable_device(struct acpiphp_slot *slot)
}

slot->flags &= (~SLOT_ENABLED);
+ pci_bus_unlock(bus);

err_exit:
return 0;
--
1.7.9.5


\
 
 \ /
  Last update: 2012-08-07 19:02    [W:0.149 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site