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

ALSA: maestro3: Allocate resources with device-managed APIs

This patch converts the resource management in PCI maestro3 driver
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.  Superfluous ac97 private_free callbacks were dropped,
too.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-21-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 47c41339
...@@ -2339,16 +2339,13 @@ snd_m3_enable_ints(struct snd_m3 *chip) ...@@ -2339,16 +2339,13 @@ snd_m3_enable_ints(struct snd_m3 *chip)
/* /*
*/ */
static int snd_m3_free(struct snd_m3 *chip) static void snd_m3_free(struct snd_card *card)
{ {
struct snd_m3 *chip = card->private_data;
struct m3_dma *s; struct m3_dma *s;
int i; int i;
cancel_work_sync(&chip->hwvol_work); cancel_work_sync(&chip->hwvol_work);
#ifdef CONFIG_SND_MAESTRO3_INPUT
if (chip->input_dev)
input_unregister_device(chip->input_dev);
#endif
if (chip->substreams) { if (chip->substreams) {
spin_lock_irq(&chip->reg_lock); spin_lock_irq(&chip->reg_lock);
...@@ -2359,7 +2356,6 @@ static int snd_m3_free(struct snd_m3 *chip) ...@@ -2359,7 +2356,6 @@ static int snd_m3_free(struct snd_m3 *chip)
snd_m3_pcm_stop(chip, s, s->substream); snd_m3_pcm_stop(chip, s, s->substream);
} }
spin_unlock_irq(&chip->reg_lock); spin_unlock_irq(&chip->reg_lock);
kfree(chip->substreams);
} }
if (chip->iobase) { if (chip->iobase) {
outw(0, chip->iobase + HOST_INT_CTRL); /* disable ints */ outw(0, chip->iobase + HOST_INT_CTRL); /* disable ints */
...@@ -2368,19 +2364,8 @@ static int snd_m3_free(struct snd_m3 *chip) ...@@ -2368,19 +2364,8 @@ static int snd_m3_free(struct snd_m3 *chip)
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
vfree(chip->suspend_mem); vfree(chip->suspend_mem);
#endif #endif
if (chip->irq >= 0)
free_irq(chip->irq, chip);
if (chip->iobase)
pci_release_regions(chip->pci);
release_firmware(chip->assp_kernel_image); release_firmware(chip->assp_kernel_image);
release_firmware(chip->assp_minisrc_image); release_firmware(chip->assp_minisrc_image);
pci_disable_device(chip->pci);
kfree(chip);
return 0;
} }
...@@ -2473,7 +2458,7 @@ static int snd_m3_input_register(struct snd_m3 *chip) ...@@ -2473,7 +2458,7 @@ static int snd_m3_input_register(struct snd_m3 *chip)
struct input_dev *input_dev; struct input_dev *input_dev;
int err; int err;
input_dev = input_allocate_device(); input_dev = devm_input_allocate_device(&chip->pci->dev);
if (!input_dev) if (!input_dev)
return -ENOMEM; return -ENOMEM;
...@@ -2493,10 +2478,8 @@ static int snd_m3_input_register(struct snd_m3 *chip) ...@@ -2493,10 +2478,8 @@ static int snd_m3_input_register(struct snd_m3 *chip)
__set_bit(KEY_VOLUMEUP, input_dev->keybit); __set_bit(KEY_VOLUMEUP, input_dev->keybit);
err = input_register_device(input_dev); err = input_register_device(input_dev);
if (err) { if (err)
input_free_device(input_dev);
return err; return err;
}
chip->input_dev = input_dev; chip->input_dev = input_dev;
return 0; return 0;
...@@ -2506,44 +2489,25 @@ static int snd_m3_input_register(struct snd_m3 *chip) ...@@ -2506,44 +2489,25 @@ static int snd_m3_input_register(struct snd_m3 *chip)
/* /*
*/ */
static int snd_m3_dev_free(struct snd_device *device)
{
struct snd_m3 *chip = device->device_data;
return snd_m3_free(chip);
}
static int static int
snd_m3_create(struct snd_card *card, struct pci_dev *pci, snd_m3_create(struct snd_card *card, struct pci_dev *pci,
int enable_amp, int enable_amp,
int amp_gpio, int amp_gpio)
struct snd_m3 **chip_ret)
{ {
struct snd_m3 *chip; struct snd_m3 *chip = card->private_data;
int i, err; int i, err;
const struct snd_pci_quirk *quirk; const struct snd_pci_quirk *quirk;
static const struct snd_device_ops ops = {
.dev_free = snd_m3_dev_free,
};
*chip_ret = NULL; if (pcim_enable_device(pci))
if (pci_enable_device(pci))
return -EIO; return -EIO;
/* check, if we can restrict PCI DMA transfers to 28 bits */ /* check, if we can restrict PCI DMA transfers to 28 bits */
if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) { if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) {
dev_err(card->dev, dev_err(card->dev,
"architecture does not support 28bit PCI busmaster DMA\n"); "architecture does not support 28bit PCI busmaster DMA\n");
pci_disable_device(pci);
return -ENXIO; return -ENXIO;
} }
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
if (chip == NULL) {
pci_disable_device(pci);
return -ENOMEM;
}
spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->reg_lock);
switch (pci->device) { switch (pci->device) {
...@@ -2559,6 +2523,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, ...@@ -2559,6 +2523,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
chip->pci = pci; chip->pci = pci;
chip->irq = -1; chip->irq = -1;
INIT_WORK(&chip->hwvol_work, snd_m3_update_hw_volume); INIT_WORK(&chip->hwvol_work, snd_m3_update_hw_volume);
card->private_free = snd_m3_free;
chip->external_amp = enable_amp; chip->external_amp = enable_amp;
if (amp_gpio >= 0 && amp_gpio <= 0x0f) if (amp_gpio >= 0 && amp_gpio <= 0x0f)
...@@ -2588,27 +2553,24 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, ...@@ -2588,27 +2553,24 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
chip->is_omnibook = 1; chip->is_omnibook = 1;
chip->num_substreams = NR_DSPS; chip->num_substreams = NR_DSPS;
chip->substreams = kcalloc(chip->num_substreams, sizeof(struct m3_dma), chip->substreams = devm_kcalloc(&pci->dev, chip->num_substreams,
GFP_KERNEL); sizeof(struct m3_dma), GFP_KERNEL);
if (chip->substreams == NULL) { if (!chip->substreams)
kfree(chip);
pci_disable_device(pci);
return -ENOMEM; return -ENOMEM;
}
err = request_firmware(&chip->assp_kernel_image, err = request_firmware(&chip->assp_kernel_image,
"ess/maestro3_assp_kernel.fw", &pci->dev); "ess/maestro3_assp_kernel.fw", &pci->dev);
if (err < 0) if (err < 0)
goto free_chip; return err;
err = request_firmware(&chip->assp_minisrc_image, err = request_firmware(&chip->assp_minisrc_image,
"ess/maestro3_assp_minisrc.fw", &pci->dev); "ess/maestro3_assp_minisrc.fw", &pci->dev);
if (err < 0) if (err < 0)
goto free_chip; return err;
err = pci_request_regions(pci, card->driver); err = pci_request_regions(pci, card->driver);
if (err < 0) if (err < 0)
goto free_chip; return err;
chip->iobase = pci_resource_start(pci, 0); chip->iobase = pci_resource_start(pci, 0);
...@@ -2624,11 +2586,10 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, ...@@ -2624,11 +2586,10 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
snd_m3_hv_init(chip); snd_m3_hv_init(chip);
if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED, if (devm_request_irq(&pci->dev, pci->irq, snd_m3_interrupt, IRQF_SHARED,
KBUILD_MODNAME, chip)) { KBUILD_MODNAME, chip)) {
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
err = -ENOMEM; return -ENOMEM;
goto free_chip;
} }
chip->irq = pci->irq; chip->irq = pci->irq;
card->sync_irq = chip->irq; card->sync_irq = chip->irq;
...@@ -2642,10 +2603,6 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, ...@@ -2642,10 +2603,6 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
dev_warn(card->dev, "can't allocate apm buffer\n"); dev_warn(card->dev, "can't allocate apm buffer\n");
#endif #endif
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0)
goto free_chip;
err = snd_m3_mixer(chip); err = snd_m3_mixer(chip);
if (err < 0) if (err < 0)
return err; return err;
...@@ -2674,13 +2631,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci, ...@@ -2674,13 +2631,7 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
snd_m3_enable_ints(chip); snd_m3_enable_ints(chip);
snd_m3_assp_continue(chip); snd_m3_assp_continue(chip);
*chip_ret = chip;
return 0; return 0;
free_chip:
snd_m3_free(chip);
return err;
} }
/* /*
...@@ -2704,10 +2655,11 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) ...@@ -2704,10 +2655,11 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
return -ENOENT; return -ENOENT;
} }
err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
0, &card); sizeof(*chip), &card);
if (err < 0) if (err < 0)
return err; return err;
chip = card->private_data;
switch (pci->device) { switch (pci->device) {
case PCI_DEVICE_ID_ESS_ALLEGRO: case PCI_DEVICE_ID_ESS_ALLEGRO:
...@@ -2723,11 +2675,9 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) ...@@ -2723,11 +2675,9 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
break; break;
} }
err = snd_m3_create(card, pci, external_amp[dev], amp_gpio[dev], &chip); err = snd_m3_create(card, pci, external_amp[dev], amp_gpio[dev]);
if (err < 0) if (err < 0)
goto free_card; return err;
card->private_data = chip;
sprintf(card->shortname, "ESS %s PCI", card->driver); sprintf(card->shortname, "ESS %s PCI", card->driver);
sprintf(card->longname, "%s at 0x%lx, irq %d", sprintf(card->longname, "%s at 0x%lx, irq %d",
...@@ -2735,7 +2685,7 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) ...@@ -2735,7 +2685,7 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto free_card; return err;
#if 0 /* TODO: not supported yet */ #if 0 /* TODO: not supported yet */
/* TODO enable MIDI IRQ and I/O */ /* TODO enable MIDI IRQ and I/O */
...@@ -2750,22 +2700,12 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) ...@@ -2750,22 +2700,12 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
pci_set_drvdata(pci, card); pci_set_drvdata(pci, card);
dev++; dev++;
return 0; return 0;
free_card:
snd_card_free(card);
return err;
}
static void snd_m3_remove(struct pci_dev *pci)
{
snd_card_free(pci_get_drvdata(pci));
} }
static struct pci_driver m3_driver = { static struct pci_driver m3_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = snd_m3_ids, .id_table = snd_m3_ids,
.probe = snd_m3_probe, .probe = snd_m3_probe,
.remove = snd_m3_remove,
.driver = { .driver = {
.pm = M3_PM_OPS, .pm = M3_PM_OPS,
}, },
......
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