[PATCH] media: cx23885: Fix a potential leak in snd_cx23885_hw_params()

Haoxiang Li posted 1 patch 3 days ago
drivers/media/pci/cx23885/cx23885-alsa.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
[PATCH] media: cx23885: Fix a potential leak in snd_cx23885_hw_params()
Posted by Haoxiang Li 3 days ago
Add an error path to free the memory allocated by cx23885_alsa_dma_init().
Also move cx23885_alsa_dma_unmap() to the goto label to unify the error
handling.

Fixes: 9529a4b0cf49 ("[media] cx23885: drop videobuf abuse in cx23885-alsa")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/media/pci/cx23885/cx23885-alsa.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-alsa.c b/drivers/media/pci/cx23885/cx23885-alsa.c
index 29f6df0e6de4..515aba9fb384 100644
--- a/drivers/media/pci/cx23885/cx23885-alsa.c
+++ b/drivers/media/pci/cx23885/cx23885-alsa.c
@@ -388,14 +388,12 @@ static int snd_cx23885_hw_params(struct snd_pcm_substream *substream,
 
 	ret = cx23885_alsa_dma_map(chip);
 	if (ret < 0)
-		goto error;
+		goto error_free;
 
 	ret = cx23885_risc_databuffer(chip->pci, &buf->risc, buf->sglist,
 				   chip->period_size, chip->num_periods, 1);
-	if (ret < 0) {
-		cx23885_alsa_dma_unmap(chip);
-		goto error;
-	}
+	if (ret < 0)
+		goto error_unmap;
 
 	/* Loop back to start of program */
 	buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC);
@@ -408,6 +406,10 @@ static int snd_cx23885_hw_params(struct snd_pcm_substream *substream,
 
 	return 0;
 
+error_unmap:
+	cx23885_alsa_dma_unmap(chip);
+error_free:
+	cx23885_alsa_dma_free(buf);
 error:
 	kfree(buf);
 	chip->buf = NULL;
-- 
2.25.1