Linux Sound subsystem development
 help / color / mirror / Atom feed
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 09/19] ASoC: qcom: lpass: add support for optional WSA interface
Date: Tue, 24 Nov 2026 17:54:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-231757@kernel.org> (raw)
In-Reply-To: <20261124-topic-sm8650-el2-v2-9-174e159f0f69@linaro.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ASoC: qcom: lpass: missing wsa_lpaif_map handling in suspend
  and resume
It also noticed 2 related pre-existing issues this patch does not
introduce:
- [Critical] ASoC: qcom: out-of-bounds array writes in
  of_lpass_cpu_parse_dai_data() [1]
- [High] ASoC: qcom: lpass: unchecked memremap() and missing unmap on
  PCM free [2]
--

commit af2e24041ddb606a271caf973ca3eb7d9100c98e
Author: Neil Armstrong <neil.armstrong@linaro.org>

ASoC: qcom: lpass: add support for optional WSA interface

This commit adds regmap, DMA control, IRQ, and buffer management support for
the optional WSA LPAIF interface used by the speaker SoundWire bus.

> diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
> index 3089107442231..db7a0752edb2f 100644
> --- a/sound/soc/qcom/lpass-cpu.c
> +++ b/sound/soc/qcom/lpass-cpu.c
[ ... ]
> @@ -984,6 +1076,16 @@ static struct regmap_config lpass_va_regmap_config = {
>  	.cache_type = REGCACHE_FLAT,
>  };
>  
> +static struct regmap_config lpass_wsa_regmap_config = {
> +	.reg_bits = 32,
> +	.reg_stride = 4,
> +	.val_bits = 32,
> +	.writeable_reg = lpass_wsa_regmap_writeable,
> +	.readable_reg = lpass_wsa_regmap_readable,
> +	.volatile_reg = lpass_wsa_regmap_volatile,
> +	.cache_type = REGCACHE_FLAT,
> +};

[Severity: Medium]
Should lpass_platform_pcmops_suspend() and lpass_platform_pcmops_resume()
also manage drvdata->wsa_lpaif_map when drvdata->wsa_enable is set?

lpass_wsa_regmap_config uses REGCACHE_FLAT and lpass_platform_wsa_hardware
advertises SNDRV_PCM_INFO_RESUME, but suspend and resume only handle
hdmiif_map and lpaif_map.  If the WSA LPAIF block loses register state across
system suspend, resuming a stream via SNDRV_PCM_TRIGGER_RESUME skips
lpass_platform_pcmops_prepare() and never syncs the cached DMA base, buffer,
and period registers back to hardware, while later regmap_update_bits() and
regmap_fields_write() calls can skip hardware writes when the new value
matches the stale flat cache.  Note that later commits in this series
("ASoC: qcom: lpass: support mapping I2S ports to multiple LPAIFs" and
"ASoC: qcom: add SM8650 LPASS CPU driver") do sync the same lpass-wsa-lpaif
regmap across suspend and resume when it is used for MI2S.

> @@ -1046,6 +1148,8 @@ static void of_lpass_cpu_parse_dai_data(struct device *dev,
>  			data->hdmi_port_enable = 1;
>  		} else if (is_cdc_dma_port(id)) {
>  			data->codec_dma_enable = 1;
> +			if (is_wsa_cdc_dma_port(id))
> +				data->wsa_enable = 1;
>  		} else {
>  			data->mi2s_playback_sd_mode[id] =
>  				of_lpass_cpu_parse_sd_lines(dev, node,

[Severity: Critical]
This problem wasn't introduced by this patch, but can
of_lpass_cpu_parse_dai_data() write out of bounds on
data->mi2s_playback_sd_mode[] and data->mi2s_capture_sd_mode[] [1]?

Both arrays are sized to LPASS_MAX_MI2S_PORTS (8), yet the initialization
loop at the top of of_lpass_cpu_parse_dai_data() indexes them by
data->variant->dai_driver[i].id without checking whether the DAI is an MI2S
port (CDC DMA DAI IDs start at 19), and the else branch above indexes them
with an unchecked id read from the Device Tree "reg" property, overwriting
adjacent fields in struct lpass_data.

> diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
> index 9666049ae51b6..99a7ce9ed7695 100644
> --- a/sound/soc/qcom/lpass-platform.c
> +++ b/sound/soc/qcom/lpass-platform.c
[ ... ]
> @@ -1148,6 +1295,14 @@ static int lpass_platform_prealloc_cdc_dma_buffer(struct snd_soc_component *comp
>  		buf->bytes = lpass_platform_va_hardware.buffer_bytes_max;
>  		buf->addr = drvdata->va_cdc_dma_lpm_buf;
>  		break;
> +	case LPASS_CDC_DMA_WSA_RX0 ... LPASS_CDC_DMA_WSA_RX9:
> +		buf->bytes = lpass_platform_wsa_hardware.buffer_bytes_max;
> +		buf->addr = drvdata->rxtx_cdc_dma_lpm_buf + LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> +		break;
> +	case LPASS_CDC_DMA_WSA_TX0 ... LPASS_CDC_DMA_WSA_TX8:
> +		buf->bytes = lpass_platform_wsa_hardware.buffer_bytes_max;
> +		buf->addr = drvdata->rxtx_cdc_dma_lpm_buf + LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 3;
> +		break;
>  	default:
>  		break;
>  	}

[Severity: High]
This problem wasn't introduced by this patch, but
lpass_platform_prealloc_cdc_dma_buffer() does not check the memremap() return
value on buf->area and leaves buf->dev.type set to SNDRV_DMA_TYPE_CONTINUOUS
with no .pcm_free callback to unmap it [2]:

sound/soc/qcom/lpass-platform.c:lpass_platform_prealloc_cdc_dma_buffer() {
	...
	buf->dev.type = SNDRV_DMA_TYPE_CONTINUOUS;
	...
	buf->area = (unsigned char * __force)memremap(buf->addr, buf->bytes, MEMREMAP_WC);

	return 0;
}

If memremap() returns NULL, a subsequent PCM transfer in
lpass_platform_copy() dereferences rt->dma_area.  When the sound card is
unbound, snd_pcm_lib_preallocate_free_for_all() -> do_free_pages() treats the
non-NULL buf->area as SNDRV_DMA_TYPE_CONTINUOUS memory, warns in
decrease_allocated_size(), leaks the mapping, and passes the remapped address
to free_pages_exact().

[1] https://sashiko.dev/#/bug/linux-ac3b3436-c7ff-4bc4-ac2f-8d1aa0b6ad52
[2] https://sashiko.dev/#/bug/linux-c4c01ba7-4086-4d0d-b8e1-8b417f2486e3

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-topic-sm8650-el2-v2-0-174e159f0f69@linaro.org?part=9

  reply	other threads:[~2026-11-24 17:54 UTC|newest]

Thread overview: 25+ 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-24 17:32 ` [PATCH v2 04/19] ASoC: dt-bindings: qcom,lpass: add WSA RX and TX channels ids Neil Armstrong
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-24 17:32 ` [PATCH v2 06/19] ASoC: dt-bindings: qcom,lpass-cpu: document the SM8650 LPASS Neil Armstrong
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 [this message]
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-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
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-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

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-231757@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox