aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_codec.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-07-30 09:01:44 -0400
committerTakashi Iwai <tiwai@suse.de>2008-10-12 20:42:58 -0400
commitb2e1859745b783922533d29e3b03af29378a23f0 (patch)
treef71eba89ae3a5bd3f7a6e3640f62904872f5c071 /sound/pci/hda/hda_codec.c
parent176d5335fe66f379a339b0ab99cc7566e90ff1a9 (diff)
ALSA: hda - Add generic arrays
Added helper functions to handle generic arrays. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r--sound/pci/hda/hda_codec.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 19b4530e3baf..e70303183c3c 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -3196,3 +3196,37 @@ int snd_hda_codecs_inuse(struct hda_bus *bus)
3196} 3196}
3197#endif 3197#endif
3198#endif 3198#endif
3199
3200/*
3201 * generic arrays
3202 */
3203
3204/* get a new element from the given array
3205 * if it exceeds the pre-allocated array size, re-allocate the array
3206 */
3207void *snd_array_new(struct snd_array *array)
3208{
3209 if (array->used >= array->alloced) {
3210 int num = array->alloced + array->alloc_align;
3211 void *nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL);
3212 if (!nlist)
3213 return NULL;
3214 if (array->list) {
3215 memcpy(nlist, array->list,
3216 array->elem_size * array->alloced);
3217 kfree(array->list);
3218 }
3219 array->list = nlist;
3220 array->alloced = num;
3221 }
3222 return array->list + (array->used++ * array->elem_size);
3223}
3224
3225/* free the given array elements */
3226void snd_array_free(struct snd_array *array)
3227{
3228 kfree(array->list);
3229 array->used = 0;
3230 array->alloced = 0;
3231 array->list = NULL;
3232}