forked from Minki/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>
This commit is contained in:
parent
5adfd8c266
commit
a033954140
@ -774,6 +774,11 @@ int snd_vx_resume(struct vx_core *chip)
|
|||||||
EXPORT_SYMBOL(snd_vx_resume);
|
EXPORT_SYMBOL(snd_vx_resume);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void snd_vx_release(struct device *dev, void *data)
|
||||||
|
{
|
||||||
|
snd_vx_free_firmware(data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* snd_vx_create - constructor for struct vx_core
|
* snd_vx_create - constructor for struct vx_core
|
||||||
* @card: card instance
|
* @card: card instance
|
||||||
@ -784,6 +789,8 @@ EXPORT_SYMBOL(snd_vx_resume);
|
|||||||
* this function allocates the instance and prepare for the hardware
|
* this function allocates the instance and prepare for the hardware
|
||||||
* initialization.
|
* initialization.
|
||||||
*
|
*
|
||||||
|
* The object is managed via devres, and will be automatically released.
|
||||||
|
*
|
||||||
* return the instance pointer if successful, NULL in error.
|
* return the instance pointer if successful, NULL in error.
|
||||||
*/
|
*/
|
||||||
struct vx_core *snd_vx_create(struct snd_card *card,
|
struct vx_core *snd_vx_create(struct snd_card *card,
|
||||||
@ -796,7 +803,8 @@ struct vx_core *snd_vx_create(struct snd_card *card,
|
|||||||
if (snd_BUG_ON(!card || !hw || !ops))
|
if (snd_BUG_ON(!card || !hw || !ops))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
chip = kzalloc(sizeof(*chip) + extra_size, GFP_KERNEL);
|
chip = devres_alloc(snd_vx_release, sizeof(*chip) + extra_size,
|
||||||
|
GFP_KERNEL);
|
||||||
if (!chip)
|
if (!chip)
|
||||||
return NULL;
|
return NULL;
|
||||||
mutex_init(&chip->lock);
|
mutex_init(&chip->lock);
|
||||||
|
@ -109,7 +109,6 @@ static int snd_vx222_free(struct vx_core *chip)
|
|||||||
if (vx->port[0])
|
if (vx->port[0])
|
||||||
pci_release_regions(vx->pci);
|
pci_release_regions(vx->pci);
|
||||||
pci_disable_device(vx->pci);
|
pci_disable_device(vx->pci);
|
||||||
kfree(chip);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,19 +50,6 @@ static void vxpocket_release(struct pcmcia_device *link)
|
|||||||
pcmcia_disable_device(link);
|
pcmcia_disable_device(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* destructor, called from snd_card_free_when_closed()
|
|
||||||
*/
|
|
||||||
static int snd_vxpocket_dev_free(struct snd_device *device)
|
|
||||||
{
|
|
||||||
struct vx_core *chip = device->device_data;
|
|
||||||
|
|
||||||
snd_vx_free_firmware(chip);
|
|
||||||
kfree(chip);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hardware information
|
* Hardware information
|
||||||
*/
|
*/
|
||||||
@ -122,21 +109,12 @@ static int snd_vxpocket_new(struct snd_card *card, int ibl,
|
|||||||
{
|
{
|
||||||
struct vx_core *chip;
|
struct vx_core *chip;
|
||||||
struct snd_vxpocket *vxp;
|
struct snd_vxpocket *vxp;
|
||||||
static const struct snd_device_ops ops = {
|
|
||||||
.dev_free = snd_vxpocket_dev_free,
|
|
||||||
};
|
|
||||||
int err;
|
|
||||||
|
|
||||||
chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops,
|
chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops,
|
||||||
sizeof(struct snd_vxpocket) - sizeof(struct vx_core));
|
sizeof(struct snd_vxpocket) - sizeof(struct vx_core));
|
||||||
if (!chip)
|
if (!chip)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
|
|
||||||
if (err < 0) {
|
|
||||||
kfree(chip);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
chip->ibl.size = ibl;
|
chip->ibl.size = ibl;
|
||||||
|
|
||||||
vxp = to_vxpocket(chip);
|
vxp = to_vxpocket(chip);
|
||||||
|
Loading…
Reference in New Issue
Block a user