Commit a7b4cbfd authored by Takashi Iwai's avatar Takashi Iwai

ALSA: es1968: Allocate resources with device-managed APIs

This patch converts the resource management in PCI es1968 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.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-19-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 08e9d3ab
...@@ -2442,7 +2442,8 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev) ...@@ -2442,7 +2442,8 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev)
if (!joystick[dev]) if (!joystick[dev])
return -ENODEV; return -ENODEV;
r = request_region(JOYSTICK_ADDR, 8, "ES1968 gameport"); r = devm_request_region(&chip->pci->dev, JOYSTICK_ADDR, 8,
"ES1968 gameport");
if (!r) if (!r)
return -EBUSY; return -EBUSY;
...@@ -2450,7 +2451,6 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev) ...@@ -2450,7 +2451,6 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev)
if (!gp) { if (!gp) {
dev_err(chip->card->dev, dev_err(chip->card->dev,
"cannot allocate memory for gameport\n"); "cannot allocate memory for gameport\n");
release_and_free_resource(r);
return -ENOMEM; return -ENOMEM;
} }
...@@ -2461,7 +2461,6 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev) ...@@ -2461,7 +2461,6 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev)
gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
gameport_set_dev_parent(gp, &chip->pci->dev); gameport_set_dev_parent(gp, &chip->pci->dev);
gp->io = JOYSTICK_ADDR; gp->io = JOYSTICK_ADDR;
gameport_set_port_data(gp, r);
gameport_register_port(gp); gameport_register_port(gp);
...@@ -2471,12 +2470,8 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev) ...@@ -2471,12 +2470,8 @@ static int snd_es1968_create_gameport(struct es1968 *chip, int dev)
static void snd_es1968_free_gameport(struct es1968 *chip) static void snd_es1968_free_gameport(struct es1968 *chip)
{ {
if (chip->gameport) { if (chip->gameport) {
struct resource *r = gameport_get_port_data(chip->gameport);
gameport_unregister_port(chip->gameport); gameport_unregister_port(chip->gameport);
chip->gameport = NULL; chip->gameport = NULL;
release_and_free_resource(r);
} }
} }
#else #else
...@@ -2490,7 +2485,7 @@ static int snd_es1968_input_register(struct es1968 *chip) ...@@ -2490,7 +2485,7 @@ static int snd_es1968_input_register(struct es1968 *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;
...@@ -2510,10 +2505,8 @@ static int snd_es1968_input_register(struct es1968 *chip) ...@@ -2510,10 +2505,8 @@ static int snd_es1968_input_register(struct es1968 *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;
...@@ -2597,13 +2590,11 @@ static const struct snd_tea575x_ops snd_es1968_tea_ops = { ...@@ -2597,13 +2590,11 @@ static const struct snd_tea575x_ops snd_es1968_tea_ops = {
}; };
#endif #endif
static int snd_es1968_free(struct es1968 *chip) static void snd_es1968_free(struct snd_card *card)
{ {
struct es1968 *chip = card->private_data;
cancel_work_sync(&chip->hwvol_work); cancel_work_sync(&chip->hwvol_work);
#ifdef CONFIG_SND_ES1968_INPUT
if (chip->input_dev)
input_unregister_device(chip->input_dev);
#endif
if (chip->io_port) { if (chip->io_port) {
outw(1, chip->io_port + 0x04); /* clear WP interrupts */ outw(1, chip->io_port + 0x04); /* clear WP interrupts */
...@@ -2615,19 +2606,7 @@ static int snd_es1968_free(struct es1968 *chip) ...@@ -2615,19 +2606,7 @@ static int snd_es1968_free(struct es1968 *chip)
v4l2_device_unregister(&chip->v4l2_dev); v4l2_device_unregister(&chip->v4l2_dev);
#endif #endif
if (chip->irq >= 0)
free_irq(chip->irq, chip);
snd_es1968_free_gameport(chip); snd_es1968_free_gameport(chip);
pci_release_regions(chip->pci);
pci_disable_device(chip->pci);
kfree(chip);
return 0;
}
static int snd_es1968_dev_free(struct snd_device *device)
{
struct es1968 *chip = device->device_data;
return snd_es1968_free(chip);
} }
struct ess_device_list { struct ess_device_list {
...@@ -2657,35 +2636,22 @@ static int snd_es1968_create(struct snd_card *card, ...@@ -2657,35 +2636,22 @@ static int snd_es1968_create(struct snd_card *card,
int capt_streams, int capt_streams,
int chip_type, int chip_type,
int do_pm, int do_pm,
int radio_nr, int radio_nr)
struct es1968 **chip_ret)
{ {
static const struct snd_device_ops ops = { struct es1968 *chip = card->private_data;
.dev_free = snd_es1968_dev_free,
};
struct es1968 *chip;
int i, err; int i, err;
*chip_ret = NULL;
/* enable PCI device */ /* enable PCI device */
err = pci_enable_device(pci); err = pcim_enable_device(pci);
if (err < 0) if (err < 0)
return err; return err;
/* 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) {
pci_disable_device(pci);
return -ENOMEM;
}
/* Set Vars */ /* Set Vars */
chip->type = chip_type; chip->type = chip_type;
spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->reg_lock);
...@@ -2702,20 +2668,17 @@ static int snd_es1968_create(struct snd_card *card, ...@@ -2702,20 +2668,17 @@ static int snd_es1968_create(struct snd_card *card,
chip->capture_streams = capt_streams; chip->capture_streams = capt_streams;
err = pci_request_regions(pci, "ESS Maestro"); err = pci_request_regions(pci, "ESS Maestro");
if (err < 0) { if (err < 0)
kfree(chip);
pci_disable_device(pci);
return err; return err;
}
chip->io_port = pci_resource_start(pci, 0); chip->io_port = pci_resource_start(pci, 0);
if (request_irq(pci->irq, snd_es1968_interrupt, IRQF_SHARED, if (devm_request_irq(&pci->dev, pci->irq, snd_es1968_interrupt,
KBUILD_MODNAME, chip)) { IRQF_SHARED, 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);
snd_es1968_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->irq = pci->irq; chip->irq = pci->irq;
card->sync_irq = chip->irq; card->sync_irq = chip->irq;
card->private_free = snd_es1968_free;
/* Clear Maestro_map */ /* Clear Maestro_map */
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
...@@ -2749,21 +2712,13 @@ static int snd_es1968_create(struct snd_card *card, ...@@ -2749,21 +2712,13 @@ static int snd_es1968_create(struct snd_card *card,
snd_es1968_chip_init(chip); snd_es1968_chip_init(chip);
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
snd_es1968_free(chip);
return err;
}
#ifdef CONFIG_SND_ES1968_RADIO #ifdef CONFIG_SND_ES1968_RADIO
/* don't play with GPIOs on laptops */ /* don't play with GPIOs on laptops */
if (chip->pci->subsystem_vendor != 0x125d) if (chip->pci->subsystem_vendor != 0x125d)
goto no_radio; return 0;
err = v4l2_device_register(&pci->dev, &chip->v4l2_dev); err = v4l2_device_register(&pci->dev, &chip->v4l2_dev);
if (err < 0) { if (err < 0)
snd_es1968_free(chip);
return err; return err;
}
chip->tea.v4l2_dev = &chip->v4l2_dev; chip->tea.v4l2_dev = &chip->v4l2_dev;
chip->tea.private_data = chip; chip->tea.private_data = chip;
chip->tea.radio_nr = radio_nr; chip->tea.radio_nr = radio_nr;
...@@ -2779,11 +2734,7 @@ static int snd_es1968_create(struct snd_card *card, ...@@ -2779,11 +2734,7 @@ static int snd_es1968_create(struct snd_card *card,
break; break;
} }
} }
no_radio:
#endif #endif
*chip_ret = chip;
return 0; return 0;
} }
...@@ -2806,10 +2757,11 @@ static int snd_es1968_probe(struct pci_dev *pci, ...@@ -2806,10 +2757,11 @@ static int snd_es1968_probe(struct pci_dev *pci,
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;
if (total_bufsize[dev] < 128) if (total_bufsize[dev] < 128)
total_bufsize[dev] = 128; total_bufsize[dev] = 128;
...@@ -2821,13 +2773,9 @@ static int snd_es1968_probe(struct pci_dev *pci, ...@@ -2821,13 +2773,9 @@ static int snd_es1968_probe(struct pci_dev *pci,
pcm_substreams_c[dev], pcm_substreams_c[dev],
pci_id->driver_data, pci_id->driver_data,
use_pm[dev], use_pm[dev],
radio_nr[dev], radio_nr[dev]);
&chip); if (err < 0)
if (err < 0) {
snd_card_free(card);
return err; return err;
}
card->private_data = chip;
switch (chip->type) { switch (chip->type) {
case TYPE_MAESTRO2E: case TYPE_MAESTRO2E:
...@@ -2845,16 +2793,12 @@ static int snd_es1968_probe(struct pci_dev *pci, ...@@ -2845,16 +2793,12 @@ static int snd_es1968_probe(struct pci_dev *pci,
} }
err = snd_es1968_pcm(chip, 0); err = snd_es1968_pcm(chip, 0);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
err = snd_es1968_mixer(chip); err = snd_es1968_mixer(chip);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
if (enable_mpu[dev] == 2) { if (enable_mpu[dev] == 2) {
/* check the deny list */ /* check the deny list */
...@@ -2897,25 +2841,17 @@ static int snd_es1968_probe(struct pci_dev *pci, ...@@ -2897,25 +2841,17 @@ static int snd_es1968_probe(struct pci_dev *pci,
card->shortname, chip->io_port, chip->irq); card->shortname, chip->io_port, chip->irq);
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
pci_set_drvdata(pci, card); pci_set_drvdata(pci, card);
dev++; dev++;
return 0; return 0;
} }
static void snd_es1968_remove(struct pci_dev *pci)
{
snd_card_free(pci_get_drvdata(pci));
}
static struct pci_driver es1968_driver = { static struct pci_driver es1968_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = snd_es1968_ids, .id_table = snd_es1968_ids,
.probe = snd_es1968_probe, .probe = snd_es1968_probe,
.remove = snd_es1968_remove,
.driver = { .driver = {
.pm = ES1968_PM_OPS, .pm = ES1968_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