linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: pci/asihpi: Fix memory leak in snd_card_asihpi_capture_open()
@ 2020-08-10  6:39 Dinghao Liu
  2020-08-10  6:58 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Dinghao Liu @ 2020-08-10  6:39 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart,
	Eliot Blennerhassett, alsa-devel, linux-kernel

When snd_pcm_hw_constraint_pow2() fails, dpcm should be freed
just like when hpi_instream_open()  fails.

Fixes: 719f82d3987aa ("ALSA: Add support of AudioScience ASI boards")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 sound/pci/asihpi/asihpi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
index 023c35a2a951..736eceacd3d0 100644
--- a/sound/pci/asihpi/asihpi.c
+++ b/sound/pci/asihpi/asihpi.c
@@ -1244,8 +1244,10 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
 	if (card->can_dma)
 		err = snd_pcm_hw_constraint_pow2(runtime, 0,
 					SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
-	if (err < 0)
+	if (err < 0) {
+		kfree(dpcm);
 		return err;
+	}
 
 	snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
 		card->update_interval_frames);
-- 
2.17.1


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

* Re: [PATCH] ALSA: pci/asihpi: Fix memory leak in snd_card_asihpi_capture_open()
  2020-08-10  6:39 [PATCH] ALSA: pci/asihpi: Fix memory leak in snd_card_asihpi_capture_open() Dinghao Liu
@ 2020-08-10  6:58 ` Takashi Iwai
  2020-08-13  6:39   ` dinghao.liu
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2020-08-10  6:58 UTC (permalink / raw)
  To: Dinghao Liu
  Cc: kjlu, Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart,
	Eliot Blennerhassett, alsa-devel, linux-kernel

On Mon, 10 Aug 2020 08:39:55 +0200,
Dinghao Liu wrote:
> 
> When snd_pcm_hw_constraint_pow2() fails, dpcm should be freed
> just like when hpi_instream_open()  fails.

It will be cleaned up via runtime->private_free call in the caller
side (snd_pcm_open -> snd_pcm_release_substream ->
snd_pcm_detach_substream), hence this would result in double-free.


thanks,

Takashi

> 
> Fixes: 719f82d3987aa ("ALSA: Add support of AudioScience ASI boards")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> ---
>  sound/pci/asihpi/asihpi.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
> index 023c35a2a951..736eceacd3d0 100644
> --- a/sound/pci/asihpi/asihpi.c
> +++ b/sound/pci/asihpi/asihpi.c
> @@ -1244,8 +1244,10 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
>  	if (card->can_dma)
>  		err = snd_pcm_hw_constraint_pow2(runtime, 0,
>  					SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
> -	if (err < 0)
> +	if (err < 0) {
> +		kfree(dpcm);
>  		return err;
> +	}
>  
>  	snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
>  		card->update_interval_frames);
> -- 
> 2.17.1
> 

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

* Re: Re: [PATCH] ALSA: pci/asihpi: Fix memory leak in snd_card_asihpi_capture_open()
  2020-08-10  6:58 ` Takashi Iwai
@ 2020-08-13  6:39   ` dinghao.liu
  0 siblings, 0 replies; 3+ messages in thread
From: dinghao.liu @ 2020-08-13  6:39 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: kjlu, Jaroslav Kysela, Takashi Iwai, Pierre-Louis Bossart,
	Eliot Blennerhassett, alsa-devel, linux-kernel

> On Mon, 10 Aug 2020 08:39:55 +0200,
> Dinghao Liu wrote:
> > 
> > When snd_pcm_hw_constraint_pow2() fails, dpcm should be freed
> > just like when hpi_instream_open()  fails.
> 
> It will be cleaned up via runtime->private_free call in the caller
> side (snd_pcm_open -> snd_pcm_release_substream ->
> snd_pcm_detach_substream), hence this would result in double-free.
> 

It's clear to me, thanks!

Regards,
Dinghao

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

end of thread, other threads:[~2020-08-13  6:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10  6:39 [PATCH] ALSA: pci/asihpi: Fix memory leak in snd_card_asihpi_capture_open() Dinghao Liu
2020-08-10  6:58 ` Takashi Iwai
2020-08-13  6:39   ` dinghao.liu

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).