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 v3 16/19] ASoC: qcom: lpass: enable the right codec_mem clock when usin LPM memory
Date: Fri, 04 Dec 2026 17:28:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-250318@kernel.org> (raw)
In-Reply-To: <20261204-topic-sm8650-el2-v3-16-8384ef0ac751@linaro.org>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ASoC: qcom: lpass: NULL from lpass_cdc_dma_mem_clk() leaves
  LPM unclocked
- [Medium] ASoC: qcom: lpass: u32 underflow in
  lpass_platform_allocate_lpm()
- [Medium] ASoC: qcom: lpass: CPU DAI ops read LPM offsets before
  allocation
- [Low] ASoC: qcom: lpass: duplicate CODEC_MEM_HZ_NORMAL macro in
  lpass-cdc-dma.c
--

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

ASoC: qcom: lpass: enable the right codec_mem clock when usin LPM memory

This commit adds lpass_cdc_dma_mem_clk() to select the codec_mem clock
matching a DMA buffer's LPM offset, updates the codec DMA DAI ops to use
it, and enables the LPM memory clock in the MI2S CPU DAI startup and
shutdown paths for non-core LPAIF ports.

> diff --git a/sound/soc/qcom/lpass-cdc-dma.c b/sound/soc/qcom/lpass-cdc-dma.c
> index d7f85a4f9d999..291c929360435 100644
> --- a/sound/soc/qcom/lpass-cdc-dma.c
> +++ b/sound/soc/qcom/lpass-cdc-dma.c
> @@ -213,8 +215,9 @@ static int lpass_cdc_dma_daiops_startup(struct snd_pcm_substream *substream,
>  		break;
>  	case LPASS_CDC_DMA_WSA_RX0 ... LPASS_CDC_DMA_WSA_RX9:
>  	case LPASS_CDC_DMA_WSA_TX0 ... LPASS_CDC_DMA_WSA_TX8:
> -		clk_set_rate(drvdata->codec_mem1, CODEC_MEM_HZ_NORMAL);
> -		clk_prepare_enable(drvdata->codec_mem1);
> +		mem_clk = lpass_cdc_dma_mem_clk(drvdata, drvdata->wsa_lpm_offset);
> +		clk_set_rate(mem_clk, CODEC_MEM_HZ_NORMAL);
> +		clk_prepare_enable(mem_clk);
>  		break;

[ ... ]

>  	case LPASS_CDC_DMA_WSA_RX0 ... LPASS_CDC_DMA_WSA_RX9:
>  	case LPASS_CDC_DMA_WSA_TX0 ... LPASS_CDC_DMA_WSA_TX8:
> -		clk_disable_unprepare(drvdata->codec_mem1);
> +		mem_clk = lpass_cdc_dma_mem_clk(drvdata, drvdata->wsa_lpm_offset);
> +		clk_disable_unprepare(mem_clk);
>  		break;

[Severity: Medium]
Can lpass_cdc_dma_daiops_startup() and lpass_cpu_daiops_startup() read
wsa_lpm_offset or mi2s_lpm_offset[] before lpass_platform_allocate_lpm()
initializes them?

asoc_qcom_lpass_cpu_platform_probe() registers lpass_cpu_comp_driver before
calling asoc_qcom_lpass_platform_register(), which is where
lpass_platform_allocate_lpm() runs.  Because qcom_snd_parse_of() points
link->platforms->of_node at the CPU node, a rebinding or concurrently
probing machine driver can bind the card and expose PCM devices before the
LPM offsets are assigned:

CPU0                                CPU1
asoc_qcom_lpass_cpu_platform_probe()
  devm_snd_soc_register_component()
    snd_soc_card_rebind()
      ... -> snd_card_register()
                                    snd_pcm_open_substream()
                                      lpass_cdc_dma_daiops_startup()
                                        reads wsa_lpm_offset == 0
                                        clk_prepare_enable(codec_mem0)
  asoc_qcom_lpass_platform_register()
    lpass_platform_allocate_lpm()
      wsa_lpm_offset = 16384
                                      ... -> lpass_cdc_dma_daiops_shutdown()
                                        reads wsa_lpm_offset == 16384
                                        clk_disable_unprepare(codec_mem1)
                                        <-- wrong clock disabled

This leaks a prepare/enable reference on codec_mem0 and triggers CCF
underflow warnings on codec_mem1 (or codec_mem2/codec_mem3 for MI2S ports).
Allocating the LPM offsets before registering lpass_cpu_comp_driver would
close this window.

> diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
> index 8b005a87d4088..a68ca4d4d63c7 100644
> --- a/sound/soc/qcom/lpass-cpu.c
> +++ b/sound/soc/qcom/lpass-cpu.c
> @@ -82,25 +82,57 @@ static int lpass_cpu_daiops_set_sysclk(struct snd_soc_dai *dai, int clk_id,
>  	return ret;
>  }
>  
> +/* LPM memory clock of the MI2S ports using a non-core LPAIF, NULL otherwise */
> +static struct clk *lpass_cpu_mi2s_mem_clk(struct lpass_data *drvdata, unsigned int dai_id)
> +{
> +	unsigned int port_id = mi2s_port_id(dai_id);
> +
> +	if (!is_lpm_mi2s_port(drvdata, dai_id))
> +		return NULL;
> +
> +	if (drvdata->mi2s_lpm[port_id] == LPASS_RXTX_CDC_LPM)
> +		return lpass_cdc_dma_mem_clk(drvdata, drvdata->mi2s_lpm_offset[port_id]);
> +
> +	return drvdata->va_mem0;
> +}
> +
>  static int lpass_cpu_daiops_startup(struct snd_pcm_substream *substream,
>  		struct snd_soc_dai *dai)
>  {
>  	struct lpass_data *drvdata = snd_soc_dai_get_drvdata(dai);
>  	unsigned int port_id = mi2s_port_id(dai->driver->id);
> +	struct clk *mem_clk = lpass_cpu_mi2s_mem_clk(drvdata, dai->driver->id);
>  	int ret;
>  
> +	if (mem_clk) {
> +		ret = clk_set_rate(mem_clk, LPASS_CODEC_MEM_HZ_NORMAL);
> +		if (ret) {
> +			dev_err(dai->dev, "error setting lpm mem clk rate: %d\n", ret);
> +			return ret;
> +		}
> +		ret = clk_prepare_enable(mem_clk);
> +		if (ret) {
> +			dev_err(dai->dev, "error in enabling lpm mem clk: %d\n", ret);
> +			return ret;
> +		}
> +	}

[Severity: Medium]
Does lpass_cpu_daiops_startup() silently leave the LPM SRAM bank unclocked
when lpass_cdc_dma_mem_clk() returns NULL?

of_lpass_cdc_dma_clks_parse() fetches codec_mem3 with
devm_clk_get_optional(), and lpass_cdc_dma_mem_clk() returns NULL both when
block 3 is assigned without codec_mem3 and for any offset >= 64 KiB.
lpass_cpu_mi2s_mem_clk() conflates that NULL with non-LPM MI2S ports, so
startup succeeds without enabling a clock; lpass_cdc_dma_daiops_startup()
has the same issue because CCF helpers treat NULL as a no-op.

Subsequent CPU or DMA accesses to the unclocked LPM bank can fail silently
or trigger a bus fault.  Returning an ERR_PTR for a missing LPM clock or
validating that a backing clock exists in lpass_platform_allocate_lpm()
would catch this cleanly.

> diff --git a/sound/soc/qcom/lpass.h b/sound/soc/qcom/lpass.h
> index 3a37bf9926457..9e18606ef3b89 100644
> --- a/sound/soc/qcom/lpass.h
> +++ b/sound/soc/qcom/lpass.h
> @@ -30,6 +30,8 @@
>  #define LPASS_CDC_DMA_INTF_FOUR_CHANNEL		(0x0F)
>  #define LPASS_CDC_DMA_INTF_SIX_CHANNEL		(0x3F)
>  #define LPASS_CDC_DMA_INTF_EIGHT_CHANNEL	(0xFF)
> +#define LPASS_CDC_DMA_LPM_MEM_BLK_SIZE (2 * 8 * 1024)
> +#define LPASS_CODEC_MEM_HZ_NORMAL		153600000

[Severity: Low]
This isn't a bug, but lpass-cdc-dma.c already includes lpass.h and still
defines its own CODEC_MEM_HZ_NORMAL with the same 153600000 value.  Could
lpass-cdc-dma.c drop the local macro and reuse LPASS_CODEC_MEM_HZ_NORMAL?

[ ... ]

> @@ -292,6 +294,24 @@ static inline bool is_lpm_mi2s_port(struct lpass_data *drvdata, unsigned int dai
>  	return false;
>  }
>  
> +static inline struct clk *lpass_cdc_dma_mem_clk(struct lpass_data *drvdata, u32 offset)
> +{
> +	unsigned int id = offset / LPASS_CDC_DMA_LPM_MEM_BLK_SIZE;
> +
> +	switch (id) {
> +	case 0:
> +		return drvdata->codec_mem0;
> +	case 1:
> +		return drvdata->codec_mem1;
> +	case 2:
> +		return drvdata->codec_mem2;
> +	case 3:
> +		return drvdata->codec_mem3;
> +	default:
> +		return NULL;
> +	}
> +}

[Severity: Medium]
Can an undersized LPM region in DT cause u32 underflow in
lpass_platform_allocate_lpm() and pass out-of-range offsets here?

sound/soc/qcom/lpass-platform.c:lpass_platform_allocate_lpm() {
	...
	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;
	...
}

When the DT LPM region is smaller than the codec DMA allocations (for
example, under 32 KiB for RXTX with WSA enabled), rxtx_cdc_dma_lpm_remain
or va_cdc_dma_lpm_remain wraps around and bypasses the subsequent MI2S
capacity checks.  That passes out-of-bounds physical addresses to memremap()
and io_remap_pfn_range(), and feeds out-of-range offsets to
lpass_cdc_dma_mem_clk().

Checking the remaining size before each codec DMA subtraction would prevent
the underflow.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-topic-sm8650-el2-v3-0-8384ef0ac751@linaro.org?part=16

  reply	other threads:[~2026-12-04 17:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 15:53 [PATCH v3 00/19] arm64: qcom: enable SM8650 audio without ADSP firmware Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 01/19] ASoC: qcom: lpass-cpu: fix RXTX WRDMA current address register readability Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 02/19] ASoC: qcom: lpass-platform: disable the RXTX & VA DMA interrupts on stop Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 03/19] ASoC: dt-bindings: qcom,lpass: add Senary & Septenary MI2S ids Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 04/19] ASoC: dt-bindings: qcom,lpass: add WSA RX and TX channels ids Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 05/19] ASoC: dt-bindings: qcom,lpass-*-macro: document less clock when ADSP is not used Neil Armstrong
2026-12-04 16:20   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 06/19] ASoC: dt-bindings: qcom,lpass-cpu: document the SM8650 LPASS Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 07/19] ASoC: codecs: lpass-wsa-macro: handle the macro & dcodec power domains Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 08/19] ASoC: qcom: lpass-cpu: get the optional codec_mem3 clock Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 09/19] ASoC: qcom: lpass: add support for optional WSA interface Neil Armstrong
2026-12-04 16:49   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 10/19] ASoC: qcom: lpass-cdc-dma: add support for WSA codec DMA Neil Armstrong
2026-12-04 16:47   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 11/19] ASoC: qcom: lpass: prepare to handle multiple lpaifs for i2s Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 12/19] ASoC: qcom: lpass: add support for MI2S_SENARY & MI2S_SEPTENARY Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 13/19] ASoC: qcom: lpass: support mapping I2S ports to multiple LPAIFs Neil Armstrong
2026-12-04 17:10   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 14/19] ASoC: qcom: lpass: support LPM memory type for I2S LPAIFs Neil Armstrong
2026-12-04 17:08   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 15/19] ASoC: qcom: lpass: allocate LPM buffer memory to DAIs Neil Armstrong
2026-12-04 17:33   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 16/19] ASoC: qcom: lpass: enable the right codec_mem clock when usin LPM memory Neil Armstrong
2026-12-04 17:28   ` sashiko-bot [this message]
2026-12-04 15:53 ` [PATCH v3 17/19] ASoC: qcom: add SM8650 LPASS CPU driver Neil Armstrong
2026-12-04 17:42   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 18/19] ASoC: qcom: sdw: allow LPASS_CDC_DMA_WSA_RX0 as soundwire dai Neil Armstrong
2026-12-04 17:52   ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 19/19] ASoC: qcom: sc8280xp: allow using the sc8280xp card with lpass-cpu Neil Armstrong
2026-12-04 17:54   ` 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-250318@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