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

ALSA: adlib: Allocate resources with device-managed APIs

This patch converts the resource management in ISA adlib driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.  The remove callback became
superfluous and dropped.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-57-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent e031577e
...@@ -43,30 +43,23 @@ static int snd_adlib_match(struct device *dev, unsigned int n) ...@@ -43,30 +43,23 @@ static int snd_adlib_match(struct device *dev, unsigned int n)
return 1; return 1;
} }
static void snd_adlib_free(struct snd_card *card)
{
release_and_free_resource(card->private_data);
}
static int snd_adlib_probe(struct device *dev, unsigned int n) static int snd_adlib_probe(struct device *dev, unsigned int n)
{ {
struct snd_card *card; struct snd_card *card;
struct snd_opl3 *opl3; struct snd_opl3 *opl3;
int error; int error;
error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
if (error < 0) { if (error < 0) {
dev_err(dev, "could not create card\n"); dev_err(dev, "could not create card\n");
return error; return error;
} }
card->private_data = request_region(port[n], 4, CRD_NAME); card->private_data = devm_request_region(dev, port[n], 4, CRD_NAME);
if (!card->private_data) { if (!card->private_data) {
dev_err(dev, "could not grab ports\n"); dev_err(dev, "could not grab ports\n");
error = -EBUSY; return -EBUSY;
goto out;
} }
card->private_free = snd_adlib_free;
strcpy(card->driver, DEV_NAME); strcpy(card->driver, DEV_NAME);
strcpy(card->shortname, CRD_NAME); strcpy(card->shortname, CRD_NAME);
...@@ -75,37 +68,28 @@ static int snd_adlib_probe(struct device *dev, unsigned int n) ...@@ -75,37 +68,28 @@ static int snd_adlib_probe(struct device *dev, unsigned int n)
error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3); error = snd_opl3_create(card, port[n], port[n] + 2, OPL3_HW_AUTO, 1, &opl3);
if (error < 0) { if (error < 0) {
dev_err(dev, "could not create OPL\n"); dev_err(dev, "could not create OPL\n");
goto out; return error;
} }
error = snd_opl3_hwdep_new(opl3, 0, 0, NULL); error = snd_opl3_hwdep_new(opl3, 0, 0, NULL);
if (error < 0) { if (error < 0) {
dev_err(dev, "could not create FM\n"); dev_err(dev, "could not create FM\n");
goto out; return error;
} }
error = snd_card_register(card); error = snd_card_register(card);
if (error < 0) { if (error < 0) {
dev_err(dev, "could not register card\n"); dev_err(dev, "could not register card\n");
goto out; return error;
} }
dev_set_drvdata(dev, card); dev_set_drvdata(dev, card);
return 0; return 0;
out: snd_card_free(card);
return error;
}
static void snd_adlib_remove(struct device *dev, unsigned int n)
{
snd_card_free(dev_get_drvdata(dev));
} }
static struct isa_driver snd_adlib_driver = { static struct isa_driver snd_adlib_driver = {
.match = snd_adlib_match, .match = snd_adlib_match,
.probe = snd_adlib_probe, .probe = snd_adlib_probe,
.remove = snd_adlib_remove,
.driver = { .driver = {
.name = DEV_NAME .name = DEV_NAME
......
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