diff options
| author | Konstantin Khlebnikov <khlebnikov@openvz.org> | 2012-08-08 06:47:51 -0400 |
|---|---|---|
| committer | Bjorn Helgaas <bhelgaas@google.com> | 2012-09-17 14:17:09 -0400 |
| commit | bfb09a86f5f60f9a83c676b53db8d9210549ee19 (patch) | |
| tree | f2a934fcfb6135989ee0cae4ad1bd122bd47fe31 | |
| parent | 55d512e245bc7699a8800e23df1a24195dd08217 (diff) | |
PCI: Convert "new_id"/"remove_id" into generic pci_bus driver attributes
This patch removes hardcoded sysfs attributes manipulation and
converts them into generic pci_bus->drv_attrs. This saves several bytes.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
| -rw-r--r-- | drivers/pci/pci-driver.c | 57 |
1 files changed, 10 insertions, 47 deletions
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index d6fd6b6d9d4b..9e1d2959e226 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
| @@ -139,7 +139,6 @@ store_new_id(struct device_driver *driver, const char *buf, size_t count) | |||
| 139 | return retval; | 139 | return retval; |
| 140 | return count; | 140 | return count; |
| 141 | } | 141 | } |
| 142 | static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); | ||
| 143 | 142 | ||
| 144 | /** | 143 | /** |
| 145 | * store_remove_id - remove a PCI device ID from this driver | 144 | * store_remove_id - remove a PCI device ID from this driver |
| @@ -185,38 +184,16 @@ store_remove_id(struct device_driver *driver, const char *buf, size_t count) | |||
| 185 | return retval; | 184 | return retval; |
| 186 | return count; | 185 | return count; |
| 187 | } | 186 | } |
| 188 | static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id); | ||
| 189 | 187 | ||
| 190 | static int | 188 | static struct driver_attribute pci_drv_attrs[] = { |
| 191 | pci_create_newid_files(struct pci_driver *drv) | 189 | __ATTR(new_id, S_IWUSR, NULL, store_new_id), |
| 192 | { | 190 | __ATTR(remove_id, S_IWUSR, NULL, store_remove_id), |
| 193 | int error = 0; | 191 | __ATTR_NULL, |
| 192 | }; | ||
| 194 | 193 | ||
| 195 | if (drv->probe != NULL) { | 194 | #else |
| 196 | error = driver_create_file(&drv->driver, &driver_attr_new_id); | 195 | #define pci_drv_attrs NULL |
| 197 | if (error == 0) { | 196 | #endif /* CONFIG_HOTPLUG */ |
| 198 | error = driver_create_file(&drv->driver, | ||
| 199 | &driver_attr_remove_id); | ||
| 200 | if (error) | ||
| 201 | driver_remove_file(&drv->driver, | ||
| 202 | &driver_attr_new_id); | ||
| 203 | } | ||
| 204 | } | ||
| 205 | return error; | ||
| 206 | } | ||
| 207 | |||
| 208 | static void pci_remove_newid_files(struct pci_driver *drv) | ||
| 209 | { | ||
| 210 | driver_remove_file(&drv->driver, &driver_attr_remove_id); | ||
| 211 | driver_remove_file(&drv->driver, &driver_attr_new_id); | ||
| 212 | } | ||
| 213 | #else /* !CONFIG_HOTPLUG */ | ||
| 214 | static inline int pci_create_newid_files(struct pci_driver *drv) | ||
| 215 | { | ||
| 216 | return 0; | ||
| 217 | } | ||
| 218 | static inline void pci_remove_newid_files(struct pci_driver *drv) {} | ||
| 219 | #endif | ||
| 220 | 197 | ||
| 221 | /** | 198 | /** |
| 222 | * pci_match_id - See if a pci device matches a given pci_id table | 199 | * pci_match_id - See if a pci device matches a given pci_id table |
| @@ -1162,8 +1139,6 @@ const struct dev_pm_ops pci_dev_pm_ops = { | |||
| 1162 | int __pci_register_driver(struct pci_driver *drv, struct module *owner, | 1139 | int __pci_register_driver(struct pci_driver *drv, struct module *owner, |
| 1163 | const char *mod_name) | 1140 | const char *mod_name) |
| 1164 | { | 1141 | { |
| 1165 | int error; | ||
| 1166 | |||
| 1167 | /* initialize common driver fields */ | 1142 | /* initialize common driver fields */ |
| 1168 | drv->driver.name = drv->name; | 1143 | drv->driver.name = drv->name; |
| 1169 | drv->driver.bus = &pci_bus_type; | 1144 | drv->driver.bus = &pci_bus_type; |
| @@ -1174,19 +1149,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner, | |||
| 1174 | INIT_LIST_HEAD(&drv->dynids.list); | 1149 | INIT_LIST_HEAD(&drv->dynids.list); |
| 1175 | 1150 | ||
| 1176 | /* register with core */ | 1151 | /* register with core */ |
| 1177 | error = driver_register(&drv->driver); | 1152 | return driver_register(&drv->driver); |
| 1178 | if (error) | ||
| 1179 | goto out; | ||
| 1180 | |||
| 1181 | error = pci_create_newid_files(drv); | ||
| 1182 | if (error) | ||
| 1183 | goto out_newid; | ||
| 1184 | out: | ||
| 1185 | return error; | ||
| 1186 | |||
| 1187 | out_newid: | ||
| 1188 | driver_unregister(&drv->driver); | ||
| 1189 | goto out; | ||
| 1190 | } | 1153 | } |
| 1191 | 1154 | ||
| 1192 | /** | 1155 | /** |
| @@ -1202,7 +1165,6 @@ out_newid: | |||
| 1202 | void | 1165 | void |
| 1203 | pci_unregister_driver(struct pci_driver *drv) | 1166 | pci_unregister_driver(struct pci_driver *drv) |
| 1204 | { | 1167 | { |
| 1205 | pci_remove_newid_files(drv); | ||
| 1206 | driver_unregister(&drv->driver); | 1168 | driver_unregister(&drv->driver); |
| 1207 | pci_free_dynids(drv); | 1169 | pci_free_dynids(drv); |
| 1208 | } | 1170 | } |
| @@ -1302,6 +1264,7 @@ struct bus_type pci_bus_type = { | |||
| 1302 | .shutdown = pci_device_shutdown, | 1264 | .shutdown = pci_device_shutdown, |
| 1303 | .dev_attrs = pci_dev_attrs, | 1265 | .dev_attrs = pci_dev_attrs, |
| 1304 | .bus_attrs = pci_bus_attrs, | 1266 | .bus_attrs = pci_bus_attrs, |
| 1267 | .drv_attrs = pci_drv_attrs, | ||
| 1305 | .pm = PCI_PM_OPS_PTR, | 1268 | .pm = PCI_PM_OPS_PTR, |
| 1306 | }; | 1269 | }; |
| 1307 | 1270 | ||
