Commit f5b33d94 authored by Andy Shevchenko's avatar Andy Shevchenko

platform/x86: intel_ips: Simplify error handling via devres API

Use devm_ and pcim_ functions to make error handling
simpler and code smaller and tidier.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
parent 687d25a2
...@@ -296,7 +296,7 @@ static struct ips_mcp_limits ips_ulv_limits = { ...@@ -296,7 +296,7 @@ static struct ips_mcp_limits ips_ulv_limits = {
struct ips_driver { struct ips_driver {
struct pci_dev *dev; struct pci_dev *dev;
void *regmap; void __iomem *regmap;
struct task_struct *monitor; struct task_struct *monitor;
struct task_struct *adjust; struct task_struct *adjust;
struct dentry *debug_root; struct dentry *debug_root;
...@@ -1517,62 +1517,45 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) ...@@ -1517,62 +1517,45 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
if (dmi_check_system(ips_blacklist)) if (dmi_check_system(ips_blacklist))
return -ENODEV; return -ENODEV;
ips = kzalloc(sizeof(struct ips_driver), GFP_KERNEL); ips = devm_kzalloc(&dev->dev, sizeof(*ips), GFP_KERNEL);
if (!ips) if (!ips)
return -ENOMEM; return -ENOMEM;
pci_set_drvdata(dev, ips); spin_lock_init(&ips->turbo_status_lock);
ips->dev = dev; ips->dev = dev;
ips->limits = ips_detect_cpu(ips); ips->limits = ips_detect_cpu(ips);
if (!ips->limits) { if (!ips->limits) {
dev_info(&dev->dev, "IPS not supported on this CPU\n"); dev_info(&dev->dev, "IPS not supported on this CPU\n");
ret = -ENXIO; return -ENXIO;
goto error_free;
} }
spin_lock_init(&ips->turbo_status_lock); ret = pcim_enable_device(dev);
ret = pci_enable_device(dev);
if (ret) { if (ret) {
dev_err(&dev->dev, "can't enable PCI device, aborting\n"); dev_err(&dev->dev, "can't enable PCI device, aborting\n");
goto error_free; return ret;
}
if (!pci_resource_start(dev, 0)) {
dev_err(&dev->dev, "TBAR not assigned, aborting\n");
ret = -ENXIO;
goto error_free;
} }
ret = pci_request_regions(dev, "ips thermal sensor"); ret = pcim_iomap_regions(dev, 1 << 0, pci_name(dev));
if (ret) { if (ret) {
dev_err(&dev->dev, "thermal resource busy, aborting\n");
goto error_free;
}
ips->regmap = ioremap(pci_resource_start(dev, 0),
pci_resource_len(dev, 0));
if (!ips->regmap) {
dev_err(&dev->dev, "failed to map thermal regs, aborting\n"); dev_err(&dev->dev, "failed to map thermal regs, aborting\n");
ret = -EBUSY; return ret;
goto error_release;
} }
ips->regmap = pcim_iomap_table(dev)[0];
pci_set_drvdata(dev, ips);
tse = thm_readb(THM_TSE); tse = thm_readb(THM_TSE);
if (tse != TSE_EN) { if (tse != TSE_EN) {
dev_err(&dev->dev, "thermal device not enabled (0x%02x), aborting\n", tse); dev_err(&dev->dev, "thermal device not enabled (0x%02x), aborting\n", tse);
ret = -ENXIO; return -ENXIO;
goto error_unmap;
} }
trc = thm_readw(THM_TRC); trc = thm_readw(THM_TRC);
trc_required_mask = TRC_CORE1_EN | TRC_CORE_PWR | TRC_MCH_EN; trc_required_mask = TRC_CORE1_EN | TRC_CORE_PWR | TRC_MCH_EN;
if ((trc & trc_required_mask) != trc_required_mask) { if ((trc & trc_required_mask) != trc_required_mask) {
dev_err(&dev->dev, "thermal reporting for required devices not enabled, aborting\n"); dev_err(&dev->dev, "thermal reporting for required devices not enabled, aborting\n");
ret = -ENXIO; return -ENXIO;
goto error_unmap;
} }
if (trc & TRC_CORE2_EN) if (trc & TRC_CORE2_EN)
...@@ -1602,8 +1585,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) ...@@ -1602,8 +1585,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
rdmsrl(PLATFORM_INFO, platform_info); rdmsrl(PLATFORM_INFO, platform_info);
if (!(platform_info & PLATFORM_TDP)) { if (!(platform_info & PLATFORM_TDP)) {
dev_err(&dev->dev, "platform indicates TDP override unavailable, aborting\n"); dev_err(&dev->dev, "platform indicates TDP override unavailable, aborting\n");
ret = -ENODEV; return -ENODEV;
goto error_unmap;
} }
/* /*
...@@ -1615,7 +1597,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) ...@@ -1615,7 +1597,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
ips); ips);
if (ret) { if (ret) {
dev_err(&dev->dev, "request irq failed, aborting\n"); dev_err(&dev->dev, "request irq failed, aborting\n");
goto error_unmap; return ret;
} }
/* Enable aux, hot & critical interrupts */ /* Enable aux, hot & critical interrupts */
...@@ -1673,12 +1655,6 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) ...@@ -1673,12 +1655,6 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
kthread_stop(ips->adjust); kthread_stop(ips->adjust);
error_free_irq: error_free_irq:
free_irq(ips->dev->irq, ips); free_irq(ips->dev->irq, ips);
error_unmap:
iounmap(ips->regmap);
error_release:
pci_release_regions(dev);
error_free:
kfree(ips);
return ret; return ret;
} }
...@@ -1714,22 +1690,14 @@ static void ips_remove(struct pci_dev *dev) ...@@ -1714,22 +1690,14 @@ static void ips_remove(struct pci_dev *dev)
kthread_stop(ips->adjust); kthread_stop(ips->adjust);
if (ips->monitor) if (ips->monitor)
kthread_stop(ips->monitor); kthread_stop(ips->monitor);
iounmap(ips->regmap);
pci_release_regions(dev);
kfree(ips);
dev_dbg(&dev->dev, "IPS driver removed\n"); dev_dbg(&dev->dev, "IPS driver removed\n");
} }
static void ips_shutdown(struct pci_dev *dev)
{
}
static struct pci_driver ips_pci_driver = { static struct pci_driver ips_pci_driver = {
.name = "intel ips", .name = "intel ips",
.id_table = ips_id_table, .id_table = ips_id_table,
.probe = ips_probe, .probe = ips_probe,
.remove = ips_remove, .remove = ips_remove,
.shutdown = ips_shutdown,
}; };
module_pci_driver(ips_pci_driver); module_pci_driver(ips_pci_driver);
......
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