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

ALSA: vx: Manage vx_core object with devres

The firmware data are also released automatically.

Link: https://lore.kernel.org/r/20210715075941.23332-50-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+10 -25
+10 -2
sound/drivers/vx/vx_core.c
··· 774 774 EXPORT_SYMBOL(snd_vx_resume); 775 775 #endif 776 776 777 + static void snd_vx_release(struct device *dev, void *data) 778 + { 779 + snd_vx_free_firmware(data); 780 + } 781 + 777 782 /** 778 783 * snd_vx_create - constructor for struct vx_core 779 784 * @card: card instance ··· 788 783 * 789 784 * this function allocates the instance and prepare for the hardware 790 785 * initialization. 786 + * 787 + * The object is managed via devres, and will be automatically released. 791 788 * 792 789 * return the instance pointer if successful, NULL in error. 793 790 */ ··· 803 796 if (snd_BUG_ON(!card || !hw || !ops)) 804 797 return NULL; 805 798 806 - chip = kzalloc(sizeof(*chip) + extra_size, GFP_KERNEL); 807 - if (! chip) 799 + chip = devres_alloc(snd_vx_release, sizeof(*chip) + extra_size, 800 + GFP_KERNEL); 801 + if (!chip) 808 802 return NULL; 809 803 mutex_init(&chip->lock); 810 804 chip->irq = -1;
-1
sound/pci/vx222/vx222.c
··· 109 109 if (vx->port[0]) 110 110 pci_release_regions(vx->pci); 111 111 pci_disable_device(vx->pci); 112 - kfree(chip); 113 112 return 0; 114 113 } 115 114
-22
sound/pcmcia/vx/vxpocket.c
··· 51 51 } 52 52 53 53 /* 54 - * destructor, called from snd_card_free_when_closed() 55 - */ 56 - static int snd_vxpocket_dev_free(struct snd_device *device) 57 - { 58 - struct vx_core *chip = device->device_data; 59 - 60 - snd_vx_free_firmware(chip); 61 - kfree(chip); 62 - return 0; 63 - } 64 - 65 - 66 - /* 67 54 * Hardware information 68 55 */ 69 56 ··· 109 122 { 110 123 struct vx_core *chip; 111 124 struct snd_vxpocket *vxp; 112 - static const struct snd_device_ops ops = { 113 - .dev_free = snd_vxpocket_dev_free, 114 - }; 115 - int err; 116 125 117 126 chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops, 118 127 sizeof(struct snd_vxpocket) - sizeof(struct vx_core)); 119 128 if (!chip) 120 129 return -ENOMEM; 121 130 122 - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); 123 - if (err < 0) { 124 - kfree(chip); 125 - return err; 126 - } 127 131 chip->ibl.size = ibl; 128 132 129 133 vxp = to_vxpocket(chip);