Commit ec3acaa8 authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] Fix the release of resources at error path

Control Midlevel
Implemented free callback to fix the release of control resources
before calling register.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 47393b6a
...@@ -1324,19 +1324,13 @@ static int snd_ctl_dev_disconnect(snd_device_t *device) ...@@ -1324,19 +1324,13 @@ static int snd_ctl_dev_disconnect(snd_device_t *device)
} }
/* /*
* de-registration of the control device * free all controls
*/ */
static int snd_ctl_dev_unregister(snd_device_t *device) static int snd_ctl_dev_free(snd_device_t *device)
{ {
snd_card_t *card = device->device_data; snd_card_t *card = device->device_data;
int err, cardnum;
snd_kcontrol_t *control; snd_kcontrol_t *control;
snd_assert(card != NULL, return -ENXIO);
cardnum = card->number;
snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO);
if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, card, 0)) < 0)
return err;
down_write(&card->controls_rwsem); down_write(&card->controls_rwsem);
while (!list_empty(&card->controls)) { while (!list_empty(&card->controls)) {
control = snd_kcontrol(card->controls.next); control = snd_kcontrol(card->controls.next);
...@@ -1346,6 +1340,22 @@ static int snd_ctl_dev_unregister(snd_device_t *device) ...@@ -1346,6 +1340,22 @@ static int snd_ctl_dev_unregister(snd_device_t *device)
return 0; return 0;
} }
/*
* de-registration of the control device
*/
static int snd_ctl_dev_unregister(snd_device_t *device)
{
snd_card_t *card = device->device_data;
int err, cardnum;
snd_assert(card != NULL, return -ENXIO);
cardnum = card->number;
snd_assert(cardnum >= 0 && cardnum < SNDRV_CARDS, return -ENXIO);
if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, card, 0)) < 0)
return err;
return snd_ctl_dev_free(device);
}
/* /*
* create control core: * create control core:
* called from init.c * called from init.c
...@@ -1353,6 +1363,7 @@ static int snd_ctl_dev_unregister(snd_device_t *device) ...@@ -1353,6 +1363,7 @@ static int snd_ctl_dev_unregister(snd_device_t *device)
int snd_ctl_create(snd_card_t *card) int snd_ctl_create(snd_card_t *card)
{ {
static snd_device_ops_t ops = { static snd_device_ops_t ops = {
.dev_free = snd_ctl_dev_free,
.dev_register = snd_ctl_dev_register, .dev_register = snd_ctl_dev_register,
.dev_disconnect = snd_ctl_dev_disconnect, .dev_disconnect = snd_ctl_dev_disconnect,
.dev_unregister = snd_ctl_dev_unregister .dev_unregister = snd_ctl_dev_unregister
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment