From a033954140ac43a8ce0eab469229a107cfee1c87 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 15 Jul 2021 09:59:11 +0200 Subject: 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 --- sound/drivers/vx/vx_core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sound/drivers') diff --git a/sound/drivers/vx/vx_core.c b/sound/drivers/vx/vx_core.c index a10449af5a76..18901e5bcfcf 100644 --- a/sound/drivers/vx/vx_core.c +++ b/sound/drivers/vx/vx_core.c @@ -774,6 +774,11 @@ int snd_vx_resume(struct vx_core *chip) EXPORT_SYMBOL(snd_vx_resume); #endif +static void snd_vx_release(struct device *dev, void *data) +{ + snd_vx_free_firmware(data); +} + /** * snd_vx_create - constructor for struct vx_core * @card: card instance @@ -784,6 +789,8 @@ EXPORT_SYMBOL(snd_vx_resume); * this function allocates the instance and prepare for the hardware * initialization. * + * The object is managed via devres, and will be automatically released. + * * return the instance pointer if successful, NULL in error. */ struct vx_core *snd_vx_create(struct snd_card *card, @@ -796,8 +803,9 @@ struct vx_core *snd_vx_create(struct snd_card *card, if (snd_BUG_ON(!card || !hw || !ops)) return NULL; - chip = kzalloc(sizeof(*chip) + extra_size, GFP_KERNEL); - if (! chip) + chip = devres_alloc(snd_vx_release, sizeof(*chip) + extra_size, + GFP_KERNEL); + if (!chip) return NULL; mutex_init(&chip->lock); chip->irq = -1; -- cgit v1.2.3