aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-03-03 11:33:10 -0500
committerTakashi Iwai <tiwai@suse.de>2015-03-23 08:19:35 -0400
commit71fc4c7ef5ef2d0ddd22f0545ede4c135b554b84 (patch)
tree2fad250a6c6f229aabd6b1aab41d24a50da511d9 /sound/pci/hda
parente311782acd196d17d25b323d115709c50c8f7d3f (diff)
ALSA: hda - Move generic array helpers to core lib
This will be used by the regmap support. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda')
-rw-r--r--sound/pci/hda/hda_codec.c46
-rw-r--r--sound/pci/hda/hda_codec.h30
2 files changed, 0 insertions, 76 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 145cae7903b6..10e257ff9084 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -5012,52 +5012,6 @@ void snd_hda_bus_reset(struct hda_bus *bus)
5012} 5012}
5013EXPORT_SYMBOL_GPL(snd_hda_bus_reset); 5013EXPORT_SYMBOL_GPL(snd_hda_bus_reset);
5014 5014
5015/*
5016 * generic arrays
5017 */
5018
5019/**
5020 * snd_array_new - get a new element from the given array
5021 * @array: the array object
5022 *
5023 * Get a new element from the given array. If it exceeds the
5024 * pre-allocated array size, re-allocate the array.
5025 *
5026 * Returns NULL if allocation failed.
5027 */
5028void *snd_array_new(struct snd_array *array)
5029{
5030 if (snd_BUG_ON(!array->elem_size))
5031 return NULL;
5032 if (array->used >= array->alloced) {
5033 int num = array->alloced + array->alloc_align;
5034 int size = (num + 1) * array->elem_size;
5035 void *nlist;
5036 if (snd_BUG_ON(num >= 4096))
5037 return NULL;
5038 nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO);
5039 if (!nlist)
5040 return NULL;
5041 array->list = nlist;
5042 array->alloced = num;
5043 }
5044 return snd_array_elem(array, array->used++);
5045}
5046EXPORT_SYMBOL_GPL(snd_array_new);
5047
5048/**
5049 * snd_array_free - free the given array elements
5050 * @array: the array object
5051 */
5052void snd_array_free(struct snd_array *array)
5053{
5054 kfree(array->list);
5055 array->used = 0;
5056 array->alloced = 0;
5057 array->list = NULL;
5058}
5059EXPORT_SYMBOL_GPL(snd_array_free);
5060
5061/** 5015/**
5062 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer 5016 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
5063 * @pcm: PCM caps bits 5017 * @pcm: PCM caps bits
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 76776164623d..3068163b3db2 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -30,36 +30,6 @@
30#include <sound/hda_verbs.h> 30#include <sound/hda_verbs.h>
31 31
32/* 32/*
33 * generic arrays
34 */
35struct snd_array {
36 unsigned int used;
37 unsigned int alloced;
38 unsigned int elem_size;
39 unsigned int alloc_align;
40 void *list;
41};
42
43void *snd_array_new(struct snd_array *array);
44void snd_array_free(struct snd_array *array);
45static inline void snd_array_init(struct snd_array *array, unsigned int size,
46 unsigned int align)
47{
48 array->elem_size = size;
49 array->alloc_align = align;
50}
51
52static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
53{
54 return array->list + idx * array->elem_size;
55}
56
57static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
58{
59 return (unsigned long)(ptr - array->list) / array->elem_size;
60}
61
62/*
63 * Structures 33 * Structures
64 */ 34 */
65 35