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=1796355662; b=dpV3yMw6R25vTEkl8pDr3apverBwrLxPq5w7QacubsFlnonSkVWHpRVxh/Kt1NoE9gkd V9155R2DrbQShLMSWLgxkwsVgmzsoB3laurM4tnNd8quSR2KY5ilGPhMHBWYYC3MhNvGY I5BKNBiUBYPg+K/MLCQYpXbGmy0wxXFUvKfewPMUhC2IdJqE4IMi/9+Fu+ar6bsv6Nnwm Z8INxVP8AHq7+RZ+HgTs7ZvgwtgvitWiHThZW9BraMC9VgHThRBb4pbTNxZFRY55F49O6 duTG40A0lvQBp2UBH3Wl6xD1Tny32ZvEyOHvpMz2f3DSa649fnzpr3/TiACobIRKlMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796355662; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=KLBEbb5dpkFzw/ORqzMJ9MfIP1nwqR560Cs9b1hJs2c=; b=soHR8pCi9EmJdXUy/o17W6lMv3VI5/3Q2UUKnZQPJbuN2Yn1OjdQTOcAhuquaRB6aSri i8zRKaaiqyAOESX99NTvTCrQmQU8jXdAUKEruyAnQfepBzZKuTHLbhf9Epwq/1d5BM9I+ W/CfWGHDT4D80eTVshGef4Fgd62VfAKwDhGKRKfdFyFflmXSZYwl2lwJCgl5tY2Nsq6G2 7EofnTh44FZZDaUFGag7jREt9AVf7zV19BfC5WtB8XF4H1k7k4Cz29QAEggqZ3KGDwHE7 3MjYlXo9r9X5F2hFaCwo9Wr/8Bpy+va8OY1Hvrun8+sQLFxHBrE4Gq8g9G5jn+Sv8IA== 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=B5A7h7ep; 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 8C641606A322 for ; Fri, 4 Dec 2026 03:41:02 +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=B5A7h7ep Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FDFE1F000C2; Fri, 4 Dec 2026 03:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796355662; bh=KLBEbb5dpkFzw/ORqzMJ9MfIP1nwqR560Cs9b1hJs2c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=B5A7h7epQrHExkaZerwsdUBc8VZ71TnoGOu71RiHQFHyL8urYLJzvtUdw2S4DyvXy an6tMvZuMBNXDZ+FKZhQ7JuzoTI6KTkNgEIaq1zZceexIaRmadybKnkh2tR8qPNOS0 1OjYEatnSXOycmRBwejRrwSHCnix5lqKBLnRcYsK3rDKK+lu+c2fCaGKR8nemUQz66 aGhrdq0kpUqVOe9ZAIlW0e1fOYOvELwFxd33zaoX6doPeZyyYmPJv3Lfm1dv1b2IuI YGlaWOkGD20eUnlquulWzxIHexmy4uB6DtO5CHtxqjF3RZP+qzyBroxHXtjK5p/Q1A o9sTVYvlK6uaA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 2/2] ASoC: ti: omap-mcbsp: Implement set_tdm_slot Reply-To: sashiko-reviews@lists.linux.dev To: "Joseph Telaak" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261203-omap-mcbsp-tdm-slot-v4-2-08985f4284f9@telaak.dev> References: <20261203-omap-mcbsp-tdm-slot-v4-0-08985f4284f9@telaak.dev> <20261203-omap-mcbsp-tdm-slot-v4-2-08985f4284f9@telaak.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 03:41:01 +0000 X-Mailing-List: linux-sound@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: omap-mcbsp: data race in omap_mcbsp_slot_rate_refine() - [Medium] ASoC: omap-mcbsp: sysclk state corrupted on error in set_dai_sysclk() - [Medium] ASoC: omap-mcbsp: stale sysclk_id and in_freq left in omap_mcbsp_remove() - [Medium] ASoC: omap-mcbsp: set_tdm_slot() latches dynamic slots and blocks post-hw_free -- commit 730349fbef80ded0ca4e7f899480736b5797d744 Author: Joseph Telaak ASoC: ti: omap-mcbsp: Implement set_tdm_slot This commit implements the set_tdm_slot() DAI op for omap-mcbsp so generic cards such as simple-audio-card can configure a frame of slots x slot_width bit clocks and let hw_params() compute the SRG divider per sample rate. > diff --git a/sound/soc/ti/omap-mcbsp.c b/sound/soc/ti/omap-mcbsp.c > index 6e0c7d7359f49..0f3925622106b 100644 > --- a/sound/soc/ti/omap-mcbsp.c > +++ b/sound/soc/ti/omap-mcbsp.c > @@ -759,12 +759,242 @@ static int omap_mcbsp_hwrule_min_buffersize(struct= snd_pcm_hw_params *params, > return snd_interval_refine(buffer_size, &frames); > } [ ... ] > +static int omap_mcbsp_slot_rate_refine(struct snd_pcm_hw_params *params, > + struct omap_mcbsp *mcbsp, int stream) > +{ > + struct snd_interval *rate =3D hw_param_interval(params, > + SNDRV_PCM_HW_PARAM_RATE); > + unsigned int list[ARRAY_SIZE(omap_mcbsp_slot_rates)]; > + unsigned int n; > + > + /* Slots cleared since open: no rates to compute */ > + if (!omap_mcbsp_slots_on(mcbsp)) > + return 0; > + /* Both directions share the sample rate generator */ > + if (omap_mcbsp_slot_other(mcbsp, stream)) > + return snd_interval_list(rate, 1, &mcbsp->slot_rate, 0); > + /* A sysclk a card sets in hw_params() is checked there */ > + if (!mcbsp->sysclk_static || !omap_mcbsp_slot_sysclk(mcbsp)) > + return 0; > + > + n =3D omap_mcbsp_slot_rate_list(mcbsp, list); > + return snd_interval_list(rate, n, list, 0); > +} [Severity: Medium] Can omap_mcbsp_slot_rate_refine() race with concurrent hw_params(), hw_free(), or set_tdm_slot() calls on the opposite direction? snd_pcm_hw_refine_with_lock() only holds the target substream's runtime->buffer_mutex, while soc_pcm_hw_params() and soc_pcm_hw_free() hold rtd->card->pcm_mutex. Neither path takes mcbsp->lock, so on SMP OMAP4/5 systems the two directions access the shared slot and clock fields without synchronization: CPU0 (capture hw_refine) CPU1 (playback hw_params) snd_pcm_hw_refine_with_lock() soc_pcm_hw_params() lock(&runtime->buffer_mutex) lock(&card->pcm_mutex) omap_mcbsp_slot_rate_refine() omap_mcbsp_dai_hw_params() if (omap_mcbsp_slot_other()) snd_interval_list(..., &mcbsp->slot_rate, 0) min(..., list[0]) mcbsp->slot_rate =3D new_rate; max(..., list[0]) <-- data race / mismatched min & max snd_interval_list() dereferences list[0] three times (snd_interval_test(), min(), and max()), so a concurrent single-stream rate change overwriting mcbsp->slot_rate can leave list_range.min > list_range.max and fail refinement with -EINVAL. Without ordering between mcbsp->slot_rate and mcbsp->slot_streams, CPU0 can also see the new slot_streams bit with a stale or zero slot_rate. Similarly, concurrent set_tdm_slot() or set_dai_sysclk() updates can mutate slots, slot_width, or in_freq across omap_mcbsp_slot_rate_refine() and omap_mcbsp_slot_div(), which reads mcbsp->in_freq three times. Protecting these fields with mcbsp->lock and snapshotting slot_rate into a local variable before calling snd_interval_list() would avoid the race. [ ... ] > @@ -1184,6 +1449,67 @@ static int omap_mcbsp_dai_set_clkdiv(struct snd_so= c_dai *cpu_dai, > return 0; > } [ ... ] > + /* The other direction may already run with the current slots */ > + if (mcbsp->configured) { > + if (slots =3D=3D mcbsp->slots && slot_width =3D=3D mcbsp->slot_width && > + tx =3D=3D mcbsp->tx_slots && rx =3D=3D mcbsp->rx_slots) > + return 0; > + return -EBUSY; > + } > + > + /* Back to the set_clkdiv() divider */ > + if (mcbsp->slot_width && !slot_width) { > + mcbsp->cfg_regs.srgr1 &=3D ~CLKGDV(0xff); > + mcbsp->cfg_regs.srgr1 |=3D > + CLKGDV((mcbsp->clk_div ? mcbsp->clk_div : 1) - 1); > + } > + > + mcbsp->slots =3D slots; > + mcbsp->slot_width =3D slot_width; > + mcbsp->tx_slots =3D tx; > + mcbsp->rx_slots =3D rx; [Severity: Medium] Will dynamic per-stream set_tdm_slot() callers get locked into the first stream's width and hit -EBUSY after hw_free()? audio-graph-card2 with dai-tdm-slot-width-map calls snd_soc_dai_set_tdm_slo= t() per stream from simple_util_hw_params() -> simple_set_tdm(). Unlike set_dai_sysclk(), which tracks sysclk_static, set_tdm_slot() does not distinguish init-time slots from dynamic ones and neither hw_free() nor shutdown() clears them, so on later opens omap_mcbsp_slot_constraints() pins CHANNELS and SAMPLE_BITS to the first stream's width and rejects other formats before simple_set_tdm() can run. In addition, omap_mcbsp_dai_hw_free() clears mcbsp->slot_streams while mcbsp->configured stays set until shutdown(). Reconfiguring an open stream via hw_free() -> hw_params() with a different slot width then fails with -EBUSY here because this checks mcbsp->configured instead of mcbsp->active || mcbsp->slot_streams. > @@ -1192,13 +1518,19 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct s= nd_soc_dai *cpu_dai, > struct omap_mcbsp_reg_cfg *regs =3D &mcbsp->cfg_regs; > int err =3D 0; > =20 > - if (mcbsp->active) { > + /* With slots, a configured stream holds the sysclk until hw_free() */ > + if (mcbsp->active || mcbsp->slot_streams) { > if (freq =3D=3D mcbsp->in_freq) > return 0; > else > return -EBUSY; > } > =20 > + /* Set outside a stream, it holds for the next open */ > + if (!snd_soc_dai_active(cpu_dai)) > + mcbsp->sysclk_static =3D true; > + else if (freq !=3D mcbsp->in_freq) > + mcbsp->sysclk_static =3D false; > mcbsp->in_freq =3D freq; > regs->srgr2 &=3D ~CLKSM; > regs->pcr0 &=3D ~SCLKME; > @@ -1243,6 +1575,8 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd= _soc_dai *cpu_dai, > default: > err =3D -ENODEV; > } > + if (!err) > + mcbsp->sysclk_id =3D clk_id; > =20 > return err; > } [Severity: Medium] Does omap_mcbsp_dai_set_dai_sysclk() leave sysclk_static, in_freq, and cfg_regs out of sync with sysclk_id when setting the clock fails? mcbsp->sysclk_static, mcbsp->in_freq, and the CLKSM/SCLKME bits in cfg_regs are overwritten before switch (clk_id) runs, while only mcbsp->sysclk_id is gated on !err. If omap2_mcbsp_set_clks_src() fails or clk_id is unsupporte= d, later TDM slot checks evaluate the old sysclk_id against the rejected frequency and sysclk_static flag. Also, the early return when mcbsp->active || mcbsp->slot_streams is set only checks freq =3D=3D mcbsp->in_freq, so requesting a different clk_id at the = same frequency silently returns 0 instead of -EBUSY. > @@ -1266,6 +1600,13 @@ static int omap_mcbsp_remove(struct snd_soc_dai *d= ai) > =20 > pm_runtime_disable(mcbsp->dev); > =20 > + /* The slots belong to the card that set them */ > + mcbsp->slots =3D 0; > + mcbsp->slot_width =3D 0; > + mcbsp->tx_slots =3D 0; > + mcbsp->rx_slots =3D 0; > + mcbsp->sysclk_static =3D false; > + > return 0; > } [Severity: Medium] Should omap_mcbsp_remove() also reset mcbsp->sysclk_id and mcbsp->in_freq? struct omap_mcbsp persists across card unbind and rebind. If a prior card left OMAP_MCBSP_SYSCLK_CLKX_EXT or OMAP_MCBSP_SYSCLK_CLKR_EXT in sysclk_id, omap_mcbsp_slots_on() returns false for a newly bound card and silently disables TDM slot mode; a stale in_freq with OMAP_MCBSP_SYSCLK_CLKS_EXT likewise bypasses the missing-sysclk and fclk checks in omap_mcbsp_slot_params_check(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-omap-mcbsp= -tdm-slot-v4-0-08985f4284f9@telaak.dev?part=3D2