diff mbox

PCI: Prevent users from disabling devices in use

Message ID 20180518165953.30848-1-keith.busch@intel.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Keith Busch May 18, 2018, 4:59 p.m. UTC
This patch returns busy status if a user tried to alter the enabled
status of a device owned by a driver. There is no good reason to provide
a convenient method to a user for altering the fundamental state of a
pci device out from under a driver using it.

Signed-off-by: Keith Busch <keith.busch@intel.com>
---
 drivers/pci/pci-sysfs.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox

Patch

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 366d93af051d..7ff3a3dce641 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -287,6 +287,8 @@  static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
 	/* this can crash the machine when done on the "wrong" device */
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
+	if (pdev->driver)
+		return -EBUSY;
 
 	if (!val) {
 		if (pci_is_enabled(pdev))