Loading include/sound/hdaudio.h +33 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,17 @@ struct hdac_widget_tree; */ extern struct bus_type snd_hda_bus_type; /* * generic arrays */ struct snd_array { unsigned int used; unsigned int alloced; unsigned int elem_size; unsigned int alloc_align; void *list; }; /* * HD-audio codec base device */ Loading Loading @@ -178,4 +189,26 @@ static inline void snd_hdac_codec_link_down(struct hdac_device *codec) clear_bit(codec->addr, &codec->bus->codec_powered); } /* * generic array helpers */ void *snd_array_new(struct snd_array *array); void snd_array_free(struct snd_array *array); static inline void snd_array_init(struct snd_array *array, unsigned int size, unsigned int align) { array->elem_size = size; array->alloc_align = align; } static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) { return array->list + idx * array->elem_size; } static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) { return (unsigned long)(ptr - array->list) / array->elem_size; } #endif /* __SOUND_HDAUDIO_H */ sound/hda/Makefile +2 −1 Original line number Diff line number Diff line snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \ array.o snd-hda-core-objs += trace.o CFLAGS_trace.o := -I$(src) Loading sound/hda/array.c 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * 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); sound/pci/hda/hda_codec.c +0 −46 Original line number Diff line number Diff line Loading @@ -5012,52 +5012,6 @@ void snd_hda_bus_reset(struct hda_bus *bus) } EXPORT_SYMBOL_GPL(snd_hda_bus_reset); /* * generic arrays */ /** * 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); /** * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer * @pcm: PCM caps bits Loading sound/pci/hda/hda_codec.h +0 −30 Original line number Diff line number Diff line Loading @@ -29,36 +29,6 @@ #include <sound/hdaudio.h> #include <sound/hda_verbs.h> /* * generic arrays */ struct snd_array { unsigned int used; unsigned int alloced; unsigned int elem_size; unsigned int alloc_align; void *list; }; void *snd_array_new(struct snd_array *array); void snd_array_free(struct snd_array *array); static inline void snd_array_init(struct snd_array *array, unsigned int size, unsigned int align) { array->elem_size = size; array->alloc_align = align; } static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) { return array->list + idx * array->elem_size; } static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) { return (unsigned long)(ptr - array->list) / array->elem_size; } /* * Structures */ Loading Loading
include/sound/hdaudio.h +33 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,17 @@ struct hdac_widget_tree; */ extern struct bus_type snd_hda_bus_type; /* * generic arrays */ struct snd_array { unsigned int used; unsigned int alloced; unsigned int elem_size; unsigned int alloc_align; void *list; }; /* * HD-audio codec base device */ Loading Loading @@ -178,4 +189,26 @@ static inline void snd_hdac_codec_link_down(struct hdac_device *codec) clear_bit(codec->addr, &codec->bus->codec_powered); } /* * generic array helpers */ void *snd_array_new(struct snd_array *array); void snd_array_free(struct snd_array *array); static inline void snd_array_init(struct snd_array *array, unsigned int size, unsigned int align) { array->elem_size = size; array->alloc_align = align; } static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) { return array->list + idx * array->elem_size; } static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) { return (unsigned long)(ptr - array->list) / array->elem_size; } #endif /* __SOUND_HDAUDIO_H */
sound/hda/Makefile +2 −1 Original line number Diff line number Diff line snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o snd-hda-core-objs := hda_bus_type.o hdac_bus.o hdac_device.o hdac_sysfs.o \ array.o snd-hda-core-objs += trace.o CFLAGS_trace.o := -I$(src) Loading
sound/hda/array.c 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * 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);
sound/pci/hda/hda_codec.c +0 −46 Original line number Diff line number Diff line Loading @@ -5012,52 +5012,6 @@ void snd_hda_bus_reset(struct hda_bus *bus) } EXPORT_SYMBOL_GPL(snd_hda_bus_reset); /* * generic arrays */ /** * 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); /** * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer * @pcm: PCM caps bits Loading
sound/pci/hda/hda_codec.h +0 −30 Original line number Diff line number Diff line Loading @@ -29,36 +29,6 @@ #include <sound/hdaudio.h> #include <sound/hda_verbs.h> /* * generic arrays */ struct snd_array { unsigned int used; unsigned int alloced; unsigned int elem_size; unsigned int alloc_align; void *list; }; void *snd_array_new(struct snd_array *array); void snd_array_free(struct snd_array *array); static inline void snd_array_init(struct snd_array *array, unsigned int size, unsigned int align) { array->elem_size = size; array->alloc_align = align; } static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) { return array->list + idx * array->elem_size; } static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) { return (unsigned long)(ptr - array->list) / array->elem_size; } /* * Structures */ Loading