Commit 78977fd5 authored by Xiaoke Wang's avatar Xiaoke Wang Committed by Takashi Iwai

ALSA: sound/isa/gus: check the return value of kstrdup()

kstrdup() returns NULL when some internal memory errors happen, it is
better to check the return value of it. Otherwise, we may not to be able
to catch some memory errors in time.
Signed-off-by: default avatarXiaoke Wang <xkernel.wang@foxmail.com>
Link: https://lore.kernel.org/r/tencent_1E3950293AC22395ACFE99404C985D738309@qq.comSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 55b71f6c
...@@ -199,6 +199,10 @@ struct snd_gf1_mem_block *snd_gf1_mem_alloc(struct snd_gf1_mem * alloc, int owne ...@@ -199,6 +199,10 @@ struct snd_gf1_mem_block *snd_gf1_mem_alloc(struct snd_gf1_mem * alloc, int owne
memcpy(&block.share_id, share_id, sizeof(block.share_id)); memcpy(&block.share_id, share_id, sizeof(block.share_id));
block.owner = owner; block.owner = owner;
block.name = kstrdup(name, GFP_KERNEL); block.name = kstrdup(name, GFP_KERNEL);
if (block.name == NULL) {
snd_gf1_mem_lock(alloc, 1);
return NULL;
}
nblock = snd_gf1_mem_xalloc(alloc, &block); nblock = snd_gf1_mem_xalloc(alloc, &block);
snd_gf1_mem_lock(alloc, 1); snd_gf1_mem_lock(alloc, 1);
return nblock; return nblock;
...@@ -237,13 +241,13 @@ int snd_gf1_mem_init(struct snd_gus_card * gus) ...@@ -237,13 +241,13 @@ int snd_gf1_mem_init(struct snd_gus_card * gus)
block.ptr = 0; block.ptr = 0;
block.size = 1024; block.size = 1024;
block.name = kstrdup("InterWave LFOs", GFP_KERNEL); block.name = kstrdup("InterWave LFOs", GFP_KERNEL);
if (snd_gf1_mem_xalloc(alloc, &block) == NULL) if (block.name == NULL || snd_gf1_mem_xalloc(alloc, &block) == NULL)
return -ENOMEM; return -ENOMEM;
} }
block.ptr = gus->gf1.default_voice_address; block.ptr = gus->gf1.default_voice_address;
block.size = 4; block.size = 4;
block.name = kstrdup("Voice default (NULL's)", GFP_KERNEL); block.name = kstrdup("Voice default (NULL's)", GFP_KERNEL);
if (snd_gf1_mem_xalloc(alloc, &block) == NULL) if (block.name == NULL || snd_gf1_mem_xalloc(alloc, &block) == NULL)
return -ENOMEM; return -ENOMEM;
#ifdef CONFIG_SND_DEBUG #ifdef CONFIG_SND_DEBUG
snd_card_ro_proc_new(gus->card, "gusmem", gus, snd_gf1_mem_info_read); snd_card_ro_proc_new(gus->card, "gusmem", gus, snd_gf1_mem_info_read);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment