Skip to contentSkip to conversation

ASoC: intel: Fix memory leak in sst_media_open()

PATCH Markus Elfring 1 participant 1 message Aug 9, 2020

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines

When power_up_sst() fails, stream needs to be freed just like when try_module_get() fails. However, current code is returning directly and ends up leaking memory.

Would an imperative wording be preferred for the change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=06a81c1c7db9bd5de0bd38cd5acc44bb22b99150#n151

…

Review static int sst_media_open(struct snd_pcm_substream *substream, · line 336

Quoted 10 lines

+++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c

(quoted diff) +3 -1
@@ -330,8 +330,10 @@  static int sst_media_open(struct snd_pcm_substream *substream,
 	runtime->private_data = stream;
 
 	ret_val = power_up_sst(stream);
-	if (ret_val < 0)
+	if (ret_val < 0) {
+		kfree(stream);
 		return ret_val;
+	}

…

I propose to add a jump target so that a bit of common exception handling code can be better reused at the end of this function implementation.

Regards,
Markus