Commit c1ae5e7f authored by Takashi Iwai's avatar Takashi Iwai

ALSA: usb-audio: Unify audioformat release code

There are many open code for releasing audioformat object.
Provide a unified helper and call it from the all places.

Only a cleanup, no functional changes.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent dae02c8c
...@@ -28,6 +28,14 @@ ...@@ -28,6 +28,14 @@
#include "power.h" #include "power.h"
#include "media.h" #include "media.h"
static void audioformat_free(struct audioformat *fp)
{
list_del(&fp->list); /* unlink for avoiding double-free */
kfree(fp->rate_table);
kfree(fp->chmap);
kfree(fp);
}
/* /*
* free a substream * free a substream
*/ */
...@@ -37,11 +45,8 @@ static void free_substream(struct snd_usb_substream *subs) ...@@ -37,11 +45,8 @@ static void free_substream(struct snd_usb_substream *subs)
if (!subs->num_formats) if (!subs->num_formats)
return; /* not initialized */ return; /* not initialized */
list_for_each_entry_safe(fp, n, &subs->fmt_list, list) { list_for_each_entry_safe(fp, n, &subs->fmt_list, list)
kfree(fp->rate_table); audioformat_free(fp);
kfree(fp->chmap);
kfree(fp);
}
kfree(subs->rate_list.list); kfree(subs->rate_list.list);
kfree(subs->str_pd); kfree(subs->str_pd);
snd_media_stream_delete(subs); snd_media_stream_delete(subs);
...@@ -832,8 +837,7 @@ snd_usb_get_audioformat_uac12(struct snd_usb_audio *chip, ...@@ -832,8 +837,7 @@ snd_usb_get_audioformat_uac12(struct snd_usb_audio *chip,
/* ok, let's parse further... */ /* ok, let's parse further... */
if (snd_usb_parse_audio_format(chip, fp, format, if (snd_usb_parse_audio_format(chip, fp, format,
fmt, stream) < 0) { fmt, stream) < 0) {
kfree(fp->rate_table); audioformat_free(fp);
kfree(fp);
return NULL; return NULL;
} }
...@@ -1043,9 +1047,7 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip, ...@@ -1043,9 +1047,7 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip,
pd = kzalloc(sizeof(*pd), GFP_KERNEL); pd = kzalloc(sizeof(*pd), GFP_KERNEL);
if (!pd) { if (!pd) {
kfree(fp->chmap); audioformat_free(fp);
kfree(fp->rate_table);
kfree(fp);
return NULL; return NULL;
} }
pd->pd_id = (stream == SNDRV_PCM_STREAM_PLAYBACK) ? pd->pd_id = (stream == SNDRV_PCM_STREAM_PLAYBACK) ?
...@@ -1064,9 +1066,7 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip, ...@@ -1064,9 +1066,7 @@ snd_usb_get_audioformat_uac3(struct snd_usb_audio *chip,
/* ok, let's parse further... */ /* ok, let's parse further... */
if (snd_usb_parse_audio_format_v3(chip, fp, as, stream) < 0) { if (snd_usb_parse_audio_format_v3(chip, fp, as, stream) < 0) {
kfree(pd); kfree(pd);
kfree(fp->chmap); audioformat_free(fp);
kfree(fp->rate_table);
kfree(fp);
return NULL; return NULL;
} }
} }
...@@ -1185,11 +1185,8 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no) ...@@ -1185,11 +1185,8 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
err = snd_usb_add_audio_stream(chip, stream, fp); err = snd_usb_add_audio_stream(chip, stream, fp);
if (err < 0) { if (err < 0) {
list_del(&fp->list); /* unlink for avoiding double-free */ audioformat_free(fp);
kfree(pd); kfree(pd);
kfree(fp->rate_table);
kfree(fp->chmap);
kfree(fp);
return err; return err;
} }
/* try to set the interface... */ /* try to set the interface... */
......
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