* [PATCHv2] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error
@ 2026-08-11 18:51 Rosen Penev
2026-08-11 22:08 ` Mark Brown
2026-08-12 6:11 ` Vincenzo Frascino
0 siblings, 2 replies; 3+ messages in thread
From: Rosen Penev @ 2026-08-11 18:51 UTC (permalink / raw)
To: linux-sound
Cc: Vincenzo Frascino, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Michal Simek, Maruthi Srinivas Bayyavarapu,
moderated list:ARM/ZYNQ ARCHITECTURE, open list
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>
Reviewed-by: Michal Simek <michal.simek@amd.com>
---
v2: change goto label from err to error.
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 b50306b0fc06..3d6f1e4046d8 100644
--- a/sound/soc/xilinx/xlnx_formatter_pcm.c
+++ b/sound/soc/xilinx/xlnx_formatter_pcm.c
@@ -383,7 +383,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 error;
}
/* Resize the buffer bytes as divisible by 64 */
@@ -393,7 +393,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 error;
}
/* Set periods as integer multiple */
@@ -402,7 +402,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 error;
}
/* enable DMA IOC irq */
@@ -411,6 +411,14 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
writel(val, stream_data->mmio + XLNX_AUD_CTRL);
return 0;
+
+error:
+ 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,
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCHv2] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error
2026-08-11 18:51 [PATCHv2] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error Rosen Penev
@ 2026-08-11 22:08 ` Mark Brown
2026-08-12 6:11 ` Vincenzo Frascino
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2026-08-11 22:08 UTC (permalink / raw)
To: linux-sound, Rosen Penev
Cc: Vincenzo Frascino, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
Michal Simek, Maruthi Srinivas Bayyavarapu, linux-arm-kernel,
linux-kernel
On Tue, 11 Aug 2026 11:51:40 -0700, Rosen Penev wrote:
> ASoC: xilinx: formatter_pcm: fix stream_data leak on open error
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.3
Thanks!
[1/1] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error
https://git.kernel.org/broonie/sound/c/b992511180e1
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* Re: [PATCHv2] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error
2026-08-11 18:51 [PATCHv2] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error Rosen Penev
2026-08-11 22:08 ` Mark Brown
@ 2026-08-12 6:11 ` Vincenzo Frascino
1 sibling, 0 replies; 3+ messages in thread
From: Vincenzo Frascino @ 2026-08-12 6:11 UTC (permalink / raw)
To: Rosen Penev, linux-sound
Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Michal Simek, Maruthi Srinivas Bayyavarapu,
moderated list:ARM/ZYNQ ARCHITECTURE, open list
On 11/08/2026 19:51, 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>
> Reviewed-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> ---
> v2: change goto label from err to error.
> 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 b50306b0fc06..3d6f1e4046d8 100644
> --- a/sound/soc/xilinx/xlnx_formatter_pcm.c
> +++ b/sound/soc/xilinx/xlnx_formatter_pcm.c
> @@ -383,7 +383,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 error;
> }
>
> /* Resize the buffer bytes as divisible by 64 */
> @@ -393,7 +393,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 error;
> }
>
> /* Set periods as integer multiple */
> @@ -402,7 +402,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 error;
> }
>
> /* enable DMA IOC irq */
> @@ -411,6 +411,14 @@ static int xlnx_formatter_pcm_open(struct snd_soc_component *component,
> writel(val, stream_data->mmio + XLNX_AUD_CTRL);
>
> return 0;
> +
> +error:
> + 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,
--
Regards,
Vincenzo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-12 10:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 18:51 [PATCHv2] ASoC: xilinx: formatter_pcm: fix stream_data leak on open error Rosen Penev
2026-08-11 22:08 ` Mark Brown
2026-08-12 6:11 ` Vincenzo Frascino
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.