]>
Commit | Line | Data |
---|---|---|
2cb7cef9 BS |
1 | From: Takashi Iwai <tiwai@suse.de> |
2 | Subject: ALSA: Backport snd_array_*() for HD-audio driver | |
3 | Patch-mainline: | |
4 | References: bnc#511306 | |
5 | ||
6 | Backport snd_array_*() from the recent kernel to update the | |
7 | HD-audio driver code. | |
8 | ||
9 | Signed-off-by: Takashi Iwai <tiwai@suse.de> | |
10 | ||
11 | --- | |
12 | sound/pci/hda/hda_codec.c | 37 +++++++++++++++++++++++++++++++++++++ | |
13 | sound/pci/hda/hda_codec.h | 30 ++++++++++++++++++++++++++++++ | |
14 | 2 files changed, 67 insertions(+) | |
15 | ||
16 | --- a/sound/pci/hda/hda_codec.c | |
17 | +++ b/sound/pci/hda/hda_codec.c | |
18 | @@ -3366,6 +3366,43 @@ | |
19 | #endif | |
20 | ||
21 | /* | |
22 | + * generic arrays | |
23 | + */ | |
24 | + | |
25 | +/* get a new element from the given array | |
26 | + * if it exceeds the pre-allocated array size, re-allocate the array | |
27 | + */ | |
28 | +void *snd_array_new(struct snd_array *array) | |
29 | +{ | |
30 | + if (array->used >= array->alloced) { | |
31 | + int num = array->alloced + array->alloc_align; | |
32 | + void *nlist; | |
33 | + if (num >= 4096) | |
34 | + return NULL; | |
35 | + nlist = kcalloc(num + 1, array->elem_size, GFP_KERNEL); | |
36 | + if (!nlist) | |
37 | + return NULL; | |
38 | + if (array->list) { | |
39 | + memcpy(nlist, array->list, | |
40 | + array->elem_size * array->alloced); | |
41 | + kfree(array->list); | |
42 | + } | |
43 | + array->list = nlist; | |
44 | + array->alloced = num; | |
45 | + } | |
46 | + return snd_array_elem(array, array->used++); | |
47 | +} | |
48 | + | |
49 | +/* free the given array elements */ | |
50 | +void snd_array_free(struct snd_array *array) | |
51 | +{ | |
52 | + kfree(array->list); | |
53 | + array->used = 0; | |
54 | + array->alloced = 0; | |
55 | + array->list = NULL; | |
56 | +} | |
57 | + | |
58 | +/* | |
59 | * used by hda_proc.c and hda_eld.c | |
60 | */ | |
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 | |
64 | @@ -520,6 +520,36 @@ | |
65 | #define HDA_MAX_CODEC_ADDRESS 0x0f | |
66 | ||
67 | /* | |
68 | + * generic arrays | |
69 | + */ | |
70 | +struct snd_array { | |
71 | + unsigned int used; | |
72 | + unsigned int alloced; | |
73 | + unsigned int elem_size; | |
74 | + unsigned int alloc_align; | |
75 | + void *list; | |
76 | +}; | |
77 | + | |
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, | |
81 | + unsigned int align) | |
82 | +{ | |
83 | + array->elem_size = size; | |
84 | + array->alloc_align = align; | |
85 | +} | |
86 | + | |
87 | +static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) | |
88 | +{ | |
89 | + return array->list + idx * array->elem_size; | |
90 | +} | |
91 | + | |
92 | +static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) | |
93 | +{ | |
94 | + return (unsigned long)(ptr - array->list) / array->elem_size; | |
95 | +} | |
96 | + | |
97 | +/* | |
98 | * Structures | |
99 | */ | |
100 |