Commit 55f8b818e578c819f4aaea7a5f5da58aa98c5e80

Authored by Andy Shevchenko
Committed by Greg Kroah-Hartman
1 parent 990785dcf5

sata_dwc_460ex: fix resource leak on error path

commit 4aaa71873ddb9faf4b0c4826579e2f6d18ff9ab4 upstream.

DMA mapped IO should be unmapped on the error path in probe() and
unconditionally on remove().

Fixes: 62936009f35a ([libata] Add 460EX on-chip SATA driver, sata_dwc_460ex)
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 12 additions and 14 deletions Side-by-side Diff

drivers/ata/sata_dwc_460ex.c
... ... @@ -797,7 +797,7 @@
797 797 if (err) {
798 798 dev_err(host_pvt.dwc_dev, "%s: dma_request_interrupts returns"
799 799 " %d\n", __func__, err);
800   - goto error_out;
  800 + return err;
801 801 }
802 802  
803 803 /* Enabe DMA */
... ... @@ -808,11 +808,6 @@
808 808 sata_dma_regs);
809 809  
810 810 return 0;
811   -
812   -error_out:
813   - dma_dwc_exit(hsdev);
814   -
815   - return err;
816 811 }
817 812  
818 813 static int sata_dwc_scr_read(struct ata_link *link, unsigned int scr, u32 *val)
... ... @@ -1662,7 +1657,7 @@
1662 1657 char *ver = (char *)&versionr;
1663 1658 u8 *base = NULL;
1664 1659 int err = 0;
1665   - int irq, rc;
  1660 + int irq;
1666 1661 struct ata_host *host;
1667 1662 struct ata_port_info pi = sata_dwc_port_info[0];
1668 1663 const struct ata_port_info *ppi[] = { &pi, NULL };
... ... @@ -1725,7 +1720,7 @@
1725 1720 if (irq == NO_IRQ) {
1726 1721 dev_err(&ofdev->dev, "no SATA DMA irq\n");
1727 1722 err = -ENODEV;
1728   - goto error_out;
  1723 + goto error_iomap;
1729 1724 }
1730 1725  
1731 1726 /* Get physical SATA DMA register base address */
1732 1727  
... ... @@ -1734,14 +1729,16 @@
1734 1729 dev_err(&ofdev->dev, "ioremap failed for AHBDMA register"
1735 1730 " address\n");
1736 1731 err = -ENODEV;
1737   - goto error_out;
  1732 + goto error_iomap;
1738 1733 }
1739 1734  
1740 1735 /* Save dev for later use in dev_xxx() routines */
1741 1736 host_pvt.dwc_dev = &ofdev->dev;
1742 1737  
1743 1738 /* Initialize AHB DMAC */
1744   - dma_dwc_init(hsdev, irq);
  1739 + err = dma_dwc_init(hsdev, irq);
  1740 + if (err)
  1741 + goto error_dma_iomap;
1745 1742  
1746 1743 /* Enable SATA Interrupts */
1747 1744 sata_dwc_enable_interrupts(hsdev);
... ... @@ -1759,9 +1756,8 @@
1759 1756 * device discovery process, invoking our port_start() handler &
1760 1757 * error_handler() to execute a dummy Softreset EH session
1761 1758 */
1762   - rc = ata_host_activate(host, irq, sata_dwc_isr, 0, &sata_dwc_sht);
1763   -
1764   - if (rc != 0)
  1759 + err = ata_host_activate(host, irq, sata_dwc_isr, 0, &sata_dwc_sht);
  1760 + if (err)
1765 1761 dev_err(&ofdev->dev, "failed to activate host");
1766 1762  
1767 1763 dev_set_drvdata(&ofdev->dev, host);
... ... @@ -1770,7 +1766,8 @@
1770 1766 error_out:
1771 1767 /* Free SATA DMA resources */
1772 1768 dma_dwc_exit(hsdev);
1773   -
  1769 +error_dma_iomap:
  1770 + iounmap((void __iomem *)host_pvt.sata_dma_regs);
1774 1771 error_iomap:
1775 1772 iounmap(base);
1776 1773 error_kmalloc:
... ... @@ -1791,6 +1788,7 @@
1791 1788 /* Free SATA DMA resources */
1792 1789 dma_dwc_exit(hsdev);
1793 1790  
  1791 + iounmap((void __iomem *)host_pvt.sata_dma_regs);
1794 1792 iounmap(hsdev->reg_base);
1795 1793 kfree(hsdev);
1796 1794 kfree(host);