mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 04:18:39 +08:00
ALSA: mpu401: Allocate resources with device-managed APIs
This patch converts the card object management with devres as a clean up. The remove callback gets reduced by that. This should give no user-visible functional changes. Note that this converts only the mpu401 card driver. The mpu401_uart component is still managed with snd_device. It's for the case where the mpu401_uart component may be removed dynamically without the actual device unbind. Link: https://lore.kernel.org/r/20210715075941.23332-77-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
60d03de81c
commit
de74763295
@ -59,8 +59,8 @@ static int snd_mpu401_create(struct device *devptr, int dev,
|
||||
snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n");
|
||||
|
||||
*rcard = NULL;
|
||||
err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
|
||||
0, &card);
|
||||
err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE,
|
||||
0, &card);
|
||||
if (err < 0)
|
||||
return err;
|
||||
strcpy(card->driver, "MPU-401 UART");
|
||||
@ -76,15 +76,11 @@ static int snd_mpu401_create(struct device *devptr, int dev,
|
||||
irq[dev], NULL);
|
||||
if (err < 0) {
|
||||
printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
|
||||
goto _err;
|
||||
return err;
|
||||
}
|
||||
|
||||
*rcard = card;
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
snd_card_free(card);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int snd_mpu401_probe(struct platform_device *devptr)
|
||||
@ -105,25 +101,16 @@ static int snd_mpu401_probe(struct platform_device *devptr)
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_card_register(card);
|
||||
if (err < 0) {
|
||||
snd_card_free(card);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
platform_set_drvdata(devptr, card);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_mpu401_remove(struct platform_device *devptr)
|
||||
{
|
||||
snd_card_free(platform_get_drvdata(devptr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SND_MPU401_DRIVER "snd_mpu401"
|
||||
|
||||
static struct platform_driver snd_mpu401_driver = {
|
||||
.probe = snd_mpu401_probe,
|
||||
.remove = snd_mpu401_remove,
|
||||
.driver = {
|
||||
.name = SND_MPU401_DRIVER,
|
||||
},
|
||||
@ -184,10 +171,8 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_card_register(card);
|
||||
if (err < 0) {
|
||||
snd_card_free(card);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
pnp_set_drvdata(pnp_dev, card);
|
||||
snd_mpu401_devices++;
|
||||
++dev;
|
||||
@ -196,19 +181,10 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
static void snd_mpu401_pnp_remove(struct pnp_dev *dev)
|
||||
{
|
||||
struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev);
|
||||
|
||||
snd_card_disconnect(card);
|
||||
snd_card_free_when_closed(card);
|
||||
}
|
||||
|
||||
static struct pnp_driver snd_mpu401_pnp_driver = {
|
||||
.name = "mpu401",
|
||||
.id_table = snd_mpu401_pnpids,
|
||||
.probe = snd_mpu401_pnp_probe,
|
||||
.remove = snd_mpu401_pnp_remove,
|
||||
};
|
||||
#else
|
||||
static struct pnp_driver snd_mpu401_pnp_driver;
|
||||
|
Loading…
Reference in New Issue
Block a user