From: sashiko-bot@kernel.org
To: "David Heidelberg" <david@ixit.cz>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH RFC v2 5/6] ASoC: cs35l36: Implement set_tdm_slot to program RX and TX slots
Date: Thu, 03 Sep 2026 18:40:56 +0000 [thread overview]
Message-ID: <20260903184056.B225E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260903-pixel3-audio-v2-5-7c22ed915291@ixit.cz>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unmapped TDM channels are not disabled and retain their default slot assignments, leading to TDM slot collisions.
- [High] The new set_tdm_slot configures the RX TDM slot via a register that aliases an existing ALSA user control, introducing state corruption.
--
commit af0d8ef24a330447b6254f7aa04fa7142a333d1b
Author: David Heidelberg <david@ixit.cz>
ASoC: cs35l36: Implement set_tdm_slot to program RX and TX slots
This commit implements the set_tdm_slot DAI operation for the CS35L36 codec,
allowing machine drivers to program ASP RX and TX slots. It maps bits in the
provided RX and TX masks to consecutive codec channels, and sets hardware
defaults if no slots are passed.
> diff --git a/sound/soc/codecs/cs35l36.c b/sound/soc/codecs/cs35l36.c
> index 89645327945f1..4d35ca6291548 100644
> --- a/sound/soc/codecs/cs35l36.c
> +++ b/sound/soc/codecs/cs35l36.c
[ ... ]
> @@ -947,10 +947,54 @@ static const struct cs35l36_pll_config *cs35l36_get_clk_config(
> return NULL;
> }
>
> +static void cs35l36_mask_to_slots(struct cs35l36_private *cs35l36,
> + unsigned long mask, unsigned int base_reg,
> + unsigned int nchan)
> +{
> + unsigned int chan = 0, shift;
> + int slot;
> +
> + /* Two 6-bit slot fields per register, at bits 0 and 16 */
> + for_each_set_bit(slot, &mask, BITS_PER_TYPE(mask)) {
> + if (chan == nchan) {
> + dev_warn(cs35l36->dev,
> + "Too many slots in TDM mask: %lx\n", mask);
> + return;
> + }
> +
> + shift = (chan % 2) * CS35L36_ASP_TX2_SLOT_SHIFT;
> + regmap_update_bits(cs35l36->regmap, base_reg + (chan / 2) * 4,
> + CS35L36_ASP_RX1_SLOT_MASK << shift,
> + slot << shift);
> + chan++;
> + }
[Severity: High]
What happens to the remaining hardware channels if the provided mask has fewer
set bits than the total number of hardware channels?
The loop finishes processing once all set bits are consumed, which seems to
ignore the remaining hardware channels and leaves them in a potentially
dangerous active state on their default slots.
For example, if a machine driver passes a tx_mask with fewer set bits than the
total number of hardware channels (8) to map a subset of slots (e.g.,
tx_mask = 0x30 to use slots 4 and 5), this loop assigns those slots to the
first channels (ASPTX1 and ASPTX2). It terminates early without modifying the
remaining channels (ASPTX3..8), leaving them at their hardware default slots
(slots 2..7).
If DAPM later enables these unmapped channels (e.g., via the 'AMP Capture'
path), they will transmit on their default slots. In this example, ASPTX5
defaults to slot 4, which collides directly with the explicitly mapped ASPTX1
on slot 4.
> +}
> +
> +static int cs35l36_set_tdm_slot(struct snd_soc_dai *dai,
> + unsigned int tx_mask, unsigned int rx_mask,
> + int slots, int slot_width)
> +{
> + struct cs35l36_private *cs35l36 =
> + snd_soc_component_get_drvdata(dai->component);
> +
> + /* Note: rx/tx is from point of view of the CPU end */
> + if (!slots || !rx_mask)
> + rx_mask = BIT(0); /* ASPRX1 in slot 0 */
> +
> + if (!slots || !tx_mask)
> + tx_mask = GENMASK(7, 0); /* ASPTX1..8 in slots 0..7 */
> +
> + cs35l36_mask_to_slots(cs35l36, rx_mask, CS35L36_ASP_RX1_SLOT, 1);
[Severity: High]
Does configuring the RX TDM slot via CS35L36_ASP_RX1_SLOT alias an existing
ALSA user control?
The driver exposes bit 0 of this exact register to userspace as a DAPM audio
routing control ('Input Mux') here:
sound/soc/codecs/cs35l36.c:
static SOC_ENUM_SINGLE_DECL(chansel_enum, CS35L36_ASP_RX1_SLOT, 0,
cs35l36_chan_text);
Because both the DAI configuration callback and an ALSA user control manage the
LSB of this register, will saving and restoring ALSA state (e.g., via
alsactl restore on boot) silently overwrite bit 0 of the TDM slot configured
by the machine driver?
For example, if the machine driver configures TDM slot 4 (binary 100), and
userspace restores 'RX2' (value 1), the slot will be corrupted to 5
(binary 101), breaking the machine driver's hardware configuration.
> + cs35l36_mask_to_slots(cs35l36, tx_mask, CS35L36_ASP_TX1_TX2_SLOT, 8);
> +
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260903-pixel3-audio-v2-0-7c22ed915291@ixit.cz?part=5
next prev parent reply other threads:[~2026-09-03 18:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 18:26 [PATCH RFC v2 0/6] Speakers for Pixel 3 / 3 XL David Heidelberg via B4 Relay
2026-09-03 18:26 ` David Heidelberg
2026-09-03 18:26 ` [PATCH RFC v2 1/6] ASoC: qcom: sdm845: Demystify TDM masks a bit David Heidelberg via B4 Relay
2026-09-03 18:26 ` David Heidelberg
2026-09-03 18:40 ` sashiko-bot
2026-09-03 18:26 ` [PATCH RFC v2 2/6] ASoC: qcom: sdm845: use DSP_A format for TDM codec DAIs David Heidelberg via B4 Relay
2026-09-03 18:26 ` David Heidelberg
2026-09-03 18:26 ` [PATCH RFC v2 3/6] ASoC: qcom: sdm845: Use per-speaker RX masks for TDM slot assignment David Heidelberg via B4 Relay
2026-09-03 18:26 ` David Heidelberg
2026-09-03 18:41 ` sashiko-bot
2026-09-03 18:26 ` [PATCH RFC v2 4/6] ASoC: qcom: sdm845: Set codec dai and component sysclk during startup David Heidelberg via B4 Relay
2026-09-03 18:26 ` David Heidelberg
2026-09-03 18:40 ` sashiko-bot
2026-09-03 18:26 ` [PATCH RFC v2 5/6] ASoC: cs35l36: Implement set_tdm_slot to program RX and TX slots David Heidelberg via B4 Relay
2026-09-03 18:26 ` David Heidelberg
2026-09-03 18:40 ` sashiko-bot [this message]
2026-09-04 8:22 ` Konrad Dybcio
2026-09-04 9:26 ` Charles Keepax
2026-09-04 9:23 ` Charles Keepax
2026-09-03 18:26 ` [PATCH RFC v2 6/6] arm64: dts: qcom: sdm845-google: Add basic audio support David Heidelberg via B4 Relay
2026-09-03 18:26 ` David Heidelberg
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=20260903184056.B225E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=david@ixit.cz \
--cc=devicetree@vger.kernel.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.