Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: wss: Allocate resources with device-managed APIs

This patch converts the resource management in ISA wss driver with
devres as a clean up. Each manual resource management is converted
with the corresponding devres helper. Since the whole destructor code
could be removed by the conversion, the lowlevel snd_device was
dropped as well.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-54-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+11 -58
-2
sound/isa/cs423x/cs4236_lib.c
··· 298 298 if (cport < 0x100 || cport == SNDRV_AUTO_PORT) { 299 299 snd_printk(KERN_ERR "please, specify control port " 300 300 "for CS4236+ chips\n"); 301 - snd_device_free(card, chip); 302 301 return -ENODEV; 303 302 } 304 303 ver1 = snd_cs4236_ctrl_in(chip, 1); ··· 307 308 if (ver1 != ver2) { 308 309 snd_printk(KERN_ERR "CS4236+ chip detected, but " 309 310 "control port 0x%lx is not valid\n", cport); 310 - snd_device_free(card, chip); 311 311 return -ENODEV; 312 312 } 313 313 snd_cs4236_ctrl_out(chip, 0, 0x00);
+11 -56
sound/isa/wss/wss_lib.c
··· 1655 1655 } 1656 1656 #endif /* CONFIG_PM */ 1657 1657 1658 - static int snd_wss_free(struct snd_wss *chip) 1659 - { 1660 - release_and_free_resource(chip->res_port); 1661 - release_and_free_resource(chip->res_cport); 1662 - if (chip->irq >= 0) { 1663 - disable_irq(chip->irq); 1664 - if (!(chip->hwshare & WSS_HWSHARE_IRQ)) 1665 - free_irq(chip->irq, (void *) chip); 1666 - } 1667 - if (!(chip->hwshare & WSS_HWSHARE_DMA1) && chip->dma1 >= 0) { 1668 - snd_dma_disable(chip->dma1); 1669 - free_dma(chip->dma1); 1670 - } 1671 - if (!(chip->hwshare & WSS_HWSHARE_DMA2) && 1672 - chip->dma2 >= 0 && chip->dma2 != chip->dma1) { 1673 - snd_dma_disable(chip->dma2); 1674 - free_dma(chip->dma2); 1675 - } 1676 - if (chip->timer) 1677 - snd_device_free(chip->card, chip->timer); 1678 - kfree(chip); 1679 - return 0; 1680 - } 1681 - 1682 - static int snd_wss_dev_free(struct snd_device *device) 1683 - { 1684 - struct snd_wss *chip = device->device_data; 1685 - return snd_wss_free(chip); 1686 - } 1687 - 1688 1658 const char *snd_wss_chip_id(struct snd_wss *chip) 1689 1659 { 1690 1660 switch (chip->hardware) { ··· 1708 1738 struct snd_wss *chip; 1709 1739 1710 1740 *rchip = NULL; 1711 - chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1741 + chip = devm_kzalloc(card->dev, sizeof(*chip), GFP_KERNEL); 1712 1742 if (chip == NULL) 1713 1743 return -ENOMEM; 1714 1744 chip->hardware = hardware; ··· 1744 1774 unsigned short hwshare, 1745 1775 struct snd_wss **rchip) 1746 1776 { 1747 - static const struct snd_device_ops ops = { 1748 - .dev_free = snd_wss_dev_free, 1749 - }; 1750 1777 struct snd_wss *chip; 1751 1778 int err; 1752 1779 ··· 1755 1788 chip->dma1 = -1; 1756 1789 chip->dma2 = -1; 1757 1790 1758 - chip->res_port = request_region(port, 4, "WSS"); 1791 + chip->res_port = devm_request_region(card->dev, port, 4, "WSS"); 1759 1792 if (!chip->res_port) { 1760 1793 snd_printk(KERN_ERR "wss: can't grab port 0x%lx\n", port); 1761 - snd_wss_free(chip); 1762 1794 return -EBUSY; 1763 1795 } 1764 1796 chip->port = port; 1765 1797 if ((long)cport >= 0) { 1766 - chip->res_cport = request_region(cport, 8, "CS4232 Control"); 1798 + chip->res_cport = devm_request_region(card->dev, cport, 8, 1799 + "CS4232 Control"); 1767 1800 if (!chip->res_cport) { 1768 1801 snd_printk(KERN_ERR 1769 1802 "wss: can't grab control port 0x%lx\n", cport); 1770 - snd_wss_free(chip); 1771 1803 return -ENODEV; 1772 1804 } 1773 1805 } 1774 1806 chip->cport = cport; 1775 1807 if (!(hwshare & WSS_HWSHARE_IRQ)) 1776 - if (request_irq(irq, snd_wss_interrupt, 0, 1777 - "WSS", (void *) chip)) { 1808 + if (devm_request_irq(card->dev, irq, snd_wss_interrupt, 0, 1809 + "WSS", (void *) chip)) { 1778 1810 snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq); 1779 - snd_wss_free(chip); 1780 1811 return -EBUSY; 1781 1812 } 1782 1813 chip->irq = irq; 1783 1814 card->sync_irq = chip->irq; 1784 - if (!(hwshare & WSS_HWSHARE_DMA1) && request_dma(dma1, "WSS - 1")) { 1815 + if (!(hwshare & WSS_HWSHARE_DMA1) && 1816 + snd_devm_request_dma(card->dev, dma1, "WSS - 1")) { 1785 1817 snd_printk(KERN_ERR "wss: can't grab DMA1 %d\n", dma1); 1786 - snd_wss_free(chip); 1787 1818 return -EBUSY; 1788 1819 } 1789 1820 chip->dma1 = dma1; 1790 - if (!(hwshare & WSS_HWSHARE_DMA2) && dma1 != dma2 && 1791 - dma2 >= 0 && request_dma(dma2, "WSS - 2")) { 1821 + if (!(hwshare & WSS_HWSHARE_DMA2) && dma1 != dma2 && dma2 >= 0 && 1822 + snd_devm_request_dma(card->dev, dma2, "WSS - 2")) { 1792 1823 snd_printk(KERN_ERR "wss: can't grab DMA2 %d\n", dma2); 1793 - snd_wss_free(chip); 1794 1824 return -EBUSY; 1795 1825 } 1796 1826 if (dma1 == dma2 || dma2 < 0) { ··· 1803 1839 } 1804 1840 1805 1841 /* global setup */ 1806 - if (snd_wss_probe(chip) < 0) { 1807 - snd_wss_free(chip); 1842 + if (snd_wss_probe(chip) < 0) 1808 1843 return -ENODEV; 1809 - } 1810 1844 snd_wss_init(chip); 1811 1845 1812 1846 #if 0 ··· 1814 1852 "not accessible\n"); 1815 1853 } 1816 1854 #endif 1817 - 1818 - /* Register device */ 1819 - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 1820 - if (err < 0) { 1821 - snd_wss_free(chip); 1822 - return err; 1823 - } 1824 1855 1825 1856 #ifdef CONFIG_PM 1826 1857 /* Power Management */