aboutsummaryrefslogtreecommitdiffstats
path: root/sound/hda/core/array.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2025-07-09 18:04:05 +0200
committerTakashi Iwai <tiwai@suse.de>2025-07-11 09:55:36 +0200
commitb2660d1ebde1ba8f3edf963f3aac2bea884457c3 (patch)
treefac0ac69b4e1c770c8f8d0f42469e4a14801c9c0 /sound/hda/core/array.c
parentALSA: hda: Move widget capability macros into hdaudio.h (diff)
downloadlinux-b2660d1ebde1ba8f3edf963f3aac2bea884457c3.tar.gz
linux-b2660d1ebde1ba8f3edf963f3aac2bea884457c3.zip
ALSA: hda: Move HD-audio core stuff into sound/hda/core
This is a part of HD-audio code restructuring. Simply move the current code of sound/hda/* into the subdirectory sound/hda/core, so that more stuff can be moved into sound/hda cleanly later. Most of file names with hdac_ and hdac_ext_ prefix are renamed without the prefix, since they can be identified well in the directory name and superfluous. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250709160434.1859-3-tiwai@suse.de
Diffstat (limited to 'sound/hda/core/array.c')
-rw-r--r--sound/hda/core/array.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/sound/hda/core/array.c b/sound/hda/core/array.c
new file mode 100644
index 000000000000..a204dcee0034
--- /dev/null
+++ b/sound/hda/core/array.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * 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 oldsize = array->alloced * array->elem_size;
+ int size = (num + 1) * array->elem_size;
+ void *nlist;
+ if (snd_BUG_ON(num >= 4096))
+ return NULL;
+ nlist = krealloc(array->list, size, GFP_KERNEL);
+ if (!nlist)
+ return NULL;
+ memset(nlist + oldsize, 0, size - oldsize);
+ 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);