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>
This commit is contained in:
parent
898294c975
commit
52a0f24bea
|
@ -246,54 +246,39 @@ static int get_port_device_capability(struct pci_dev *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pcie_device_init - initialize PCI Express port service device
|
* pcie_device_init - allocate and initialize PCI Express port service device
|
||||||
* @dev: Port service device to initialize
|
* @pdev: PCI Express port to associate the service device with
|
||||||
* @parent: PCI Express port to associate the service device with
|
* @service: Type of service to associate with the service device
|
||||||
* @port_type: Type of the port
|
|
||||||
* @service_type: Type of service to associate with the service device
|
|
||||||
* @irq: Interrupt vector to associate with the service device
|
* @irq: Interrupt vector to associate with the service device
|
||||||
*/
|
*/
|
||||||
static void pcie_device_init(struct pci_dev *parent, struct pcie_device *dev,
|
static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
|
||||||
int service_type, int irq)
|
|
||||||
{
|
{
|
||||||
struct pcie_port_data *port_data = pci_get_drvdata(parent);
|
int retval;
|
||||||
|
struct pcie_device *pcie;
|
||||||
struct device *device;
|
struct device *device;
|
||||||
int port_type = port_data->port_type;
|
|
||||||
|
|
||||||
dev->port = parent;
|
pcie = kzalloc(sizeof(*pcie), GFP_KERNEL);
|
||||||
dev->irq = irq;
|
if (!pcie)
|
||||||
dev->service = service_type;
|
return -ENOMEM;
|
||||||
|
pcie->port = pdev;
|
||||||
|
pcie->irq = irq;
|
||||||
|
pcie->service = service;
|
||||||
|
|
||||||
/* Initialize generic device interface */
|
/* Initialize generic device interface */
|
||||||
device = &dev->device;
|
device = &pcie->device;
|
||||||
memset(device, 0, sizeof(struct device));
|
|
||||||
device->bus = &pcie_port_bus_type;
|
device->bus = &pcie_port_bus_type;
|
||||||
device->driver = NULL;
|
|
||||||
dev_set_drvdata(device, NULL);
|
|
||||||
device->release = release_pcie_device; /* callback to free pcie dev */
|
device->release = release_pcie_device; /* callback to free pcie dev */
|
||||||
dev_set_name(device, "%s:pcie%02x",
|
dev_set_name(device, "%s:pcie%02x",
|
||||||
pci_name(parent), get_descriptor_id(port_type, service_type));
|
pci_name(pdev),
|
||||||
device->parent = &parent->dev;
|
get_descriptor_id(pdev->pcie_type, service));
|
||||||
}
|
device->parent = &pdev->dev;
|
||||||
|
|
||||||
/**
|
retval = device_register(device);
|
||||||
* alloc_pcie_device - allocate PCI Express port service device structure
|
if (retval)
|
||||||
* @parent: PCI Express port to associate the service device with
|
kfree(pcie);
|
||||||
* @port_type: Type of the port
|
else
|
||||||
* @service_type: Type of service to associate with the service device
|
get_device(device);
|
||||||
* @irq: Interrupt vector to associate with the service device
|
return retval;
|
||||||
*/
|
|
||||||
static struct pcie_device* alloc_pcie_device(struct pci_dev *parent,
|
|
||||||
int service_type, int irq)
|
|
||||||
{
|
|
||||||
struct pcie_device *device;
|
|
||||||
|
|
||||||
device = kzalloc(sizeof(struct pcie_device), GFP_KERNEL);
|
|
||||||
if (!device)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
pcie_device_init(parent, device, service_type, irq);
|
|
||||||
return device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -346,23 +331,13 @@ int pcie_port_device_register(struct pci_dev *dev)
|
||||||
|
|
||||||
/* Allocate child services if any */
|
/* Allocate child services if any */
|
||||||
for (i = 0, nr_serv = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) {
|
for (i = 0, nr_serv = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) {
|
||||||
struct pcie_device *child;
|
|
||||||
int service = 1 << i;
|
int service = 1 << i;
|
||||||
|
|
||||||
if (!(capabilities & service))
|
if (!(capabilities & service))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
child = alloc_pcie_device(dev, service, vectors[i]);
|
status = pcie_device_init(dev, service, vectors[i]);
|
||||||
if (!child)
|
if (!status)
|
||||||
continue;
|
|
||||||
|
|
||||||
status = device_register(&child->device);
|
|
||||||
if (status) {
|
|
||||||
kfree(child);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_device(&child->device);
|
|
||||||
nr_serv++;
|
nr_serv++;
|
||||||
}
|
}
|
||||||
if (!nr_serv) {
|
if (!nr_serv) {
|
||||||
|
|
Loading…
Reference in New Issue