1 From: Takashi Iwai <tiwai@suse.de>
2 Subject: ALSA: Backport snd_array_*() for HD-audio driver
6 Backport snd_array_*() from the recent kernel to update the
9 Signed-off-by: Takashi Iwai <tiwai@suse.de>
12 sound/pci/hda/hda_codec.c | 37 +++++++++++++++++++++++++++++++++++++
13 sound/pci/hda/hda_codec.h | 30 ++++++++++++++++++++++++++++++
14 2 files changed, 67 insertions(+)
16 --- a/sound/pci/hda/hda_codec.c
17 +++ b/sound/pci/hda/hda_codec.c
18 @@ -3366,6 +3366,43 @@
25 +/* get a new element from the given array
26 + * if it exceeds the pre-allocated array size, re-allocate the array
28 +void *snd_array_new(struct snd_array *array)
30 + if (array->used >= array->alloced) {
31 + int num = array->alloced + array->alloc_align;
35 + nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL);
39 + memcpy(nlist, array->list,
40 + array->elem_size * array->alloced);
43 + array->list = nlist;
44 + array->alloced = num;
46 + return snd_array_elem(array, array->used++);
49 +/* free the given array elements */
50 +void snd_array_free(struct snd_array *array)
59 * used by hda_proc.c and hda_eld.c
61 void snd_print_pcm_rates(int pcm, char *buf, int buflen)
62 --- a/sound/pci/hda/hda_codec.h
63 +++ b/sound/pci/hda/hda_codec.h
65 #define HDA_MAX_CODEC_ADDRESS 0x0f
72 + unsigned int alloced;
73 + unsigned int elem_size;
74 + unsigned int alloc_align;
78 +void *snd_array_new(struct snd_array *array);
79 +void snd_array_free(struct snd_array *array);
80 +static inline void snd_array_init(struct snd_array *array, unsigned int size,
83 + array->elem_size = size;
84 + array->alloc_align = align;
87 +static inline void *snd_array_elem(struct snd_array *array, unsigned int idx)
89 + return array->list + idx * array->elem_size;
92 +static inline unsigned int snd_array_index(struct snd_array *array, void *ptr)
94 + return (unsigned long)(ptr - array->list) / array->elem_size;