aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>2009-11-25 07:01:28 -0500
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-12-04 18:55:18 -0500
commit52a0f24beabe9e89223e367c65a0156dff17265c (patch)
treed6249304150228dcb15052781cb9f26afae05be4 /drivers/pci
parent898294c97500b1cdff6edce52fd34e024eb070ec (diff)
PCI: portdrv: cleanup pcie_device registration
In the current port bus driver implementation, pcie_device allocation, initialization and registration are done in separated functions. Doing those in one function make the code simple and easier to read. Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/pcie/portdrv_core.c77
1 files changed, 26 insertions, 51 deletions
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index a0376f80bc5e..7ea37c075d7e 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -246,54 +246,39 @@ static int get_port_device_capability(struct pci_dev *dev)
246} 246}
247 247
248/** 248/**
249 * pcie_device_init - initialize PCI Express port service device 249 * pcie_device_init - allocate and initialize PCI Express port service device
250 * @dev: Port service device to initialize 250 * @pdev: PCI Express port to associate the service device with
251 * @parent: PCI Express port to associate the service device with 251 * @service: Type of service to associate with the service device
252 * @port_type: Type of the port
253 * @service_type: Type of service to associate with the service device
254 * @irq: Interrupt vector to associate with the service device 252 * @irq: Interrupt vector to associate with the service device
255 */ 253 */
256static void pcie_device_init(struct pci_dev *parent, struct pcie_device *dev, 254static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
257 int service_type, int irq)
258{ 255{
259 struct pcie_port_data *port_data = pci_get_drvdata(parent); 256 int retval;
257 struct pcie_device *pcie;
260 struct device *device; 258 struct device *device;
261 int port_type = port_data->port_type;
262 259
263 dev->port = parent; 260 pcie = kzalloc(sizeof(*pcie), GFP_KERNEL);
264 dev->irq = irq; 261 if (!pcie)
265 dev->service = service_type; 262 return -ENOMEM;
263 pcie->port = pdev;
264 pcie->irq = irq;
265 pcie->service = service;
266 266
267 /* Initialize generic device interface */ 267 /* Initialize generic device interface */
268 device = &dev->device; 268 device = &pcie->device;
269 memset(device, 0, sizeof(struct device));
270 device->bus = &pcie_port_bus_type; 269 device->bus = &pcie_port_bus_type;
271 device->driver = NULL;
272 dev_set_drvdata(device, NULL);
273 device->release = release_pcie_device; /* callback to free pcie dev */ 270 device->release = release_pcie_device; /* callback to free pcie dev */
274 dev_set_name(device, "%s:pcie%02x", 271 dev_set_name(device, "%s:pcie%02x",
275 pci_name(parent), get_descriptor_id(port_type, service_type)); 272 pci_name(pdev),
276 device->parent = &parent->dev; 273 get_descriptor_id(pdev->pcie_type, service));
277} 274 device->parent = &pdev->dev;
278 275
279/** 276 retval = device_register(device);
280 * alloc_pcie_device - allocate PCI Express port service device structure 277 if (retval)
281 * @parent: PCI Express port to associate the service device with 278 kfree(pcie);
282 * @port_type: Type of the port 279 else
283 * @service_type: Type of service to associate with the service device 280 get_device(device);
284 * @irq: Interrupt vector to associate with the service device 281 return retval;
285 */
286static struct pcie_device* alloc_pcie_device(struct pci_dev *parent,
287 int service_type, int irq)
288{
289 struct pcie_device *device;
290
291 device = kzalloc(sizeof(struct pcie_device), GFP_KERNEL);
292 if (!device)
293 return NULL;
294
295 pcie_device_init(parent, device, service_type, irq);
296 return device;
297} 282}
298 283
299/** 284/**
@@ -346,24 +331,14 @@ int pcie_port_device_register(struct pci_dev *dev)
346 331
347 /* Allocate child services if any */ 332 /* Allocate child services if any */
348 for (i = 0, nr_serv = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) { 333 for (i = 0, nr_serv = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) {
349 struct pcie_device *child;
350 int service = 1 << i; 334 int service = 1 << i;
351 335
352 if (!(capabilities & service)) 336 if (!(capabilities & service))
353 continue; 337 continue;
354 338
355 child = alloc_pcie_device(dev, service, vectors[i]); 339 status = pcie_device_init(dev, service, vectors[i]);
356 if (!child) 340 if (!status)
357 continue; 341 nr_serv++;
358
359 status = device_register(&child->device);
360 if (status) {
361 kfree(child);
362 continue;
363 }
364
365 get_device(&child->device);
366 nr_serv++;
367 } 342 }
368 if (!nr_serv) { 343 if (!nr_serv) {
369 pci_disable_device(dev); 344 pci_disable_device(dev);