diff mbox series

[4.19,072/264] ASoC: qcom: lpass-platform: fix memory leak

Message ID 20201027135434.080956764@linuxfoundation.org
State New
Headers show
Series None | expand

Commit Message

Greg KH Oct. 27, 2020, 1:52 p.m. UTC
From: Rohit kumar <rohitkr@codeaurora.org>

[ Upstream commit 5fd188215d4eb52703600d8986b22311099a5940 ]

lpass_pcm_data is never freed. Free it in close
ops to avoid memory leak.

Fixes: 022d00ee0b55 ("ASoC: lpass-platform: Fix broken pcm data usage")
Signed-off-by: Rohit kumar <rohitkr@codeaurora.org>
Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/1597402388-14112-5-git-send-email-rohitkr@codeaurora.org
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/qcom/lpass-platform.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Pavel Machek Oct. 28, 2020, 7:02 a.m. UTC | #1
Hi!

> From: Rohit kumar <rohitkr@codeaurora.org>
> 
> [ Upstream commit 5fd188215d4eb52703600d8986b22311099a5940 ]
> 
> lpass_pcm_data is never freed. Free it in close
> ops to avoid memory leak.

AFAICT this introduces memory leaks in the error paths.

Best regards,
							Pavel

Signed-off-by: Pavel Machek <pavel@ucw.cz>

diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
index 2f2967247789..9e13a00d8c80 100644
--- a/sound/soc/qcom/lpass-platform.c
+++ b/sound/soc/qcom/lpass-platform.c
@@ -81,17 +81,20 @@ static int lpass_platform_pcmops_open(struct snd_pcm_substream *substream)
 	else
 		dma_ch = 0;
 
-	if (dma_ch < 0)
+	if (dma_ch < 0) {
+		kfree(data);
 		return dma_ch;
+	}
 
 	drvdata->substream[dma_ch] = substream;
 
 	ret = regmap_write(drvdata->lpaif_map,
 			LPAIF_DMACTL_REG(v, dma_ch, dir), 0);
 	if (ret) {
+		kfree(data);
 		dev_err(soc_runtime->dev,
 			"error writing to rdmactl reg: %d\n", ret);
-			return ret;
+		return ret;
 	}
 
 	data->dma_ch = dma_ch;
@@ -103,6 +106,7 @@ static int lpass_platform_pcmops_open(struct snd_pcm_substream *substream)
 	ret = snd_pcm_hw_constraint_integer(runtime,
 			SNDRV_PCM_HW_PARAM_PERIODS);
 	if (ret < 0) {
+		kfree(data);
 		dev_err(soc_runtime->dev, "setting constraints failed: %d\n",
 			ret);
 		return -EINVAL;
Pavel Machek Oct. 28, 2020, 7:43 a.m. UTC | #2
On Wed 2020-10-28 13:04:02, Rohit Kumar wrote:
> Thanks Pavel for the review.

> 

> On 10/28/2020 12:32 PM, Pavel Machek wrote:

> >Hi!

> >

> >>From: Rohit kumar <rohitkr@codeaurora.org>

> >>

> >>[ Upstream commit 5fd188215d4eb52703600d8986b22311099a5940 ]

> >>

> >>lpass_pcm_data is never freed. Free it in close

> >>ops to avoid memory leak.

> >AFAICT this introduces memory leaks in the error paths.

> Yes, I will post the fix soon. Thanks for review.


Well, the email had a fix attached :-). Feel free to review it and use
it...

Best regards,

								Pavel


-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
diff mbox series

Patch

diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
index d07271ea4c451..2f29672477892 100644
--- a/sound/soc/qcom/lpass-platform.c
+++ b/sound/soc/qcom/lpass-platform.c
@@ -69,7 +69,7 @@  static int lpass_platform_pcmops_open(struct snd_pcm_substream *substream)
 	int ret, dma_ch, dir = substream->stream;
 	struct lpass_pcm_data *data;
 
-	data = devm_kzalloc(soc_runtime->dev, sizeof(*data), GFP_KERNEL);
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -127,6 +127,7 @@  static int lpass_platform_pcmops_close(struct snd_pcm_substream *substream)
 	if (v->free_dma_channel)
 		v->free_dma_channel(drvdata, data->dma_ch);
 
+	kfree(data);
 	return 0;
 }