From: sashiko-bot@kernel.org
To: liuchen <2508871010@qq.com>, linux-sound@vger.kernel.org
Subject: Re: [PATCH] ASoC: wcd937x: bound the DT channel mapping to the channel
Date: Mon, 16 Nov 2026 07:27:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-216422@kernel.org> (raw)
In-Reply-To: <tencent_5E8B535138DB2906DF4871E24590DA458A06@qq.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] ASoC: wcd937x: single-word handle used in Signed-off-by trailer
- [Low] ASoC: wcd937x: stale ret check in wcd9370_probe() after clamping
size
- [Low] ASoC: wcd937x: Fixes trailer cites wrong commit in commit
message
--
commit e110cdb8f270ccdee8cfffae54f7844e1377eb32
Author: liuchen <2508871010@qq.com>
> ASoC: wcd937x: bound the DT channel mapping to the channel tables
>
> wcd9370_probe() copies qcom,{tx,rx}-channel-mapping into the per-channel
> tables with the length of the DT property as the loop bound. Nothing
> checks that the property describes no more channels than
> wcd937x_sdw_tx_ch_info[] (11 entries) and wcd937x_sdw_rx_ch_info[]
> (8 entries) hold.
>
> The DT binding requires exactly 12 entries for qcom,tx-channel-mapping
> ("adc1, adc2, adc3, dmic0, dmic1, mbhc, dmic2, dmic3, dmic4, dmic5,
> dmic6, dmic7"), while the driver's table stops at WCD937X_DMIC6, i.e. 11
> channels. Any board that follows the binding therefore writes one entry
> past the end of the table; both boards in mainline that use the property
> do so (qcm6490-idp.dts and sm7150-xiaomi-davinci.dtsi both spell out 12
> values).
>
> Both tables live in .data right next to each other, so the stray write
> lands in wcd937x_sdw_rx_ch_info[0].ch_mask. The 12th value, 4, stores
> WCD937X_SWRM_CH_MASK(4) == 0x8 into HPH_L; the codec then asks for
> SoundWire RX channel 4 (EN_CHAN = 0x8) while the AFE keeps sending two
> channels (active_channels_mask = 0x3). The CDC DMA never completes a
> block, the DSP never reports WRITE_DONE, and playback on the RX codec
> DMA path fails with -EIO after the wait_for_avail() timeout.
>
> Clamp the property length to the scratch buffer before reading it and to
> the table size before filling it in, so that an over-long mapping is
> ignored instead of corrupting the RX table.
>
> The overflow was found while debugging RX codec DMA playback (no
> WRITE_DONE from the DSP, playback failing with -EIO) on an SM7150 phone:
> a temporary printk showed exactly one entry of the runtime table
> differing from .data, which led to the 12th iteration of the loop.
> Diagnosis, patch and this changelog were produced with the help of an AI
> coding assistant (Claude, Anthropic); the submitter reviewed the change,
> built it for arm64 with W=1 and verified on that phone that playback now
> completes and that the codec enables SoundWire RX channels 1 and 2
> (EN_CHAN = 0x3) instead of channel 4 (0x8).
>
> Not done: qcm6490-idp was not booted, there was no KASAN or reproducer
> other than the phone, and the DT binding still advertises 12 TX channels
> while the table holds 11, so a conforming mapping now has its last entry
> ignored instead of written out of bounds (binding update left as a
> follow-up).
>
> Fixes: c99a515ff153 ("ASoC: codecs: wcd937x-sdw: add SoundWire driver")
> Signed-off-by: liuchen <2508871010@qq.com>
[Severity: High]
The Author header and Signed-off-by trailer use a single-word handle
("liuchen") instead of a full real name as required by the Developer's
Certificate of Origin in Documentation/process/submitting-patches.rst.
[Severity: Low]
In commit c99a515ff153 ("ASoC: codecs: wcd937x-sdw: add SoundWire driver"),
wcd937x_sdw_rx_ch_info and wcd937x_sdw_tx_ch_info were const arrays and
wcd9370_probe() did not parse qcom,tx-channel-mapping or
qcom,rx-channel-mapping. Should the Fixes: tag instead point to the commit
that introduced static channel mapping support:
Fixes: c06c4f7cbea1 ("ASoC: codecs: wcd937x: Add static channel mapping support in wcd937x-sdw")
> diff --git a/sound/soc/codecs/wcd937x-sdw.c b/sound/soc/codecs/wcd937x-sdw.c
> index 57549518767ce..baacfef6c9cb4 100644
> --- a/sound/soc/codecs/wcd937x-sdw.c
> +++ b/sound/soc/codecs/wcd937x-sdw.c
> @@ -1003,6 +1003,8 @@ static int wcd9370_probe(struct sdw_slave *pdev,
> if (wcd->is_tx) {
> master_ch_mask_size = of_property_count_u8_elems(dev->of_node,
> "qcom,tx-channel-mapping");
> + master_ch_mask_size = clamp(master_ch_mask_size, 0,
> + (int)ARRAY_SIZE(master_ch_mask));
>
> if (master_ch_mask_size)
> ret = of_property_read_u8_array(dev->of_node, "qcom,tx-channel-mapping",
> @@ -1010,6 +1012,8 @@ static int wcd9370_probe(struct sdw_slave *pdev,
> } else {
> master_ch_mask_size = of_property_count_u8_elems(dev->of_node,
> "qcom,rx-channel-mapping");
> + master_ch_mask_size = clamp(master_ch_mask_size, 0,
> + (int)ARRAY_SIZE(master_ch_mask));
>
> if (master_ch_mask_size)
> ret = of_property_read_u8_array(dev->of_node, "qcom,rx-channel-mapping",
[Severity: Low]
Does clamping master_ch_mask_size to 0 before checking
if (master_ch_mask_size) leave ret holding the stale return value from the
earlier port-mapping read when the optional channel-mapping property is
absent?
When qcom,tx-channel-mapping or qcom,rx-channel-mapping is omitted from the
Device Tree, of_property_count_u8_elems() returns a negative error code.
Previously, if (master_ch_mask_size) was true for negative values, so
of_property_read_u8_array() ran and set ret to a negative error code.
Clamping master_ch_mask_size to 0 skips of_property_read_u8_array(), so the
subsequent check in wcd9370_probe():
sound/soc/codecs/wcd937x-sdw.c:wcd9370_probe() {
...
if (ret < 0)
dev_info(dev, "Static channel mapping not specified using device channel maps\n");
}
evaluates the return status of of_property_read_u32_array() for
qcom,tx-port-mapping or qcom,rx-port-mapping instead, suppressing the
fallback message when port mapping succeeded.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_5E8B535138DB2906DF4871E24590DA458A06@qq.com?part=1
prev parent reply other threads:[~2026-11-16 7:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:09 [PATCH] ASoC: wcd937x: bound the DT channel mapping to the channel liuchen
2026-11-16 7:27 ` sashiko-bot [this message]
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-216422@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=2508871010@qq.com \
--cc=linux-sound@vger.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