[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1228140490-32199-1-git-send-email-xyzzy@speakeasy.org>
Date: Mon, 1 Dec 2008 06:08:09 -0800
From: Trent Piepho <xyzzy@...akeasy.org>
To: linux-kernel@...r.kernel.org
Cc: linux-pci <linux-pci@...r.kernel.org>,
Matthew Wilcox <matthew@....cx>, Alex Chiang <achiang@...com>,
Trent Piepho <xyzzy@...akeasy.org>
Subject: [PATCH] PCI: Method for removing PCI devices
This patch adds an attribute named "remove" to a PCI device's sysfs
directory. Writing a non-zero value to this attribute will remove the PCI
device and any children of it.
---
drivers/pci/pci-sysfs.c | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 9a5bdc0..fe0f6a9 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -217,6 +217,31 @@ msi_bus_store(struct device *dev, struct device_attribute *attr,
return count;
}
+static void remove_callback(void *data)
+{
+ pci_remove_bus_device((struct pci_dev *)data);
+}
+
+static ssize_t
+remove_store(struct device *dev, struct device_attribute *dummy,
+ const char *buf, size_t count)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ unsigned long val;
+
+ if (strict_strtoul(buf, 0, &val) < 0)
+ return -EINVAL;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ if (val)
+ sysfs_schedule_callback(&dev->kobj, remove_callback, pdev,
+ THIS_MODULE);
+
+ return count;
+}
+
struct device_attribute pci_dev_attrs[] = {
__ATTR_RO(resource),
__ATTR_RO(vendor),
@@ -235,6 +260,7 @@ struct device_attribute pci_dev_attrs[] = {
__ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
broken_parity_status_show,broken_parity_status_store),
__ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
+ __ATTR(remove, S_IWUSR, NULL, remove_store),
__ATTR_NULL,
};
--
1.5.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists