Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+5 -29
+5 -29
sound/drivers/mpu401/mpu401.c
··· 59 59 snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n"); 60 60 61 61 *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); 64 64 if (err < 0) 65 65 return err; 66 66 strcpy(card->driver, "MPU-401 UART"); ··· 76 76 irq[dev], NULL); 77 77 if (err < 0) { 78 78 printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]); 79 - goto _err; 79 + return err; 80 80 } 81 81 82 82 *rcard = card; 83 83 return 0; 84 - 85 - _err: 86 - snd_card_free(card); 87 - return err; 88 84 } 89 85 90 86 static int snd_mpu401_probe(struct platform_device *devptr) ··· 101 105 if (err < 0) 102 106 return err; 103 107 err = snd_card_register(card); 104 - if (err < 0) { 105 - snd_card_free(card); 108 + if (err < 0) 106 109 return err; 107 - } 108 110 platform_set_drvdata(devptr, card); 109 - return 0; 110 - } 111 - 112 - static int snd_mpu401_remove(struct platform_device *devptr) 113 - { 114 - snd_card_free(platform_get_drvdata(devptr)); 115 111 return 0; 116 112 } 117 113 ··· 111 123 112 124 static struct platform_driver snd_mpu401_driver = { 113 125 .probe = snd_mpu401_probe, 114 - .remove = snd_mpu401_remove, 115 126 .driver = { 116 127 .name = SND_MPU401_DRIVER, 117 128 }, ··· 171 184 if (err < 0) 172 185 return err; 173 186 err = snd_card_register(card); 174 - if (err < 0) { 175 - snd_card_free(card); 187 + if (err < 0) 176 188 return err; 177 - } 178 189 pnp_set_drvdata(pnp_dev, card); 179 190 snd_mpu401_devices++; 180 191 ++dev; ··· 181 196 return -ENODEV; 182 197 } 183 198 184 - static void snd_mpu401_pnp_remove(struct pnp_dev *dev) 185 - { 186 - struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev); 187 - 188 - snd_card_disconnect(card); 189 - snd_card_free_when_closed(card); 190 - } 191 - 192 199 static struct pnp_driver snd_mpu401_pnp_driver = { 193 200 .name = "mpu401", 194 201 .id_table = snd_mpu401_pnpids, 195 202 .probe = snd_mpu401_pnp_probe, 196 - .remove = snd_mpu401_pnp_remove, 197 203 }; 198 204 #else 199 205 static struct pnp_driver snd_mpu401_pnp_driver;