Commit 21a9314c authored by Takashi Iwai's avatar Takashi Iwai

ALSA: als300: Allocate resources with device-managed APIs

This patch converts the resource management in PCI als300 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-10-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 567f5875
...@@ -163,21 +163,11 @@ static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd) ...@@ -163,21 +163,11 @@ static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd)
snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp); snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp);
} }
static int snd_als300_free(struct snd_als300 *chip) static void snd_als300_free(struct snd_card *card)
{ {
snd_als300_set_irq_flag(chip, IRQ_DISABLE); struct snd_als300 *chip = card->private_data;
if (chip->irq >= 0)
free_irq(chip->irq, chip);
pci_release_regions(chip->pci);
pci_disable_device(chip->pci);
kfree(chip);
return 0;
}
static int snd_als300_dev_free(struct snd_device *device) snd_als300_set_irq_flag(chip, IRQ_DISABLE);
{
struct snd_als300 *chip = device->device_data;
return snd_als300_free(chip);
} }
static irqreturn_t snd_als300_interrupt(int irq, void *dev_id) static irqreturn_t snd_als300_interrupt(int irq, void *dev_id)
...@@ -248,11 +238,6 @@ static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id) ...@@ -248,11 +238,6 @@ static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static void snd_als300_remove(struct pci_dev *pci)
{
snd_card_free(pci_get_drvdata(pci));
}
static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97, static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97,
unsigned short reg) unsigned short reg)
{ {
...@@ -610,35 +595,22 @@ static void snd_als300_init(struct snd_als300 *chip) ...@@ -610,35 +595,22 @@ static void snd_als300_init(struct snd_als300 *chip)
} }
static int snd_als300_create(struct snd_card *card, static int snd_als300_create(struct snd_card *card,
struct pci_dev *pci, int chip_type, struct pci_dev *pci, int chip_type)
struct snd_als300 **rchip)
{ {
struct snd_als300 *chip; struct snd_als300 *chip = card->private_data;
void *irq_handler; void *irq_handler;
int err; int err;
static const struct snd_device_ops ops = { err = pcim_enable_device(pci);
.dev_free = snd_als300_dev_free,
};
*rchip = NULL;
err = pci_enable_device(pci);
if (err < 0) if (err < 0)
return err; return err;
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, "error setting 28bit DMA mask\n"); dev_err(card->dev, "error setting 28bit DMA mask\n");
pci_disable_device(pci);
return -ENXIO; return -ENXIO;
} }
pci_set_master(pci); pci_set_master(pci);
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
if (chip == NULL) {
pci_disable_device(pci);
return -ENOMEM;
}
chip->card = card; chip->card = card;
chip->pci = pci; chip->pci = pci;
chip->irq = -1; chip->irq = -1;
...@@ -646,11 +618,9 @@ static int snd_als300_create(struct snd_card *card, ...@@ -646,11 +618,9 @@ static int snd_als300_create(struct snd_card *card,
spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->reg_lock);
err = pci_request_regions(pci, "ALS300"); err = pci_request_regions(pci, "ALS300");
if (err < 0) { if (err < 0)
kfree(chip);
pci_disable_device(pci);
return err; return err;
}
chip->port = pci_resource_start(pci, 0); chip->port = pci_resource_start(pci, 0);
if (chip->chip_type == DEVICE_ALS300_PLUS) if (chip->chip_type == DEVICE_ALS300_PLUS)
...@@ -658,38 +628,29 @@ static int snd_als300_create(struct snd_card *card, ...@@ -658,38 +628,29 @@ static int snd_als300_create(struct snd_card *card,
else else
irq_handler = snd_als300_interrupt; irq_handler = snd_als300_interrupt;
if (request_irq(pci->irq, irq_handler, IRQF_SHARED, if (devm_request_irq(&pci->dev, pci->irq, irq_handler, 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);
snd_als300_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_als300_free;
snd_als300_init(chip); snd_als300_init(chip);
err = snd_als300_ac97(chip); err = snd_als300_ac97(chip);
if (err < 0) { if (err < 0) {
dev_err(card->dev, "Could not create ac97\n"); dev_err(card->dev, "Could not create ac97\n");
snd_als300_free(chip);
return err; return err;
} }
err = snd_als300_new_pcm(chip); err = snd_als300_new_pcm(chip);
if (err < 0) { if (err < 0) {
dev_err(card->dev, "Could not create PCM\n"); dev_err(card->dev, "Could not create PCM\n");
snd_als300_free(chip);
return err;
}
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
snd_als300_free(chip);
return err; return err;
} }
*rchip = chip;
return 0; return 0;
} }
...@@ -737,20 +698,16 @@ static int snd_als300_probe(struct pci_dev *pci, ...@@ -737,20 +698,16 @@ static int snd_als300_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_type = pci_id->driver_data; chip_type = pci_id->driver_data;
err = snd_als300_create(card, pci, chip_type, &chip); err = snd_als300_create(card, pci, chip_type);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
card->private_data = chip;
strcpy(card->driver, "ALS300"); strcpy(card->driver, "ALS300");
if (chip->chip_type == DEVICE_ALS300_PLUS) if (chip->chip_type == DEVICE_ALS300_PLUS)
...@@ -764,10 +721,9 @@ static int snd_als300_probe(struct pci_dev *pci, ...@@ -764,10 +721,9 @@ static int snd_als300_probe(struct pci_dev *pci,
card->shortname, chip->port, chip->irq); card->shortname, chip->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;
...@@ -777,7 +733,6 @@ static struct pci_driver als300_driver = { ...@@ -777,7 +733,6 @@ static struct pci_driver als300_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = snd_als300_ids, .id_table = snd_als300_ids,
.probe = snd_als300_probe, .probe = snd_als300_probe,
.remove = snd_als300_remove,
.driver = { .driver = {
.pm = SND_ALS300_PM_OPS, .pm = SND_ALS300_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