ASoC: qdsp6: q6asm-dai: Fix a small memory leak
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 21 Dec 2018 09:06:10 +0000 (12:06 +0300)
committerMark Brown <broonie@kernel.org>
Thu, 3 Jan 2019 16:32:56 +0000 (16:32 +0000)
We can't return directly if snd_dma_alloc_pages() fails; we first need
to free prtd->audio_client and prtd.

Fixes: 22930c79ac5c ("ASoC: qdsp6: q6asm-dai: Add support to compress offload")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/qdsp6/q6asm-dai.c

index 3407e51b88613a8dd630ff760c6f9024737e3ea1..548eb4fa2da64415ccf7f9db83f84575a251093f 100644 (file)
@@ -573,8 +573,7 @@ static int q6asm_dai_compr_open(struct snd_compr_stream *stream)
        if (IS_ERR(prtd->audio_client)) {
                dev_err(dev, "Could not allocate memory\n");
                ret = PTR_ERR(prtd->audio_client);
-               kfree(prtd);
-               return ret;
+               goto free_prtd;
        }
 
        size = COMPR_PLAYBACK_MAX_FRAGMENT_SIZE *
@@ -583,7 +582,7 @@ static int q6asm_dai_compr_open(struct snd_compr_stream *stream)
                                  &prtd->dma_buffer);
        if (ret) {
                dev_err(dev, "Cannot allocate buffer(s)\n");
-               return ret;
+               goto free_client;
        }
 
        if (pdata->sid < 0)
@@ -596,6 +595,13 @@ static int q6asm_dai_compr_open(struct snd_compr_stream *stream)
        runtime->private_data = prtd;
 
        return 0;
+
+free_client:
+       q6asm_audio_client_free(prtd->audio_client);
+free_prtd:
+       kfree(prtd);
+
+       return ret;
 }
 
 static int q6asm_dai_compr_free(struct snd_compr_stream *stream)