Skip to contentSkip to conversation

ALSA: missing check for possible NULL after the call to kstrdup

PATCH Applied Austin Kim 2 participants 3 messages Nov 9, 2021 Sound

lore
Share & tools
lore

Austin Kim

author
#0 lore raw

PATCH 1/1 ALSA: missing check for possible NULL after the call to kstrdup

From: Austin Kim <[email protected]>

If kcalloc() return NULL due to memory starvation, it is possible for kstrdup() to return NULL in similar case. So add null check after the call to kstrdup() is made.

---
 sound/synth/emux/emux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/synth/emux/emux.c +1 -1
index 49d1976a132c..6dab3c5bac00 100644
@@ -88,7 +88,7 @@ int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, ch
 	emu->name = kstrdup(name, GFP_KERNEL);
 	emu->voices = kcalloc(emu->max_voices, sizeof(struct snd_emux_voice),
 			      GFP_KERNEL);
-	if (emu->voices == NULL)
+	if ((emu->name == NULL) || (emu->voices == NULL))
 		return -ENOMEM;
 
 	/* create soundfont list */
Signature · 1 line
2.20.1
Applied
#1 lore raw
Quoted 8 lines · Austin Kim

From: Austin Kim <[email protected]>

If kcalloc() return NULL due to memory starvation, it is possible for kstrdup() to return NULL in similar case. So add null check after the call to kstrdup() is made.

Thanks, applied now with a minor coding-style fix (we need no extra parentheses), the correction of the subject line with the proper prefix, and the addition of Cc-to-stable.

Takashi

author
#2 lore raw

2021년 11월 9일 (화) 오후 3:24, Takashi Iwai <[email protected]>님이 작성:

Quoted 10 lines
Quoted 7 lines · Austin Kim

From: Austin Kim <[email protected]>

If kcalloc() return NULL due to memory starvation, it is possible for kstrdup() to return NULL in similar case. So add null check after the call to kstrdup() is made.

Quoted 6 lines
Quoted 1 line

Thanks, applied now with a minor coding-style fix (we need no extra parentheses), the correction of the subject line with the proper prefix, and the addition of Cc-to-stable.

Great, Thanks

BR,
Austin Kim

Quoted 2 lines

Takashi