Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com> Tested-by: Peter Schneider <pschneider1968@googlemail.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Salvatore Bonaccorso <carnil@debian.org> Tested-by: Brett A C Sheffield <bacs@librecast.net> Tested-by: Mark Brown <broonie@kernel.org> Tested-by: Luna Jernberg <droidbittin@gmail.com> Tested-by: Ronald Warsow <rwarsow@gmx.de> Tested-by: Justin M. Forbes <jforbes@fedoraproject.org> Tested-by: Ron Economos <re@w6rz.net> Tested-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
// 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);
|