From: sashiko-bot@kernel.org
To: "Neil Armstrong" <neil.armstrong@linaro.org>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 15/19] ASoC: qcom: lpass: allocate LPM buffer memory to DAIs
Date: Tue, 24 Nov 2026 18:01:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-231761@kernel.org> (raw)
In-Reply-To: <20261124-topic-sm8650-el2-v2-15-174e159f0f69@linaro.org>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ASoC: qcom: lpass: unchecked memremap() and invalid free of LPM
MI2S buffer
- [High] ASoC: qcom: lpass: VA and RXTX LPAIF resources not gated when
used for MI2S
- [High] ASoC: qcom: lpass: unchecked memremap() and missing pcm_free
memunmap()
- [Medium] ASoC: qcom: lpass: mi2s_lpm_enable set for disabled LPM
LPAIFs in probe
- [Medium] ASoC: qcom: lpass: LPM buffer offset 0 collision in
lpass_platform_allocate_lpm()
--
commit 4c2b83ff038eba299bfce68560d0b64cb7efc8a7
Author: Neil Armstrong <neil.armstrong@linaro.org>
ASoC: qcom: lpass: allocate LPM buffer memory to DAIs
This commit dynamically assigns LPM SRAM buffer offsets for Codec DMA and
LPM-backed MI2S DAIs and preallocates LPM DMA buffers for MI2S ports that
cannot access DDR.
> diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
> index a83507c2cd557..8b005a87d4088 100644
> --- a/sound/soc/qcom/lpass-cpu.c
> +++ b/sound/soc/qcom/lpass-cpu.c
> @@ -1169,6 +1169,8 @@ static void of_lpass_cpu_parse_dai_data(struct device *dev,
> data->codec_dma_enable = 1;
> if (is_wsa_cdc_dma_port(id))
> data->wsa_enable = 1;
> + else if (!is_rxtx_cdc_dma_port(id))
> + data->va_enable = 1;
> } else if (is_mi2s_port_id(id)) {
> unsigned int port_id = mi2s_port_id(id);
[Severity: High]
Should drvdata->va_enable (and an equivalent rxtx_enable flag) also gate
claiming the VA and RXTX LPAIF MMIO and IRQ resources when Codec DMA is
enabled?
When a board uses RXTX or WSA Codec DMA alongside an MI2S port on
lpass-va-lpaif (with va_enable == 0), asoc_qcom_lpass_cpu_platform_probe()
still unconditionally claims "lpass-va-lpaif" via
devm_platform_ioremap_resource_byname() under if (drvdata->codec_dma_enable),
causing lpass_cpu_init_lpaif() for that MI2S LPAIF to fail with -EBUSY
(and asoc_qcom_lpass_platform_register() similarly requests
"lpass-irq-vaif" unconditionally). Conversely, without an rxtx_enable
flag, enabling only VA or WSA Codec DMA unconditionally claims
"lpass-rxtx-lpaif" and reserves 2 * LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE of
rxtx_cdc_dma_lpm in lpass_platform_allocate_lpm().
[ ... ]
> @@ -1380,6 +1366,9 @@ int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev)
> variant->mi2s_desc[i].reg_name);
> if (ret)
> return ret;
> +
> + if (variant->mi2s_desc[i].lpm_type != LPASS_LPM_NONE)
> + drvdata->mi2s_lpm_enable = true;
> }
> } else {
[Severity: Medium]
Does this set drvdata->mi2s_lpm_enable even when the LPM-backed LPAIF has
no ports enabled in DT?
When no port on variant->mi2s_desc[i] is set in drvdata->lpaif_port_enable,
lpass_cpu_init_lpaif() returns 0 early with drvdata->lpaif[i].drvdata left
NULL. Checking variant->mi2s_desc[i].lpm_type without checking
drvdata->lpaif[i].drvdata sets mi2s_lpm_enable to true on every variant
whose static mi2s_desc table contains an LPM LPAIF, forcing probe to
require the Codec DMA LPM clocks and LPM memory resources even when only
core-LPAIF MI2S or HDMI/DP DAIs are used.
> diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
> index 16a964e1aec1f..855f1ee193946 100644
> --- a/sound/soc/qcom/lpass-platform.c
> +++ b/sound/soc/qcom/lpass-platform.c
[ ... ]
> @@ -1288,6 +1321,41 @@ static irqreturn_t lpass_platform_wsaif_irq(int irq, void *data)
> return IRQ_HANDLED;
> }
>
> +static int lpass_platform_prealloc_lpm_mi2s_buffer(struct snd_soc_component *component,
> + struct snd_pcm *pcm, int dai_id)
> +{
> + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
> + unsigned int port_id = mi2s_port_id(dai_id);
> + struct snd_pcm_substream *substream;
> + struct snd_dma_buffer *buf;
> + u32 addr;
> + int dir;
> +
> + if (drvdata->mi2s_lpm[port_id] == LPASS_VA_CDC_LPM)
> + addr = drvdata->va_cdc_dma_lpm_buf;
> + else
> + addr = drvdata->rxtx_cdc_dma_lpm_buf;
> + addr += drvdata->mi2s_lpm_offset[port_id];
> +
> + /* Playback and capture buffers are allocated one after the other */
> + for (dir = SNDRV_PCM_STREAM_PLAYBACK; dir <= SNDRV_PCM_STREAM_CAPTURE; dir++) {
> + substream = pcm->streams[dir].substream;
> + if (!substream)
> + continue;
> +
> + buf = &substream->dma_buffer;
> + buf->dev.dev = pcm->card->dev;
> + buf->dev.type = SNDRV_DMA_TYPE_CONTINUOUS;
> + buf->private_data = NULL;
> + buf->bytes = lpass_platform_lpm_mi2s_hardware.buffer_bytes_max;
> + buf->addr = addr + dir * LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE;
> + buf->area = (unsigned char * __force)memremap(buf->addr, buf->bytes,
> + MEMREMAP_WC);
> + }
> +
> + return 0;
> +}
[Severity: High]
What happens on PCM teardown or if memremap() returns NULL here?
Because buf->dev.type is set to SNDRV_DMA_TYPE_CONTINUOUS and
lpass_component_driver has no .pcm_free callback to memunmap(buf->area) and
clear buf->area, PCM teardown in snd_pcm_free() ->
snd_pcm_lib_preallocate_free_for_all() -> do_free_pages() passes the
memremap() I/O virtual address to snd_dma_continuous_free() ->
free_pages_exact() and leaks the mapping. In addition, if memremap()
returns NULL, lpass_platform_prealloc_lpm_mi2s_buffer() still returns 0
(leaking the playback mapping if capture fails), and a subsequent transfer
in lpass_platform_copy() dereferences a NULL runtime->dma_area.
> @@ -1412,6 +1482,7 @@ static int lpass_platform_copy(struct snd_soc_component *component,
> unsigned long pos, struct iov_iter *buf,
> unsigned long bytes)
> {
> + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
> struct snd_pcm_runtime *rt = substream->runtime;
> struct snd_soc_pcm_runtime *soc_runtime = snd_soc_substream_to_rtd(substream);
> struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(soc_runtime, 0);
> @@ -1422,7 +1493,7 @@ static int lpass_platform_copy(struct snd_soc_component *component,
> channel * (rt->dma_bytes / rt->channels));
>
> if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
> - if (is_cdc_dma_port(dai_id)) {
> + if (is_cdc_dma_port(dai_id) || is_lpm_mi2s_port(drvdata, dai_id)) {
> if (copy_from_iter_toio(dma_buf, bytes, buf) != bytes)
> ret = -EFAULT;
> } else {
> @@ -1430,7 +1501,7 @@ static int lpass_platform_copy(struct snd_soc_component *component,
> ret = -EFAULT;
> }
> } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
> - if (is_cdc_dma_port(dai_id)) {
> + if (is_cdc_dma_port(dai_id) || is_lpm_mi2s_port(drvdata, dai_id)) {
> if (copy_to_iter_fromio(dma_buf, bytes, buf) != bytes)
> ret = -EFAULT;
> } else {
[Severity: High]
Should both lpass_platform_prealloc_lpm_mi2s_buffer() and
lpass_platform_prealloc_cdc_dma_buffer() return -ENOMEM if memremap()
fails, and should lpass_component_driver provide a .pcm_free callback to
memunmap() and zero substream->dma_buffer.area so that lpass_platform_copy()
cannot hit a NULL rt->dma_area and snd_pcm_free() does not call
free_pages_exact() on the remapped LPM pointer?
> @@ -1459,6 +1530,66 @@ static const struct snd_soc_component_driver lpass_component_driver = {
>
> };
>
> +static int lpass_platform_allocate_lpm(struct lpass_data *drvdata)
> +{
> + u32 rxtx_cdc_dma_lpm_remain = drvdata->rxtx_cdc_dma_lpm_size;
> + u32 va_cdc_dma_lpm_remain = drvdata->va_cdc_dma_lpm_size;
> + u32 rxtx_cdc_dma_lpm_offset = 0;
> + u32 va_cdc_dma_lpm_offset = 0;
> + int port_id;
> +
> + if (drvdata->codec_dma_enable) {
> + drvdata->rxtx_lpm_offset = rxtx_cdc_dma_lpm_offset;
> + rxtx_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> + rxtx_cdc_dma_lpm_remain -= LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> +
> + if (drvdata->va_enable) {
> + drvdata->va_lpm_offset = va_cdc_dma_lpm_offset;
> + va_cdc_dma_lpm_offset += LPASS_VA_CDC_DMA_LPM_BUFF_SIZE;
> + va_cdc_dma_lpm_remain -= LPASS_VA_CDC_DMA_LPM_BUFF_SIZE;
> + }
> +
> + if (drvdata->wsa_enable) {
> + drvdata->wsa_lpm_offset = rxtx_cdc_dma_lpm_offset;
> + rxtx_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> + rxtx_cdc_dma_lpm_remain -= LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> + }
> + }
> +
> + if (!drvdata->mi2s_lpm_enable)
> + return 0;
> +
> + for (port_id = 0; port_id < LPASS_MAX_MI2S_PORTS; port_id++) {
> + if (!test_bit(port_id, &drvdata->lpaif_port_enable))
> + continue;
> +
> + switch (drvdata->mi2s_lpm[port_id]) {
[Severity: Medium]
Can an MI2S port on an enabled multi-port LPM LPAIF collide at LPM offset 0
if that port has no child node in DT?
of_lpass_cpu_parse_dai_data() sets a default 8-channel SD-line mode for all
MI2S ports and only sets drvdata->lpaif_port_enable for ports with an
explicit child node, while asoc_qcom_lpass_cpu_platform_probe() populates
drvdata->mi2s_lpaif[port_id] and drvdata->mi2s_lpm[port_id] for all MI2S
DAIs and lpass_cpu_daiops_probe() only checks that the port's LPAIF was
initialized:
sound/soc/qcom/lpass-cpu.c:lpass_cpu_daiops_probe() {
...
/* The LPAIF is only initialized if one of its ports is described in DT */
if (!lpaif || !lpaif->drvdata) {
dev_err(dai->dev, "LPAIF of this port is not enabled\n");
return -ENODEV;
}
...
}
If one port on a multi-port LPM LPAIF (such as lpass-aud-lpaif) is listed
in DT and a sibling port on the same LPAIF relies on the default SD-line
configuration without a child node, the sibling port still probes and
is_lpm_mi2s_port() returns true, but lpass_platform_allocate_lpm() skips it
and leaves drvdata->mi2s_lpm_offset[port_id] at 0, aliasing the buffer of
whichever DAI was allocated at offset 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-topic-sm8650-el2-v2-0-174e159f0f69@linaro.org?part=15
next prev parent reply other threads:[~2026-11-24 18:01 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 17:32 [PATCH v2 00/19] arm64: qcom: enable SM8650 audio without ADSP firmware Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 01/19] ASoC: qcom: lpass-cpu: fix RXTX WRDMA current address register readability Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 02/19] ASoC: qcom: lpass-platform: disable the RXTX & VA DMA interrupts on stop Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 03/19] ASoC: dt-bindings: qcom,lpass: add Senary & Septenary MI2S ids Neil Armstrong
2026-11-25 8:22 ` Krzysztof Kozlowski
2026-11-24 17:32 ` [PATCH v2 04/19] ASoC: dt-bindings: qcom,lpass: add WSA RX and TX channels ids Neil Armstrong
2026-11-25 8:23 ` Krzysztof Kozlowski
2026-11-24 17:32 ` [PATCH v2 05/19] ASoC: dt-bindings: qcom,lpass-*-macro: document less clock when ADSP is not used Neil Armstrong
2026-11-25 8:23 ` Krzysztof Kozlowski
2026-11-24 17:32 ` [PATCH v2 06/19] ASoC: dt-bindings: qcom,lpass-cpu: document the SM8650 LPASS Neil Armstrong
2026-11-25 8:24 ` Krzysztof Kozlowski
2026-11-24 17:32 ` [PATCH v2 07/19] ASoC: codecs: lpass-wsa-macro: handle the macro & dcodec power domains Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 08/19] ASoC: qcom: lpass-cpu: get the optional codec_mem3 clock Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 09/19] ASoC: qcom: lpass: add support for optional WSA interface Neil Armstrong
2026-11-24 17:54 ` sashiko-bot
2026-11-25 8:38 ` Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 10/19] ASoC: qcom: lpass-cdc-dma: add support for WSA codec DMA Neil Armstrong
2026-11-24 17:44 ` sashiko-bot
2026-11-25 8:38 ` Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 11/19] ASoC: qcom: lpass: prepare to handle multiple lpaifs for i2s Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 12/19] ASoC: qcom: lpass: add support for MI2S_SENARY & MI2S_SEPTENARY Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 13/19] ASoC: qcom: lpass: support mapping I2S ports to multiple LPAIFs Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 14/19] ASoC: qcom: lpass: support LPM memory type for I2S LPAIFs Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 15/19] ASoC: qcom: lpass: allocate LPM buffer memory to DAIs Neil Armstrong
2026-11-24 18:01 ` sashiko-bot [this message]
2026-11-25 8:44 ` Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 16/19] ASoC: qcom: lpass: enable the right codec_mem clock when usin LPM memory Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 17/19] ASoC: qcom: add SM8650 LPASS CPU driver Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 18/19] ASoC: qcom: sdw: allow LPASS_CDC_DMA_WSA_RX0 as soundwire dai Neil Armstrong
2026-11-24 17:48 ` sashiko-bot
2026-11-25 8:45 ` Neil Armstrong
2026-11-24 17:32 ` [PATCH v2 19/19] ASoC: qcom: sc8280xp: allow using the sc8280xp card with lpass-cpu Neil Armstrong
2026-11-24 17:56 ` sashiko-bot
2026-11-25 8:46 ` Neil Armstrong
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=sashiko-outbox-231761@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 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.