Commit 946a7773 authored by Hong Liu's avatar Hong Liu Committed by Jiri Kosina

HID: intel-ish-hid: use resource-managed api

Use resource-managed api to simplify error handling in probe and
driver remove logic.

With this patch, we can save ~170 bytes code size in intel-ish-ipc.ko.
before:
   text	   data	    bss	    dec	    hex	filename
  11495	   1568	     72	  13135	   334f	intel-ish-ipc.ko
after:
   text    data     bss     dec     hex filename
  11327    1568      72   12967    32a7 intel-ish-ipc.ko
Signed-off-by: default avatarHong Liu <hong.liu@intel.com>
Acked-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 18c0b546
...@@ -114,18 +114,19 @@ static const struct pci_device_id ish_invalid_pci_ids[] = { ...@@ -114,18 +114,19 @@ static const struct pci_device_id ish_invalid_pci_ids[] = {
*/ */
static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent) static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
{ {
struct ishtp_device *dev; int ret;
struct ish_hw *hw; struct ish_hw *hw;
int ret; struct ishtp_device *ishtp;
struct device *dev = &pdev->dev;
/* Check for invalid platforms for ISH support */ /* Check for invalid platforms for ISH support */
if (pci_dev_present(ish_invalid_pci_ids)) if (pci_dev_present(ish_invalid_pci_ids))
return -ENODEV; return -ENODEV;
/* enable pci dev */ /* enable pci dev */
ret = pci_enable_device(pdev); ret = pcim_enable_device(pdev);
if (ret) { if (ret) {
dev_err(&pdev->dev, "ISH: Failed to enable PCI device\n"); dev_err(dev, "ISH: Failed to enable PCI device\n");
return ret; return ret;
} }
...@@ -133,65 +134,44 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -133,65 +134,44 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
pci_set_master(pdev); pci_set_master(pdev);
/* pci request regions for ISH driver */ /* pci request regions for ISH driver */
ret = pci_request_regions(pdev, KBUILD_MODNAME); ret = pcim_iomap_regions(pdev, 1 << 0, KBUILD_MODNAME);
if (ret) { if (ret) {
dev_err(&pdev->dev, "ISH: Failed to get PCI regions\n"); dev_err(dev, "ISH: Failed to get PCI regions\n");
goto disable_device; return ret;
} }
/* allocates and initializes the ISH dev structure */ /* allocates and initializes the ISH dev structure */
dev = ish_dev_init(pdev); ishtp = ish_dev_init(pdev);
if (!dev) { if (!ishtp) {
ret = -ENOMEM; ret = -ENOMEM;
goto release_regions; return ret;
} }
hw = to_ish_hw(dev); hw = to_ish_hw(ishtp);
dev->print_log = ish_event_tracer; ishtp->print_log = ish_event_tracer;
/* mapping IO device memory */ /* mapping IO device memory */
hw->mem_addr = pci_iomap(pdev, 0, 0); hw->mem_addr = pcim_iomap_table(pdev)[0];
if (!hw->mem_addr) { ishtp->pdev = pdev;
dev_err(&pdev->dev, "ISH: mapping I/O range failure\n");
ret = -ENOMEM;
goto free_device;
}
dev->pdev = pdev;
pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3; pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
/* request and enable interrupt */ /* request and enable interrupt */
ret = request_irq(pdev->irq, ish_irq_handler, IRQF_SHARED, ret = devm_request_irq(dev, pdev->irq, ish_irq_handler,
KBUILD_MODNAME, dev); IRQF_SHARED, KBUILD_MODNAME, ishtp);
if (ret) { if (ret) {
dev_err(&pdev->dev, "ISH: request IRQ failure (%d)\n", dev_err(dev, "ISH: request IRQ %d failed\n", pdev->irq);
pdev->irq); return ret;
goto free_device;
} }
dev_set_drvdata(dev->devc, dev); dev_set_drvdata(ishtp->devc, ishtp);
init_waitqueue_head(&dev->suspend_wait); init_waitqueue_head(&ishtp->suspend_wait);
init_waitqueue_head(&dev->resume_wait); init_waitqueue_head(&ishtp->resume_wait);
ret = ish_init(dev); ret = ish_init(ishtp);
if (ret) if (ret)
goto free_irq; return ret;
return 0; return 0;
free_irq:
free_irq(pdev->irq, dev);
free_device:
pci_iounmap(pdev, hw->mem_addr);
release_regions:
pci_release_regions(pdev);
disable_device:
pci_clear_master(pdev);
pci_disable_device(pdev);
dev_err(&pdev->dev, "ISH: PCI driver initialization failed.\n");
return ret;
} }
/** /**
...@@ -203,16 +183,9 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -203,16 +183,9 @@ static int ish_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
static void ish_remove(struct pci_dev *pdev) static void ish_remove(struct pci_dev *pdev)
{ {
struct ishtp_device *ishtp_dev = pci_get_drvdata(pdev); struct ishtp_device *ishtp_dev = pci_get_drvdata(pdev);
struct ish_hw *hw = to_ish_hw(ishtp_dev);
ishtp_bus_remove_all_clients(ishtp_dev, false); ishtp_bus_remove_all_clients(ishtp_dev, false);
ish_device_disable(ishtp_dev); ish_device_disable(ishtp_dev);
free_irq(pdev->irq, ishtp_dev);
pci_iounmap(pdev, hw->mem_addr);
pci_release_regions(pdev);
pci_clear_master(pdev);
pci_disable_device(pdev);
} }
static struct device __maybe_unused *ish_resume_device; static struct device __maybe_unused *ish_resume_device;
......
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