Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@amd.com>
To: Rosen Penev <rosenp@gmail.com>, linux-sound@vger.kernel.org
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	Maruthi Srinivas Bayyavarapu
	<maruthi.srinivas.bayyavarapu@xilinx.com>,
	"moderated list:ARM/ZYNQ ARCHITECTURE"
	<linux-arm-kernel@lists.infradead.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error
Date: Tue, 11 Aug 2026 16:04:34 +0200	[thread overview]
Message-ID: <23036150-4cd3-4b7e-bbfa-dc1a370a24e4@amd.com> (raw)
In-Reply-To: <20260807004031.47455-1-rosenp@gmail.com>



On 8/7/26 02:40, Rosen Penev wrote:
> In xlnx_formatter_pcm_open(), stream_data is allocated and
> adata->play_stream or adata->capture_stream is assigned early.  If a
> later step, such as snd_pcm_hw_constraint_step() or
> snd_pcm_hw_constraint_integer(), fails, the function returns the error
> immediately.  ALSA does not call the close callback when open fails, so
> stream_data is leaked and the stream pointer is left dangling, pointing
> to a substream that ALSA frees.  A later interrupt would then call
> snd_pcm_period_elapsed() on the freed substream.
> 
> Free stream_data and clear the stream pointer on the error paths.
> 
> Fixes: 6f6c3c36f091 ("ASoC: xlnx: add pcm formatter platform driver")
> Assisted-by: opencode:deepseek-v4-flash-free
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>   sound/soc/xilinx/xlnx_formatter_pcm.c | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/soc/xilinx/xlnx_formatter_pcm.c b/sound/soc/xilinx/xlnx_formatter_pcm.c
> index 7eba3a0205f1..4f4c1e650aaf 100644
> --- a/sound/soc/xilinx/xlnx_formatter_pcm.c
> +++ b/sound/soc/xilinx/xlnx_formatter_pcm.c
> @@ -385,7 +385,7 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
>   	if (err) {
>   		dev_err(component->dev,
>   			"Unable to set constraint on period bytes\n");
> -		return err;
> +		goto err;
>   	}
>   
>   	/* Resize the buffer bytes as divisible by 64 */
> @@ -395,7 +395,7 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
>   	if (err) {
>   		dev_err(component->dev,
>   			"Unable to set constraint on buffer bytes\n");
> -		return err;
> +		goto err;
>   	}
>   
>   	/* Set periods as integer multiple */
> @@ -404,7 +404,7 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
>   	if (err < 0) {
>   		dev_err(component->dev,
>   			"Unable to set constraint on periods to be integer\n");
> -		return err;
> +		goto err;
>   	}
>   
>   	/* enable DMA IOC irq */
> @@ -413,6 +413,14 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
>   	writel(val, stream_data->mmio + XLNX_AUD_CTRL);
>   
>   	return 0;
> +
> +err:

err is also variable in this code that's why I suggest you to rename this label.

> +	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
> +		adata->play_stream = NULL;
> +	else
> +		adata->capture_stream = NULL;
> +	kfree(stream_data);
> +	return err;
>   }
>   
>   static int xlnx_formatter_pcm_close(struct snd_soc_component *component,

With that fixed fell free to add

Reviewed-by: Michal Simek <michal.simek@amd.com>

Thanks,
Michal



      reply	other threads:[~2026-08-11 14:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07  0:40 [PATCH] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error Rosen Penev
2026-08-11 14:04 ` Michal Simek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23036150-4cd3-4b7e-bbfa-dc1a370a24e4@amd.com \
    --to=michal.simek@amd.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=maruthi.srinivas.bayyavarapu@xilinx.com \
    --cc=perex@perex.cz \
    --cc=rosenp@gmail.com \
    --cc=tiwai@suse.com \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox