From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796405338; b=feEG6zFqG2bjyDJhOjsOe34D+JSEd0F9cqhQ/EZF6BqAzmvhIjQMeg4AmYO50Yhk/2/A g1JRviHsloN0kRSCjc6X/ZIFtzA55etRAncqJ+deX41T7kqZb/N77GnxKe3iuh+NSQ1Wb 3ETBPSqZGyoeifmKq0n9Vd3ZEDVK/MNz4Xepwt2qIFaVmZOe4QFlQz2f0jjE+b4PDK3wB XtXjoc+6fs/aQT0cs3njEBi7b5kfxKheUDb3ZTO/LGWza/tkiMYXh1zScNh+gbuBHvW/L 0gX6q4wK1UVqa0syXhYhd91w/ZAe3QVR9CvXTqSGjeOuOE8Acr5NsPl2NTNx0i+gHFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796405338; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=OrbZhus/DBtS5B4FJLg6hL7Kuw44xCwnL6Hlf4PuvQQ=; b=2gJPdCJFjwdRaEKri3+7mFreAAcWuehfPC6K37IjpGNkD6ZVw09jL2I86aofviTXQgkp lg2t/ZAboYdTZaASMdIqcdDwyztqFHJ7FE7ZLoU7YnPmLtTwMQfFnnoV0lEkEqFNZ0evb /1hDuC/Rw0ZmqsPjMvYD2MFN7aHzyY57BeBUTLFcgjlojwSd2DQr1VQGhBQGA+28Kv1r7 4pLQNrVtBJU4x5rdFjiqh+L3/fKNfvqfTdiQ5dSKLDB0wdCReDojTT8Y57tazWiJlosDz AGZCatl+WKRg5Ptq2n5prt76bLeAMJwxS+pOeTNvb6qm9h8iHM7DNX/Xjwlh6g2+ohQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ApZmtQ2A; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECBF4606A322; Fri, 4 Dec 2026 17:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ApZmtQ2A Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61D041F00936; Fri, 4 Dec 2026 17:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796405337; bh=OrbZhus/DBtS5B4FJLg6hL7Kuw44xCwnL6Hlf4PuvQQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ApZmtQ2AdrGiPwKWO/99Rkq1UmWVmHp1uTXSN6jZjksg/A+1vn9JJcKrU08bY7tHE 93Xujxh4fG98Wp/ocgqM59VUBFl8Hd4TPiPOpxnxMNl8GoYUSmnJakGi6sFN7ztulJ lvwdTP13+1p97BQxogErKglzBDRatXfyM7txaYZoRUfORQizNpxS1JRd3X/s48jM9B Di+QPc/z6kzuYqWvNt6YuNaXYo81JOlrCyIlMSxwNVzoeAGPJtxso4KT6Hf3rH22NV +lMXEK5KbMNW1sJofkakKdMYvV2cSLEVItD1K4ZHolkXjlp1gqChfDoTBkD99koLa0 eAoLXUBfOYWlQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 16/19] ASoC: qcom: lpass: enable the right codec_mem clock when usin LPM memory Reply-To: sashiko-reviews@lists.linux.dev To: "Neil Armstrong" Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204-topic-sm8650-el2-v3-16-8384ef0ac751@linaro.org> References: <20261204-topic-sm8650-el2-v3-0-8384ef0ac751@linaro.org> <20261204-topic-sm8650-el2-v3-16-8384ef0ac751@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:28:57 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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-dm= a.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_pc= m_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 =3D 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 =3D 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 =3D=3D 0 clk_prepare_enable(codec_mem0) asoc_qcom_lpass_platform_register() lpass_platform_allocate_lpm() wsa_lpm_offset =3D 16384 ... -> lpass_cdc_dma_daiops_shutdown() reads wsa_lpm_offset =3D=3D 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; > } > =20 > +/* LPM memory clock of the MI2S ports using a non-core LPAIF, NULL other= wise */ > +static struct clk *lpass_cpu_mi2s_mem_clk(struct lpass_data *drvdata, un= signed int dai_id) > +{ > + unsigned int port_id =3D mi2s_port_id(dai_id); > + > + if (!is_lpm_mi2s_port(drvdata, dai_id)) > + return NULL; > + > + if (drvdata->mi2s_lpm[port_id] =3D=3D 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 =3D snd_soc_dai_get_drvdata(dai); > unsigned int port_id =3D mi2s_port_id(dai->driver->id); > + struct clk *mem_clk =3D lpass_cpu_mi2s_mem_clk(drvdata, dai->driver->id= ); > int ret; > =20 > + if (mem_clk) { > + ret =3D 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 =3D 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 >=3D 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_dat= a *drvdata, unsigned int dai > return false; > } > =20 > +static inline struct clk *lpass_cdc_dma_mem_clk(struct lpass_data *drvda= ta, u32 offset) > +{ > + unsigned int id =3D 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 =3D rxtx_cdc_dma_lpm_offset; rxtx_cdc_dma_lpm_offset +=3D LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2; rxtx_cdc_dma_lpm_remain -=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-topic-sm86= 50-el2-v3-0-8384ef0ac751@linaro.org?part=3D16