Commit 596ae97a authored by Takashi Iwai's avatar Takashi Iwai

ALSA: oxygen: Allocate resources with device-managed APIs

This patch converts the resource management in PCI oxygen drivers with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper, and the page allocations are
done with the devres helper.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-44-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c19935f0
...@@ -854,7 +854,6 @@ static struct pci_driver oxygen_driver = { ...@@ -854,7 +854,6 @@ static struct pci_driver oxygen_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = oxygen_ids, .id_table = oxygen_ids,
.probe = generic_oxygen_probe, .probe = generic_oxygen_probe,
.remove = oxygen_pci_remove,
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
.driver = { .driver = {
.pm = &oxygen_pci_pm, .pm = &oxygen_pci_pm,
......
...@@ -161,7 +161,6 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, ...@@ -161,7 +161,6 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
const struct pci_device_id *id const struct pci_device_id *id
) )
); );
void oxygen_pci_remove(struct pci_dev *pci);
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
extern const struct dev_pm_ops oxygen_pci_pm; extern const struct dev_pm_ops oxygen_pci_pm;
#endif #endif
......
...@@ -570,15 +570,10 @@ static void oxygen_card_free(struct snd_card *card) ...@@ -570,15 +570,10 @@ static void oxygen_card_free(struct snd_card *card)
struct oxygen *chip = card->private_data; struct oxygen *chip = card->private_data;
oxygen_shutdown(chip); oxygen_shutdown(chip);
if (chip->irq >= 0)
free_irq(chip->irq, chip);
flush_work(&chip->spdif_input_bits_work); flush_work(&chip->spdif_input_bits_work);
flush_work(&chip->gpio_work); flush_work(&chip->gpio_work);
chip->model.cleanup(chip); chip->model.cleanup(chip);
kfree(chip->model_data);
mutex_destroy(&chip->mutex); mutex_destroy(&chip->mutex);
pci_release_regions(chip->pci);
pci_disable_device(chip->pci);
} }
int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
...@@ -594,8 +589,8 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, ...@@ -594,8 +589,8 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
const struct pci_device_id *pci_id; const struct pci_device_id *pci_id;
int err; int err;
err = snd_card_new(&pci->dev, index, id, owner, err = snd_devm_card_new(&pci->dev, index, id, owner,
sizeof(*chip), &card); sizeof(*chip), &card);
if (err < 0) if (err < 0)
return err; return err;
...@@ -610,41 +605,38 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, ...@@ -610,41 +605,38 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
INIT_WORK(&chip->gpio_work, oxygen_gpio_changed); INIT_WORK(&chip->gpio_work, oxygen_gpio_changed);
init_waitqueue_head(&chip->ac97_waitqueue); init_waitqueue_head(&chip->ac97_waitqueue);
err = pci_enable_device(pci); err = pcim_enable_device(pci);
if (err < 0) if (err < 0)
goto err_card; return err;
err = pci_request_regions(pci, DRIVER); err = pci_request_regions(pci, DRIVER);
if (err < 0) { if (err < 0) {
dev_err(card->dev, "cannot reserve PCI resources\n"); dev_err(card->dev, "cannot reserve PCI resources\n");
goto err_pci_enable; return err;
} }
if (!(pci_resource_flags(pci, 0) & IORESOURCE_IO) || if (!(pci_resource_flags(pci, 0) & IORESOURCE_IO) ||
pci_resource_len(pci, 0) < OXYGEN_IO_SIZE) { pci_resource_len(pci, 0) < OXYGEN_IO_SIZE) {
dev_err(card->dev, "invalid PCI I/O range\n"); dev_err(card->dev, "invalid PCI I/O range\n");
err = -ENXIO; return -ENXIO;
goto err_pci_regions;
} }
chip->addr = pci_resource_start(pci, 0); chip->addr = pci_resource_start(pci, 0);
pci_id = oxygen_search_pci_id(chip, ids); pci_id = oxygen_search_pci_id(chip, ids);
if (!pci_id) { if (!pci_id)
err = -ENODEV; return -ENODEV;
goto err_pci_regions;
}
oxygen_restore_eeprom(chip, pci_id); oxygen_restore_eeprom(chip, pci_id);
err = get_model(chip, pci_id); err = get_model(chip, pci_id);
if (err < 0) if (err < 0)
goto err_pci_regions; return err;
if (chip->model.model_data_size) { if (chip->model.model_data_size) {
chip->model_data = kzalloc(chip->model.model_data_size, chip->model_data = devm_kzalloc(&pci->dev,
GFP_KERNEL); chip->model.model_data_size,
if (!chip->model_data) { GFP_KERNEL);
err = -ENOMEM; if (!chip->model_data)
goto err_pci_regions; return -ENOMEM;
}
} }
pci_set_master(pci); pci_set_master(pci);
...@@ -654,11 +646,11 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, ...@@ -654,11 +646,11 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
oxygen_init(chip); oxygen_init(chip);
chip->model.init(chip); chip->model.init(chip);
err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED, err = devm_request_irq(&pci->dev, pci->irq, oxygen_interrupt,
KBUILD_MODNAME, chip); IRQF_SHARED, KBUILD_MODNAME, chip);
if (err < 0) { if (err < 0) {
dev_err(card->dev, "cannot grab interrupt %d\n", pci->irq); dev_err(card->dev, "cannot grab interrupt %d\n", pci->irq);
goto err_card; return err;
} }
chip->irq = pci->irq; chip->irq = pci->irq;
card->sync_irq = chip->irq; card->sync_irq = chip->irq;
...@@ -672,11 +664,11 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, ...@@ -672,11 +664,11 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
err = oxygen_pcm_init(chip); err = oxygen_pcm_init(chip);
if (err < 0) if (err < 0)
goto err_card; return err;
err = oxygen_mixer_init(chip); err = oxygen_mixer_init(chip);
if (err < 0) if (err < 0)
goto err_card; return err;
if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) { if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) {
unsigned int info_flags = unsigned int info_flags =
...@@ -689,7 +681,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, ...@@ -689,7 +681,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
chip->addr + OXYGEN_MPU401, chip->addr + OXYGEN_MPU401,
info_flags, -1, &chip->midi); info_flags, -1, &chip->midi);
if (err < 0) if (err < 0)
goto err_card; return err;
} }
oxygen_proc_init(chip); oxygen_proc_init(chip);
...@@ -704,27 +696,13 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, ...@@ -704,27 +696,13 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto err_card; return err;
pci_set_drvdata(pci, card); pci_set_drvdata(pci, card);
return 0; return 0;
err_pci_regions:
pci_release_regions(pci);
err_pci_enable:
pci_disable_device(pci);
err_card:
snd_card_free(card);
return err;
} }
EXPORT_SYMBOL(oxygen_pci_probe); EXPORT_SYMBOL(oxygen_pci_probe);
void oxygen_pci_remove(struct pci_dev *pci)
{
snd_card_free(pci_get_drvdata(pci));
}
EXPORT_SYMBOL(oxygen_pci_remove);
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
static int oxygen_pci_suspend(struct device *dev) static int oxygen_pci_suspend(struct device *dev)
{ {
......
...@@ -137,7 +137,6 @@ static struct pci_driver se6x_driver = { ...@@ -137,7 +137,6 @@ static struct pci_driver se6x_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = se6x_ids, .id_table = se6x_ids,
.probe = se6x_probe, .probe = se6x_probe,
.remove = oxygen_pci_remove,
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
.driver = { .driver = {
.pm = &oxygen_pci_pm, .pm = &oxygen_pci_pm,
......
...@@ -82,7 +82,6 @@ static struct pci_driver xonar_driver = { ...@@ -82,7 +82,6 @@ static struct pci_driver xonar_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = xonar_ids, .id_table = xonar_ids,
.probe = xonar_probe, .probe = xonar_probe,
.remove = oxygen_pci_remove,
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
.driver = { .driver = {
.pm = &oxygen_pci_pm, .pm = &oxygen_pci_pm,
......
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