ALSA: hda: Fix krealloc() with __GFP_ZERO usage

krealloc() doesn't work always properly with __GFP_ZERO flag as
expected.  For clearing the reallocated area, we need to clear
explicitly instead.

Reported-by: Joe Perches <joe@perches.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2016-08-03 15:13:00 +02:00
parent fd48331f9b
commit 33baefe5e7
1 changed files with 3 additions and 1 deletions

View File

@ -21,13 +21,15 @@ void *snd_array_new(struct snd_array *array)
return NULL; return NULL;
if (array->used >= array->alloced) { if (array->used >= array->alloced) {
int num = array->alloced + array->alloc_align; int num = array->alloced + array->alloc_align;
int oldsize = array->alloced * array->elem_size;
int size = (num + 1) * array->elem_size; int size = (num + 1) * array->elem_size;
void *nlist; void *nlist;
if (snd_BUG_ON(num >= 4096)) if (snd_BUG_ON(num >= 4096))
return NULL; return NULL;
nlist = krealloc(array->list, size, GFP_KERNEL | __GFP_ZERO); nlist = krealloc(array->list, size, GFP_KERNEL);
if (!nlist) if (!nlist)
return NULL; return NULL;
memset(nlist + oldsize, 0, size - oldsize);
array->list = nlist; array->list = nlist;
array->alloced = num; array->alloced = num;
} }