summaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci-sysfs.c
diff options
context:
space:
mode:
authorChristoph Hellwig2018-05-18 18:56:24 +0200
committerBjorn Helgaas2018-05-26 00:28:02 +0200
commit6f5cdfa802733dcb561bf664cc89d203f2fd958f (patch)
treebd0ece32aabf1720cfccbf8197166dd8950c5bf1 /drivers/pci/pci-sysfs.c
parentPCI: Check whether bridges allow access to extended config space (diff)
downloadkernel-qcow2-linux-6f5cdfa802733dcb561bf664cc89d203f2fd958f.tar.gz
kernel-qcow2-linux-6f5cdfa802733dcb561bf664cc89d203f2fd958f.tar.xz
kernel-qcow2-linux-6f5cdfa802733dcb561bf664cc89d203f2fd958f.zip
PCI: Prevent sysfs disable of device while driver is attached
Manipulating the enable_cnt behind the back of the driver will wreak complete havoc with the kernel state, so disallow it. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Acked-by: Keith Busch <keith.busch@intel.com>
Diffstat (limited to 'drivers/pci/pci-sysfs.c')
-rw-r--r--drivers/pci/pci-sysfs.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 366d93af051d..788a200fb2dc 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -288,13 +288,16 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- if (!val) {
- if (pci_is_enabled(pdev))
- pci_disable_device(pdev);
- else
- result = -EIO;
- } else
+ device_lock(dev);
+ if (dev->driver)
+ result = -EBUSY;
+ else if (val)
result = pci_enable_device(pdev);
+ else if (pci_is_enabled(pdev))
+ pci_disable_device(pdev);
+ else
+ result = -EIO;
+ device_unlock(dev);
return result < 0 ? result : count;
}