alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [v2] ASoC: intel: Fix memleak in sst_media_open
@ 2020-08-13  8:41 Dinghao Liu
  2020-08-13 12:52 ` Pierre-Louis Bossart
  2020-08-18 16:54 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Dinghao Liu @ 2020-08-13  8:41 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Cezary Rojewski, Kuninori Morimoto, linux-kernel, Takashi Iwai,
	Jie Yang, Pierre-Louis Bossart, Liam Girdwood, Vinod Koul,
	Mark Brown, Ranjani Sridharan, alsa-devel, Subhransu S. Prusty

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.

Fixes: 0121327c1a68b ("ASoC: Intel: mfld-pcm: add control for powering up/down dsp")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---

Changelog:

v2: - Add a new label 'out_power_up' to unify code style.
---
 sound/soc/intel/atom/sst-mfld-platform-pcm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/intel/atom/sst-mfld-platform-pcm.c b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
index 49b9f18472bc..b1cac7abdc0a 100644
--- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
@@ -331,7 +331,7 @@ static int sst_media_open(struct snd_pcm_substream *substream,
 
 	ret_val = power_up_sst(stream);
 	if (ret_val < 0)
-		return ret_val;
+		goto out_power_up;
 
 	/* Make sure, that the period size is always even */
 	snd_pcm_hw_constraint_step(substream->runtime, 0,
@@ -340,8 +340,9 @@ static int sst_media_open(struct snd_pcm_substream *substream,
 	return snd_pcm_hw_constraint_integer(runtime,
 			 SNDRV_PCM_HW_PARAM_PERIODS);
 out_ops:
-	kfree(stream);
 	mutex_unlock(&sst_lock);
+out_power_up:
+	kfree(stream);
 	return ret_val;
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [v2] ASoC: intel: Fix memleak in sst_media_open
  2020-08-13  8:41 [PATCH] [v2] ASoC: intel: Fix memleak in sst_media_open Dinghao Liu
@ 2020-08-13 12:52 ` Pierre-Louis Bossart
  2020-08-18 16:54 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Pierre-Louis Bossart @ 2020-08-13 12:52 UTC (permalink / raw)
  To: Dinghao Liu, kjlu
  Cc: Cezary Rojewski, Kuninori Morimoto, linux-kernel, Jie Yang,
	Takashi Iwai, Liam Girdwood, Vinod Koul, Mark Brown,
	Ranjani Sridharan, alsa-devel, Subhransu S. Prusty



On 8/13/20 3:41 AM, Dinghao Liu wrote:
> 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.
> 
> Fixes: 0121327c1a68b ("ASoC: Intel: mfld-pcm: add control for powering up/down dsp")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

Thanks for spotting this!

> ---
> 
> Changelog:
> 
> v2: - Add a new label 'out_power_up' to unify code style.
> ---
>   sound/soc/intel/atom/sst-mfld-platform-pcm.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/intel/atom/sst-mfld-platform-pcm.c b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
> index 49b9f18472bc..b1cac7abdc0a 100644
> --- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c
> +++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
> @@ -331,7 +331,7 @@ static int sst_media_open(struct snd_pcm_substream *substream,
>   
>   	ret_val = power_up_sst(stream);
>   	if (ret_val < 0)
> -		return ret_val;
> +		goto out_power_up;
>   
>   	/* Make sure, that the period size is always even */
>   	snd_pcm_hw_constraint_step(substream->runtime, 0,
> @@ -340,8 +340,9 @@ static int sst_media_open(struct snd_pcm_substream *substream,
>   	return snd_pcm_hw_constraint_integer(runtime,
>   			 SNDRV_PCM_HW_PARAM_PERIODS);
>   out_ops:
> -	kfree(stream);
>   	mutex_unlock(&sst_lock);
> +out_power_up:
> +	kfree(stream);
>   	return ret_val;
>   }
>   
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [v2] ASoC: intel: Fix memleak in sst_media_open
  2020-08-13  8:41 [PATCH] [v2] ASoC: intel: Fix memleak in sst_media_open Dinghao Liu
  2020-08-13 12:52 ` Pierre-Louis Bossart
@ 2020-08-18 16:54 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2020-08-18 16:54 UTC (permalink / raw)
  To: Dinghao Liu, kjlu
  Cc: Cezary Rojewski, Kuninori Morimoto, linux-kernel, Takashi Iwai,
	Jie Yang, Pierre-Louis Bossart, Liam Girdwood, Vinod Koul,
	Ranjani Sridharan, alsa-devel, Subhransu S. Prusty

On Thu, 13 Aug 2020 16:41:10 +0800, Dinghao Liu wrote:
> 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.

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: intel: Fix memleak in sst_media_open
      commit: 062fa09f44f4fb3776a23184d5d296b0c8872eb9

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-18 17:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13  8:41 [PATCH] [v2] ASoC: intel: Fix memleak in sst_media_open Dinghao Liu
2020-08-13 12:52 ` Pierre-Louis Bossart
2020-08-18 16:54 ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).