Commit 5eab6cb0 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: sb: Allocate resources with device-managed APIs

This patch converts the resource management in ISA sb drivers with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper, and the card object release is
managed now via card->private_free instead of a lowlevel snd_device.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-55-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ea2bfa29
...@@ -56,9 +56,6 @@ struct snd_emu8000 { ...@@ -56,9 +56,6 @@ struct snd_emu8000 {
unsigned long port1; /* Port usually base+0 */ unsigned long port1; /* Port usually base+0 */
unsigned long port2; /* Port usually at base+0x400 */ unsigned long port2; /* Port usually at base+0x400 */
unsigned long port3; /* Port usually at base+0x800 */ unsigned long port3; /* Port usually at base+0x800 */
struct resource *res_port1;
struct resource *res_port2;
struct resource *res_port3;
unsigned short last_reg;/* Last register command */ unsigned short last_reg;/* Last register command */
spinlock_t reg_lock; spinlock_t reg_lock;
......
...@@ -1048,27 +1048,6 @@ snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu) ...@@ -1048,27 +1048,6 @@ snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu)
return err; return err;
} }
/*
* free resources
*/
static int snd_emu8000_free(struct snd_emu8000 *hw)
{
release_and_free_resource(hw->res_port1);
release_and_free_resource(hw->res_port2);
release_and_free_resource(hw->res_port3);
kfree(hw);
return 0;
}
/*
*/
static int snd_emu8000_dev_free(struct snd_device *device)
{
struct snd_emu8000 *hw = device->device_data;
return snd_emu8000_free(hw);
}
/* /*
* initialize and register emu8000 synth device. * initialize and register emu8000 synth device.
*/ */
...@@ -1079,9 +1058,6 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, ...@@ -1079,9 +1058,6 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports,
struct snd_seq_device *awe; struct snd_seq_device *awe;
struct snd_emu8000 *hw; struct snd_emu8000 *hw;
int err; int err;
static const struct snd_device_ops ops = {
.dev_free = snd_emu8000_dev_free,
};
if (awe_ret) if (awe_ret)
*awe_ret = NULL; *awe_ret = NULL;
...@@ -1089,7 +1065,7 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, ...@@ -1089,7 +1065,7 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports,
if (seq_ports <= 0) if (seq_ports <= 0)
return 0; return 0;
hw = kzalloc(sizeof(*hw), GFP_KERNEL); hw = devm_kzalloc(card->dev, sizeof(*hw), GFP_KERNEL);
if (hw == NULL) if (hw == NULL)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&hw->reg_lock); spin_lock_init(&hw->reg_lock);
...@@ -1097,12 +1073,10 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, ...@@ -1097,12 +1073,10 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports,
hw->port1 = port; hw->port1 = port;
hw->port2 = port + 0x400; hw->port2 = port + 0x400;
hw->port3 = port + 0x800; hw->port3 = port + 0x800;
hw->res_port1 = request_region(hw->port1, 4, "Emu8000-1"); if (!devm_request_region(card->dev, hw->port1, 4, "Emu8000-1") ||
hw->res_port2 = request_region(hw->port2, 4, "Emu8000-2"); !devm_request_region(card->dev, hw->port2, 4, "Emu8000-2") ||
hw->res_port3 = request_region(hw->port3, 4, "Emu8000-3"); !devm_request_region(card->dev, hw->port3, 4, "Emu8000-3")) {
if (!hw->res_port1 || !hw->res_port2 || !hw->res_port3) {
snd_printk(KERN_ERR "sbawe: can't grab ports 0x%lx, 0x%lx, 0x%lx\n", hw->port1, hw->port2, hw->port3); snd_printk(KERN_ERR "sbawe: can't grab ports 0x%lx, 0x%lx, 0x%lx\n", hw->port1, hw->port2, hw->port3);
snd_emu8000_free(hw);
return -EBUSY; return -EBUSY;
} }
hw->mem_size = 0; hw->mem_size = 0;
...@@ -1115,23 +1089,13 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports, ...@@ -1115,23 +1089,13 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports,
hw->fm_chorus_depth = 0; hw->fm_chorus_depth = 0;
hw->fm_reverb_depth = 0; hw->fm_reverb_depth = 0;
if (snd_emu8000_detect(hw) < 0) { if (snd_emu8000_detect(hw) < 0)
snd_emu8000_free(hw);
return -ENODEV; return -ENODEV;
}
snd_emu8000_init_hw(hw); snd_emu8000_init_hw(hw);
err = snd_emu8000_create_mixer(card, hw); err = snd_emu8000_create_mixer(card, hw);
if (err < 0) { if (err < 0)
snd_emu8000_free(hw);
return err;
}
err = snd_device_new(card, SNDRV_DEV_CODEC, hw, &ops);
if (err < 0) {
snd_emu8000_free(hw);
return err; return err;
}
#if IS_ENABLED(CONFIG_SND_SEQUENCER) #if IS_ENABLED(CONFIG_SND_SEQUENCER)
if (snd_seq_device_new(card, index, SNDRV_SEQ_DEV_ID_EMU8000, if (snd_seq_device_new(card, index, SNDRV_SEQ_DEV_ID_EMU8000,
sizeof(struct snd_emu8000*), &awe) >= 0) { sizeof(struct snd_emu8000*), &awe) >= 0) {
......
...@@ -226,7 +226,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -226,7 +226,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
static const int possible_dmas16[] = {5, 7, -1}; static const int possible_dmas16[] = {5, 7, -1};
int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq; int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq;
err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_card_jazz16), &card); sizeof(struct snd_card_jazz16), &card);
if (err < 0) if (err < 0)
return err; return err;
...@@ -238,8 +238,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -238,8 +238,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
xirq = snd_legacy_find_free_irq(possible_irqs); xirq = snd_legacy_find_free_irq(possible_irqs);
if (xirq < 0) { if (xirq < 0) {
snd_printk(KERN_ERR "unable to find a free IRQ\n"); snd_printk(KERN_ERR "unable to find a free IRQ\n");
err = -EBUSY; return -EBUSY;
goto err_free;
} }
} }
xdma8 = dma8[dev]; xdma8 = dma8[dev];
...@@ -247,8 +246,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -247,8 +246,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
xdma8 = snd_legacy_find_free_dma(possible_dmas8); xdma8 = snd_legacy_find_free_dma(possible_dmas8);
if (xdma8 < 0) { if (xdma8 < 0) {
snd_printk(KERN_ERR "unable to find a free DMA8\n"); snd_printk(KERN_ERR "unable to find a free DMA8\n");
err = -EBUSY; return -EBUSY;
goto err_free;
} }
} }
xdma16 = dma16[dev]; xdma16 = dma16[dev];
...@@ -256,8 +254,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -256,8 +254,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
xdma16 = snd_legacy_find_free_dma(possible_dmas16); xdma16 = snd_legacy_find_free_dma(possible_dmas16);
if (xdma16 < 0) { if (xdma16 < 0) {
snd_printk(KERN_ERR "unable to find a free DMA16\n"); snd_printk(KERN_ERR "unable to find a free DMA16\n");
err = -EBUSY; return -EBUSY;
goto err_free;
} }
} }
...@@ -267,7 +264,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -267,7 +264,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
err = jazz16_detect_board(port[dev], xmpu_port); err = jazz16_detect_board(port[dev], xmpu_port);
if (err < 0) { if (err < 0) {
printk(KERN_ERR "Media Vision Jazz16 board not detected\n"); printk(KERN_ERR "Media Vision Jazz16 board not detected\n");
goto err_free; return err;
} }
err = snd_sbdsp_create(card, port[dev], irq[dev], err = snd_sbdsp_create(card, port[dev], irq[dev],
jazz16_interrupt, jazz16_interrupt,
...@@ -275,7 +272,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -275,7 +272,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
SB_HW_JAZZ16, SB_HW_JAZZ16,
&chip); &chip);
if (err < 0) if (err < 0)
goto err_free; return err;
xmpu_irq = mpu_irq[dev]; xmpu_irq = mpu_irq[dev];
if (xmpu_irq == SNDRV_AUTO_IRQ || mpu_port[dev] == SNDRV_AUTO_PORT) if (xmpu_irq == SNDRV_AUTO_IRQ || mpu_port[dev] == SNDRV_AUTO_PORT)
...@@ -283,7 +280,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -283,7 +280,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
err = jazz16_configure_board(chip, xmpu_irq); err = jazz16_configure_board(chip, xmpu_irq);
if (err < 0) { if (err < 0) {
printk(KERN_ERR "Media Vision Jazz16 configuration failed\n"); printk(KERN_ERR "Media Vision Jazz16 configuration failed\n");
goto err_free; return err;
} }
jazz16->chip = chip; jazz16->chip = chip;
...@@ -296,10 +293,10 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -296,10 +293,10 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
err = snd_sb8dsp_pcm(chip, 0); err = snd_sb8dsp_pcm(chip, 0);
if (err < 0) if (err < 0)
goto err_free; return err;
err = snd_sbmixer_new(chip); err = snd_sbmixer_new(chip);
if (err < 0) if (err < 0)
goto err_free; return err;
err = snd_opl3_create(card, chip->port, chip->port + 2, err = snd_opl3_create(card, chip->port, chip->port + 2,
OPL3_HW_AUTO, 1, &opl3); OPL3_HW_AUTO, 1, &opl3);
...@@ -309,7 +306,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -309,7 +306,7 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
else { else {
err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
if (err < 0) if (err < 0)
goto err_free; return err;
} }
if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
if (mpu_irq[dev] == SNDRV_AUTO_IRQ) if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
...@@ -326,21 +323,10 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev) ...@@ -326,21 +323,10 @@ static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto err_free; return err;
dev_set_drvdata(devptr, card); dev_set_drvdata(devptr, card);
return 0; return 0;
err_free:
snd_card_free(card);
return err;
}
static void snd_jazz16_remove(struct device *devptr, unsigned int dev)
{
struct snd_card *card = dev_get_drvdata(devptr);
snd_card_free(card);
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
...@@ -372,7 +358,6 @@ static int snd_jazz16_resume(struct device *pdev, unsigned int n) ...@@ -372,7 +358,6 @@ static int snd_jazz16_resume(struct device *pdev, unsigned int n)
static struct isa_driver snd_jazz16_driver = { static struct isa_driver snd_jazz16_driver = {
.match = snd_jazz16_match, .match = snd_jazz16_match,
.probe = snd_jazz16_probe, .probe = snd_jazz16_probe,
.remove = snd_jazz16_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_jazz16_suspend, .suspend = snd_jazz16_suspend,
.resume = snd_jazz16_resume, .resume = snd_jazz16_resume,
......
...@@ -285,15 +285,6 @@ static int snd_card_sb16_pnp(int dev, struct snd_card_sb16 *acard, ...@@ -285,15 +285,6 @@ static int snd_card_sb16_pnp(int dev, struct snd_card_sb16 *acard,
#endif /* CONFIG_PNP */ #endif /* CONFIG_PNP */
static void snd_sb16_free(struct snd_card *card)
{
struct snd_card_sb16 *acard = card->private_data;
if (acard == NULL)
return;
release_and_free_resource(acard->fm_res);
}
#ifdef CONFIG_PNP #ifdef CONFIG_PNP
#define is_isapnp_selected(dev) isapnp[dev] #define is_isapnp_selected(dev) isapnp[dev]
#else #else
...@@ -306,11 +297,10 @@ static int snd_sb16_card_new(struct device *devptr, int dev, ...@@ -306,11 +297,10 @@ static int snd_sb16_card_new(struct device *devptr, int dev,
struct snd_card *card; struct snd_card *card;
int err; int err;
err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_card_sb16), &card); sizeof(struct snd_card_sb16), &card);
if (err < 0) if (err < 0)
return err; return err;
card->private_free = snd_sb16_free;
*cardp = card; *cardp = card;
return 0; return 0;
} }
...@@ -482,17 +472,16 @@ static int snd_sb16_isa_probe1(int dev, struct device *pdev) ...@@ -482,17 +472,16 @@ static int snd_sb16_isa_probe1(int dev, struct device *pdev)
/* non-PnP FM port address is hardwired with base port address */ /* non-PnP FM port address is hardwired with base port address */
fm_port[dev] = port[dev]; fm_port[dev] = port[dev];
/* block the 0x388 port to avoid PnP conflicts */ /* block the 0x388 port to avoid PnP conflicts */
acard->fm_res = request_region(0x388, 4, "SoundBlaster FM"); acard->fm_res = devm_request_region(card->dev, 0x388, 4,
"SoundBlaster FM");
#ifdef SNDRV_SBAWE_EMU8000 #ifdef SNDRV_SBAWE_EMU8000
/* non-PnP AWE port address is hardwired with base port address */ /* non-PnP AWE port address is hardwired with base port address */
awe_port[dev] = port[dev] + 0x400; awe_port[dev] = port[dev] + 0x400;
#endif #endif
err = snd_sb16_probe(card, dev); err = snd_sb16_probe(card, dev);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
dev_set_drvdata(pdev, card); dev_set_drvdata(pdev, card);
return 0; return 0;
} }
...@@ -547,11 +536,6 @@ static int snd_sb16_isa_probe(struct device *pdev, unsigned int dev) ...@@ -547,11 +536,6 @@ static int snd_sb16_isa_probe(struct device *pdev, unsigned int dev)
} }
} }
static void snd_sb16_isa_remove(struct device *pdev, unsigned int dev)
{
snd_card_free(dev_get_drvdata(pdev));
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int snd_sb16_isa_suspend(struct device *dev, unsigned int n, static int snd_sb16_isa_suspend(struct device *dev, unsigned int n,
pm_message_t state) pm_message_t state)
...@@ -574,7 +558,6 @@ static int snd_sb16_isa_resume(struct device *dev, unsigned int n) ...@@ -574,7 +558,6 @@ static int snd_sb16_isa_resume(struct device *dev, unsigned int n)
static struct isa_driver snd_sb16_isa_driver = { static struct isa_driver snd_sb16_isa_driver = {
.match = snd_sb16_isa_match, .match = snd_sb16_isa_match,
.probe = snd_sb16_isa_probe, .probe = snd_sb16_isa_probe,
.remove = snd_sb16_isa_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_sb16_isa_suspend, .suspend = snd_sb16_isa_suspend,
.resume = snd_sb16_isa_resume, .resume = snd_sb16_isa_resume,
...@@ -600,15 +583,11 @@ static int snd_sb16_pnp_detect(struct pnp_card_link *pcard, ...@@ -600,15 +583,11 @@ static int snd_sb16_pnp_detect(struct pnp_card_link *pcard,
if (res < 0) if (res < 0)
return res; return res;
res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid); res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid);
if (res < 0) { if (res < 0)
snd_card_free(card);
return res; return res;
}
res = snd_sb16_probe(card, dev); res = snd_sb16_probe(card, dev);
if (res < 0) { if (res < 0)
snd_card_free(card);
return res; return res;
}
pnp_set_card_drvdata(pcard, card); pnp_set_card_drvdata(pcard, card);
dev++; dev++;
return 0; return 0;
...@@ -617,12 +596,6 @@ static int snd_sb16_pnp_detect(struct pnp_card_link *pcard, ...@@ -617,12 +596,6 @@ static int snd_sb16_pnp_detect(struct pnp_card_link *pcard,
return -ENODEV; return -ENODEV;
} }
static void snd_sb16_pnp_remove(struct pnp_card_link *pcard)
{
snd_card_free(pnp_get_card_drvdata(pcard));
pnp_set_card_drvdata(pcard, NULL);
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int snd_sb16_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state) static int snd_sb16_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
{ {
...@@ -643,7 +616,6 @@ static struct pnp_card_driver sb16_pnpc_driver = { ...@@ -643,7 +616,6 @@ static struct pnp_card_driver sb16_pnpc_driver = {
#endif #endif
.id_table = snd_sb16_pnpids, .id_table = snd_sb16_pnpids,
.probe = snd_sb16_pnp_detect, .probe = snd_sb16_pnp_detect,
.remove = snd_sb16_pnp_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_sb16_pnp_suspend, .suspend = snd_sb16_pnp_suspend,
.resume = snd_sb16_pnp_resume, .resume = snd_sb16_pnp_resume,
......
...@@ -54,15 +54,6 @@ static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id) ...@@ -54,15 +54,6 @@ static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id)
} }
} }
static void snd_sb8_free(struct snd_card *card)
{
struct snd_sb8 *acard = card->private_data;
if (acard == NULL)
return;
release_and_free_resource(acard->fm_res);
}
static int snd_sb8_match(struct device *pdev, unsigned int dev) static int snd_sb8_match(struct device *pdev, unsigned int dev)
{ {
if (!enable[dev]) if (!enable[dev])
...@@ -86,26 +77,26 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev) ...@@ -86,26 +77,26 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
struct snd_opl3 *opl3; struct snd_opl3 *opl3;
int err; int err;
err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_sb8), &card); sizeof(struct snd_sb8), &card);
if (err < 0) if (err < 0)
return err; return err;
acard = card->private_data; acard = card->private_data;
card->private_free = snd_sb8_free;
/* /*
* Block the 0x388 port to avoid PnP conflicts. * Block the 0x388 port to avoid PnP conflicts.
* No need to check this value after request_region, * No need to check this value after request_region,
* as we never do anything with it. * as we never do anything with it.
*/ */
acard->fm_res = request_region(0x388, 4, "SoundBlaster FM"); acard->fm_res = devm_request_region(card->dev, 0x388, 4,
"SoundBlaster FM");
if (port[dev] != SNDRV_AUTO_PORT) { if (port[dev] != SNDRV_AUTO_PORT) {
err = snd_sbdsp_create(card, port[dev], irq[dev], err = snd_sbdsp_create(card, port[dev], irq[dev],
snd_sb8_interrupt, dma8[dev], snd_sb8_interrupt, dma8[dev],
-1, SB_HW_AUTO, &chip); -1, SB_HW_AUTO, &chip);
if (err < 0) if (err < 0)
goto _err; return err;
} else { } else {
/* auto-probe legacy ports */ /* auto-probe legacy ports */
static const unsigned long possible_ports[] = { static const unsigned long possible_ports[] = {
...@@ -125,10 +116,8 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev) ...@@ -125,10 +116,8 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
break; break;
} }
} }
if (i >= ARRAY_SIZE(possible_ports)) { if (i >= ARRAY_SIZE(possible_ports))
err = -EINVAL; return -EINVAL;
goto _err;
}
} }
acard->chip = chip; acard->chip = chip;
...@@ -139,17 +128,16 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev) ...@@ -139,17 +128,16 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
else else
snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n", snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
port[dev]); port[dev]);
err = -ENODEV; return -ENODEV;
goto _err;
} }
err = snd_sb8dsp_pcm(chip, 0); err = snd_sb8dsp_pcm(chip, 0);
if (err < 0) if (err < 0)
goto _err; return err;
err = snd_sbmixer_new(chip); err = snd_sbmixer_new(chip);
if (err < 0) if (err < 0)
goto _err; return err;
if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) { if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
err = snd_opl3_create(card, chip->port + 8, 0, err = snd_opl3_create(card, chip->port + 8, 0,
...@@ -167,12 +155,12 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev) ...@@ -167,12 +155,12 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
if (err >= 0) { if (err >= 0) {
err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
if (err < 0) if (err < 0)
goto _err; return err;
} }
err = snd_sb8dsp_midi(chip, 0); err = snd_sb8dsp_midi(chip, 0);
if (err < 0) if (err < 0)
goto _err; return err;
strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8"); strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
strcpy(card->shortname, chip->name); strcpy(card->shortname, chip->name);
...@@ -183,19 +171,10 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev) ...@@ -183,19 +171,10 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto _err; return err;
dev_set_drvdata(pdev, card); dev_set_drvdata(pdev, card);
return 0; return 0;
_err:
snd_card_free(card);
return err;
}
static void snd_sb8_remove(struct device *pdev, unsigned int dev)
{
snd_card_free(dev_get_drvdata(pdev));
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
...@@ -229,7 +208,6 @@ static int snd_sb8_resume(struct device *dev, unsigned int n) ...@@ -229,7 +208,6 @@ static int snd_sb8_resume(struct device *dev, unsigned int n)
static struct isa_driver snd_sb8_driver = { static struct isa_driver snd_sb8_driver = {
.match = snd_sb8_match, .match = snd_sb8_match,
.probe = snd_sb8_probe, .probe = snd_sb8_probe,
.remove = snd_sb8_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_sb8_suspend, .suspend = snd_sb8_suspend,
.resume = snd_sb8_resume, .resume = snd_sb8_resume,
......
...@@ -168,31 +168,6 @@ static int snd_sbdsp_probe(struct snd_sb * chip) ...@@ -168,31 +168,6 @@ static int snd_sbdsp_probe(struct snd_sb * chip)
return 0; return 0;
} }
static int snd_sbdsp_free(struct snd_sb *chip)
{
release_and_free_resource(chip->res_port);
if (chip->irq >= 0)
free_irq(chip->irq, (void *) chip);
#ifdef CONFIG_ISA
if (chip->dma8 >= 0) {
disable_dma(chip->dma8);
free_dma(chip->dma8);
}
if (chip->dma16 >= 0 && chip->dma16 != chip->dma8) {
disable_dma(chip->dma16);
free_dma(chip->dma16);
}
#endif
kfree(chip);
return 0;
}
static int snd_sbdsp_dev_free(struct snd_device *device)
{
struct snd_sb *chip = device->device_data;
return snd_sbdsp_free(chip);
}
int snd_sbdsp_create(struct snd_card *card, int snd_sbdsp_create(struct snd_card *card,
unsigned long port, unsigned long port,
int irq, int irq,
...@@ -204,15 +179,12 @@ int snd_sbdsp_create(struct snd_card *card, ...@@ -204,15 +179,12 @@ int snd_sbdsp_create(struct snd_card *card,
{ {
struct snd_sb *chip; struct snd_sb *chip;
int err; int err;
static const struct snd_device_ops ops = {
.dev_free = snd_sbdsp_dev_free,
};
if (snd_BUG_ON(!r_chip)) if (snd_BUG_ON(!r_chip))
return -EINVAL; return -EINVAL;
*r_chip = NULL; *r_chip = NULL;
chip = kzalloc(sizeof(*chip), GFP_KERNEL); chip = devm_kzalloc(card->dev, sizeof(*chip), GFP_KERNEL);
if (chip == NULL) if (!chip)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->reg_lock);
spin_lock_init(&chip->open_lock); spin_lock_init(&chip->open_lock);
...@@ -223,13 +195,12 @@ int snd_sbdsp_create(struct snd_card *card, ...@@ -223,13 +195,12 @@ int snd_sbdsp_create(struct snd_card *card,
chip->dma16 = -1; chip->dma16 = -1;
chip->port = port; chip->port = port;
if (request_irq(irq, irq_handler, if (devm_request_irq(card->dev, irq, irq_handler,
(hardware == SB_HW_ALS4000 || (hardware == SB_HW_ALS4000 ||
hardware == SB_HW_CS5530) ? hardware == SB_HW_CS5530) ?
IRQF_SHARED : 0, IRQF_SHARED : 0,
"SoundBlaster", (void *) chip)) { "SoundBlaster", (void *) chip)) {
snd_printk(KERN_ERR "sb: can't grab irq %d\n", irq); snd_printk(KERN_ERR "sb: can't grab irq %d\n", irq);
snd_sbdsp_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->irq = irq; chip->irq = irq;
...@@ -238,17 +209,17 @@ int snd_sbdsp_create(struct snd_card *card, ...@@ -238,17 +209,17 @@ int snd_sbdsp_create(struct snd_card *card,
if (hardware == SB_HW_ALS4000) if (hardware == SB_HW_ALS4000)
goto __skip_allocation; goto __skip_allocation;
chip->res_port = request_region(port, 16, "SoundBlaster"); chip->res_port = devm_request_region(card->dev, port, 16,
"SoundBlaster");
if (!chip->res_port) { if (!chip->res_port) {
snd_printk(KERN_ERR "sb: can't grab port 0x%lx\n", port); snd_printk(KERN_ERR "sb: can't grab port 0x%lx\n", port);
snd_sbdsp_free(chip);
return -EBUSY; return -EBUSY;
} }
#ifdef CONFIG_ISA #ifdef CONFIG_ISA
if (dma8 >= 0 && request_dma(dma8, "SoundBlaster - 8bit")) { if (dma8 >= 0 && snd_devm_request_dma(card->dev, dma8,
"SoundBlaster - 8bit")) {
snd_printk(KERN_ERR "sb: can't grab DMA8 %d\n", dma8); snd_printk(KERN_ERR "sb: can't grab DMA8 %d\n", dma8);
snd_sbdsp_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->dma8 = dma8; chip->dma8 = dma8;
...@@ -256,9 +227,9 @@ int snd_sbdsp_create(struct snd_card *card, ...@@ -256,9 +227,9 @@ int snd_sbdsp_create(struct snd_card *card,
if (hardware != SB_HW_ALS100 && (dma16 < 5 || dma16 > 7)) { if (hardware != SB_HW_ALS100 && (dma16 < 5 || dma16 > 7)) {
/* no duplex */ /* no duplex */
dma16 = -1; dma16 = -1;
} else if (request_dma(dma16, "SoundBlaster - 16bit")) { } else if (snd_devm_request_dma(card->dev, dma16,
"SoundBlaster - 16bit")) {
snd_printk(KERN_ERR "sb: can't grab DMA16 %d\n", dma16); snd_printk(KERN_ERR "sb: can't grab DMA16 %d\n", dma16);
snd_sbdsp_free(chip);
return -EBUSY; return -EBUSY;
} }
} }
...@@ -269,15 +240,8 @@ int snd_sbdsp_create(struct snd_card *card, ...@@ -269,15 +240,8 @@ int snd_sbdsp_create(struct snd_card *card,
chip->card = card; chip->card = card;
chip->hardware = hardware; chip->hardware = hardware;
err = snd_sbdsp_probe(chip); err = snd_sbdsp_probe(chip);
if (err < 0) { if (err < 0)
snd_sbdsp_free(chip);
return err; return err;
}
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
snd_sbdsp_free(chip);
return err;
}
*r_chip = chip; *r_chip = chip;
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