Commit 83beee5c authored by Kuppuswamy Sathyanarayanan's avatar Kuppuswamy Sathyanarayanan Committed by Andy Shevchenko

platform/x86: intel_pmc_ipc: Use devm_* calls in driver probe function

This patch cleans up unnecessary free/alloc calls in ipc_plat_probe(),
ipc_pci_probe() and ipc_plat_get_res() functions by using devm_*
calls.

This patch also adds proper error handling for failure cases in
ipc_pci_probe() function.
Signed-off-by: default avatarKuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
[andy: fixed style issues, missed devm_free_irq(), removed unnecessary log message]
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
parent ce7c47d6
...@@ -480,52 +480,39 @@ static irqreturn_t ioc(int irq, void *dev_id) ...@@ -480,52 +480,39 @@ static irqreturn_t ioc(int irq, void *dev_id)
static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{ {
resource_size_t pci_resource; struct intel_pmc_ipc_dev *pmc = &ipcdev;
int ret; int ret;
int len;
ipcdev.dev = &pci_dev_get(pdev)->dev; /* Only one PMC is supported */
ipcdev.irq_mode = IPC_TRIGGER_MODE_IRQ; if (pmc->dev)
return -EBUSY;
ret = pci_enable_device(pdev); pmc->irq_mode = IPC_TRIGGER_MODE_IRQ;
ret = pcim_enable_device(pdev);
if (ret) if (ret)
return ret; return ret;
ret = pci_request_regions(pdev, "intel_pmc_ipc"); ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
if (ret) if (ret)
return ret; return ret;
pci_resource = pci_resource_start(pdev, 0); init_completion(&pmc->cmd_complete);
len = pci_resource_len(pdev, 0);
if (!pci_resource || !len) {
dev_err(&pdev->dev, "Failed to get resource\n");
return -ENOMEM;
}
init_completion(&ipcdev.cmd_complete); pmc->ipc_base = pcim_iomap_table(pdev)[0];
if (request_irq(pdev->irq, ioc, 0, "intel_pmc_ipc", &ipcdev)) { ret = devm_request_irq(&pdev->dev, pdev->irq, ioc, 0, "intel_pmc_ipc",
pmc);
if (ret) {
dev_err(&pdev->dev, "Failed to request irq\n"); dev_err(&pdev->dev, "Failed to request irq\n");
return -EBUSY; return ret;
} }
ipcdev.ipc_base = ioremap_nocache(pci_resource, len); pmc->dev = &pdev->dev;
if (!ipcdev.ipc_base) {
dev_err(&pdev->dev, "Failed to ioremap ipc base\n");
free_irq(pdev->irq, &ipcdev);
ret = -ENOMEM;
}
return ret; pci_set_drvdata(pdev, pmc);
}
static void ipc_pci_remove(struct pci_dev *pdev) return 0;
{
free_irq(pdev->irq, &ipcdev);
pci_release_regions(pdev);
pci_dev_put(pdev);
iounmap(ipcdev.ipc_base);
ipcdev.dev = NULL;
} }
static const struct pci_device_id ipc_pci_ids[] = { static const struct pci_device_id ipc_pci_ids[] = {
...@@ -540,7 +527,6 @@ static struct pci_driver ipc_pci_driver = { ...@@ -540,7 +527,6 @@ static struct pci_driver ipc_pci_driver = {
.name = "intel_pmc_ipc", .name = "intel_pmc_ipc",
.id_table = ipc_pci_ids, .id_table = ipc_pci_ids,
.probe = ipc_pci_probe, .probe = ipc_pci_probe,
.remove = ipc_pci_remove,
}; };
static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev, static ssize_t intel_pmc_ipc_simple_cmd_store(struct device *dev,
...@@ -850,17 +836,12 @@ static int ipc_plat_get_res(struct platform_device *pdev) ...@@ -850,17 +836,12 @@ static int ipc_plat_get_res(struct platform_device *pdev)
return -ENXIO; return -ENXIO;
} }
size = PLAT_RESOURCE_IPC_SIZE + PLAT_RESOURCE_GCR_SIZE; size = PLAT_RESOURCE_IPC_SIZE + PLAT_RESOURCE_GCR_SIZE;
res->end = res->start + size - 1;
addr = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(addr))
return PTR_ERR(addr);
if (!request_mem_region(res->start, size, pdev->name)) {
dev_err(&pdev->dev, "Failed to request ipc resource\n");
return -EBUSY;
}
addr = ioremap_nocache(res->start, size);
if (!addr) {
dev_err(&pdev->dev, "I/O memory remapping failed\n");
release_mem_region(res->start, size);
return -ENOMEM;
}
ipcdev.ipc_base = addr; ipcdev.ipc_base = addr;
ipcdev.gcr_mem_base = addr + PLAT_RESOURCE_GCR_OFFSET; ipcdev.gcr_mem_base = addr + PLAT_RESOURCE_GCR_OFFSET;
...@@ -917,7 +898,6 @@ MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids); ...@@ -917,7 +898,6 @@ MODULE_DEVICE_TABLE(acpi, ipc_acpi_ids);
static int ipc_plat_probe(struct platform_device *pdev) static int ipc_plat_probe(struct platform_device *pdev)
{ {
struct resource *res;
int ret; int ret;
ipcdev.dev = &pdev->dev; ipcdev.dev = &pdev->dev;
...@@ -939,10 +919,10 @@ static int ipc_plat_probe(struct platform_device *pdev) ...@@ -939,10 +919,10 @@ static int ipc_plat_probe(struct platform_device *pdev)
ret = ipc_create_pmc_devices(); ret = ipc_create_pmc_devices();
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to create pmc devices\n"); dev_err(&pdev->dev, "Failed to create pmc devices\n");
goto err_device; return ret;
} }
if (request_irq(ipcdev.irq, ioc, IRQF_NO_SUSPEND, if (devm_request_irq(&pdev->dev, ipcdev.irq, ioc, IRQF_NO_SUSPEND,
"intel_pmc_ipc", &ipcdev)) { "intel_pmc_ipc", &ipcdev)) {
dev_err(&pdev->dev, "Failed to request irq\n"); dev_err(&pdev->dev, "Failed to request irq\n");
ret = -EBUSY; ret = -EBUSY;
...@@ -960,40 +940,22 @@ static int ipc_plat_probe(struct platform_device *pdev) ...@@ -960,40 +940,22 @@ static int ipc_plat_probe(struct platform_device *pdev)
return 0; return 0;
err_sys: err_sys:
free_irq(ipcdev.irq, &ipcdev); devm_free_irq(&pdev->dev, ipcdev.irq, &ipcdev);
err_irq: err_irq:
platform_device_unregister(ipcdev.tco_dev); platform_device_unregister(ipcdev.tco_dev);
platform_device_unregister(ipcdev.punit_dev); platform_device_unregister(ipcdev.punit_dev);
platform_device_unregister(ipcdev.telemetry_dev); platform_device_unregister(ipcdev.telemetry_dev);
err_device:
iounmap(ipcdev.ipc_base);
res = platform_get_resource(pdev, IORESOURCE_MEM,
PLAT_RESOURCE_IPC_INDEX);
if (res) {
release_mem_region(res->start,
PLAT_RESOURCE_IPC_SIZE +
PLAT_RESOURCE_GCR_SIZE);
}
return ret; return ret;
} }
static int ipc_plat_remove(struct platform_device *pdev) static int ipc_plat_remove(struct platform_device *pdev)
{ {
struct resource *res;
sysfs_remove_group(&pdev->dev.kobj, &intel_ipc_group); sysfs_remove_group(&pdev->dev.kobj, &intel_ipc_group);
free_irq(ipcdev.irq, &ipcdev); devm_free_irq(&pdev->dev, ipcdev.irq, &ipcdev);
platform_device_unregister(ipcdev.tco_dev); platform_device_unregister(ipcdev.tco_dev);
platform_device_unregister(ipcdev.punit_dev); platform_device_unregister(ipcdev.punit_dev);
platform_device_unregister(ipcdev.telemetry_dev); platform_device_unregister(ipcdev.telemetry_dev);
iounmap(ipcdev.ipc_base);
res = platform_get_resource(pdev, IORESOURCE_MEM,
PLAT_RESOURCE_IPC_INDEX);
if (res) {
release_mem_region(res->start,
PLAT_RESOURCE_IPC_SIZE +
PLAT_RESOURCE_GCR_SIZE);
}
ipcdev.dev = NULL; ipcdev.dev = NULL;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment