diff options
Diffstat (limited to 'drivers/pci/pci-sysfs.c')
-rw-r--r-- | drivers/pci/pci-sysfs.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index f952bfea48a6..7a94076752d0 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c | |||
@@ -42,7 +42,6 @@ pci_config_attr(subsystem_vendor, "0x%04x\n"); | |||
42 | pci_config_attr(subsystem_device, "0x%04x\n"); | 42 | pci_config_attr(subsystem_device, "0x%04x\n"); |
43 | pci_config_attr(class, "0x%06x\n"); | 43 | pci_config_attr(class, "0x%06x\n"); |
44 | pci_config_attr(irq, "%u\n"); | 44 | pci_config_attr(irq, "%u\n"); |
45 | pci_config_attr(is_enabled, "%u\n"); | ||
46 | 45 | ||
47 | static ssize_t broken_parity_status_show(struct device *dev, | 46 | static ssize_t broken_parity_status_show(struct device *dev, |
48 | struct device_attribute *attr, | 47 | struct device_attribute *attr, |
@@ -112,26 +111,36 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | |||
112 | (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), | 111 | (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), |
113 | (u8)(pci_dev->class)); | 112 | (u8)(pci_dev->class)); |
114 | } | 113 | } |
115 | static ssize_t | 114 | |
116 | is_enabled_store(struct device *dev, struct device_attribute *attr, | 115 | static ssize_t is_enabled_store(struct device *dev, |
117 | const char *buf, size_t count) | 116 | struct device_attribute *attr, const char *buf, |
117 | size_t count) | ||
118 | { | 118 | { |
119 | ssize_t result = -EINVAL; | ||
119 | struct pci_dev *pdev = to_pci_dev(dev); | 120 | struct pci_dev *pdev = to_pci_dev(dev); |
120 | int retval = 0; | ||
121 | 121 | ||
122 | /* this can crash the machine when done on the "wrong" device */ | 122 | /* this can crash the machine when done on the "wrong" device */ |
123 | if (!capable(CAP_SYS_ADMIN)) | 123 | if (!capable(CAP_SYS_ADMIN)) |
124 | return count; | 124 | return count; |
125 | 125 | ||
126 | if (*buf == '0') | 126 | if (*buf == '0') { |
127 | pci_disable_device(pdev); | 127 | if (atomic_read(&pdev->enable_cnt) != 0) |
128 | pci_disable_device(pdev); | ||
129 | else | ||
130 | result = -EIO; | ||
131 | } else if (*buf == '1') | ||
132 | result = pci_enable_device(pdev); | ||
133 | |||
134 | return result < 0 ? result : count; | ||
135 | } | ||
128 | 136 | ||
129 | if (*buf == '1') | 137 | static ssize_t is_enabled_show(struct device *dev, |
130 | retval = pci_enable_device(pdev); | 138 | struct device_attribute *attr, char *buf) |
139 | { | ||
140 | struct pci_dev *pdev; | ||
131 | 141 | ||
132 | if (retval) | 142 | pdev = to_pci_dev (dev); |
133 | return retval; | 143 | return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt)); |
134 | return count; | ||
135 | } | 144 | } |
136 | 145 | ||
137 | static ssize_t | 146 | static ssize_t |