Skip to content

Commit de74763

Browse files
committed
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>
1 parent 60d03de commit de74763

1 file changed

Lines changed: 5 additions & 29 deletions

File tree

sound/drivers/mpu401/mpu401.c

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ static int snd_mpu401_create(struct device *devptr, int dev,
5959
snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n");
6060

6161
*rcard = NULL;
62-
err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
63-
0, &card);
62+
err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE,
63+
0, &card);
6464
if (err < 0)
6565
return err;
6666
strcpy(card->driver, "MPU-401 UART");
@@ -76,15 +76,11 @@ static int snd_mpu401_create(struct device *devptr, int dev,
7676
irq[dev], NULL);
7777
if (err < 0) {
7878
printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
79-
goto _err;
79+
return err;
8080
}
8181

8282
*rcard = card;
8383
return 0;
84-
85-
_err:
86-
snd_card_free(card);
87-
return err;
8884
}
8985

9086
static int snd_mpu401_probe(struct platform_device *devptr)
@@ -105,25 +101,16 @@ static int snd_mpu401_probe(struct platform_device *devptr)
105101
if (err < 0)
106102
return err;
107103
err = snd_card_register(card);
108-
if (err < 0) {
109-
snd_card_free(card);
104+
if (err < 0)
110105
return err;
111-
}
112106
platform_set_drvdata(devptr, card);
113107
return 0;
114108
}
115109

116-
static int snd_mpu401_remove(struct platform_device *devptr)
117-
{
118-
snd_card_free(platform_get_drvdata(devptr));
119-
return 0;
120-
}
121-
122110
#define SND_MPU401_DRIVER "snd_mpu401"
123111

124112
static struct platform_driver snd_mpu401_driver = {
125113
.probe = snd_mpu401_probe,
126-
.remove = snd_mpu401_remove,
127114
.driver = {
128115
.name = SND_MPU401_DRIVER,
129116
},
@@ -184,10 +171,8 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
184171
if (err < 0)
185172
return err;
186173
err = snd_card_register(card);
187-
if (err < 0) {
188-
snd_card_free(card);
174+
if (err < 0)
189175
return err;
190-
}
191176
pnp_set_drvdata(pnp_dev, card);
192177
snd_mpu401_devices++;
193178
++dev;
@@ -196,19 +181,10 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
196181
return -ENODEV;
197182
}
198183

199-
static void snd_mpu401_pnp_remove(struct pnp_dev *dev)
200-
{
201-
struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev);
202-
203-
snd_card_disconnect(card);
204-
snd_card_free_when_closed(card);
205-
}
206-
207184
static struct pnp_driver snd_mpu401_pnp_driver = {
208185
.name = "mpu401",
209186
.id_table = snd_mpu401_pnpids,
210187
.probe = snd_mpu401_pnp_probe,
211-
.remove = snd_mpu401_pnp_remove,
212188
};
213189
#else
214190
static struct pnp_driver snd_mpu401_pnp_driver;

0 commit comments

Comments
 (0)