summaryrefslogtreecommitdiff
path: root/sound/hda/array.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-04-04 12:15:32 +0200
committerTakashi Iwai <tiwai@suse.de>2015-04-04 12:16:30 +0200
commit664bc5c55923712a8aabd2a390ed7477325e32df (patch)
tree6382fd31d0fab7699fb2ff6b0501275700dd5b85 /sound/hda/array.c
parentffda568e8b4979c6a04bbdd92acfd93b5dc5e163 (diff)
parent9d82f9272ddd8492afdd721c9999171741be835b (diff)
downloadlinux-next-664bc5c55923712a8aabd2a390ed7477325e32df.tar.gz
Merge branch 'topic/hda-regmap' into for-next
This merges the support of regmap in HD-audio infrastructure. Many in-house cache codes in HD-audio driver are relaced with the more standard regmap base now. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/hda/array.c')
-rw-r--r--sound/hda/array.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/sound/hda/array.c b/sound/hda/array.c
new file mode 100644
index 000000000000..516795baa7db
--- /dev/null
+++ b/sound/hda/array.c
@@ -0,0 +1,49 @@
+/*
+ * generic arrays
+ */
+
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/hdaudio.h>
+
+/**
+ * snd_array_new - get a new element from the given array
+ * @array: the array object
+ *
+ * Get a new element from the given array. If it exceeds the
+ * pre-allocated array size, re-allocate the array.
+ *
+ * Returns NULL if allocation failed.
+ */
+void *snd_array_new(struct snd_array *array)
+{
+ if (snd_BUG_ON(!array->elem_size))
+ return NULL;
+ if (array->used >= array->alloced) {
+ int num = array->alloced + array->alloc_align;
+ int size = (num + 1) * array->elem_size;
+ void *nlist;
+ if (snd_BUG_ON(num >= 4096))
+ return NULL;
+ nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO);
+ if (!nlist)
+ return NULL;
+ array->list = nlist;
+ array->alloced = num;
+ }
+ return snd_array_elem(array, array->used++);
+}
+EXPORT_SYMBOL_GPL(snd_array_new);
+
+/**
+ * snd_array_free - free the given array elements
+ * @array: the array object
+ */
+void snd_array_free(struct snd_array *array)
+{
+ kfree(array->list);
+ array->used = 0;
+ array->alloced = 0;
+ array->list = NULL;
+}
+EXPORT_SYMBOL_GPL(snd_array_free);