From: sashiko-bot@kernel.org
To: "Srinivas Kandagatla" <srinivas.kandagatla@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
Date: Fri, 04 Dec 2026 13:43:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-249890@kernel.org> (raw)
In-Reply-To: <20261204113101.1141644-15-srinivas.kandagatla@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 13 potential
issues to consider:
- [High] ASoC: audioreach: call to deleted audioreach_sp_disarm_vi()
breaks build
- [High] ASoC: audioreach: argument mismatch calling
audioreach_speaker_protection_vi()
- [High] ASoC: qcom: audioreach: UAF on unload after removing
audioreach_sp_shutdown()
- [Medium] ASoC: audioreach: race in audioreach_sp_finish_calibration()
watchdog cancel
- [Medium] ASoC: audioreach: watchdog timeout leaves sp_vi_r0.armed set
- [Medium] ASoC: qcom: audioreach: VI speaker-count checked after
partial DSP config
- [Medium] ASoC: qcom: audioreach: TOCTOU race on sp_operation_mode
during VI setup
- [Medium] ASoC: qcom: audioreach: watchdog race in
audioreach_sp_finish_calibration()
- [Medium] ASoC: qcom: audioreach: watchdog timeout leaves
sp_vi_r0.armed set
- [Medium] ASoC: qcom: audioreach: calibration state not unwound on VI
config error
- [Medium] ASoC: qcom: missing num_ch check in
audioreach_vi_calibration_event()
- [Low] ASoC: qcom: audioreach: broken fixed-point R0/T0 diagnostic log
formatting
- [Low] ASoC: qcom: audioreach: zero-channel event wipes cached R0/T0
calibration
--
commit 0bca08e0faa877f7524d142ce001fdb361728129
Author: Ravi Hothi <ravi.hothi@oss.qualcomm.com>
ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode
This commit caches calibrated speaker R0/T0 values and sends them to the
VI module via PARAM_ID_SP_TH_VI_R0T0_CFG in normal mode. It also
removes audioreach_sp_disarm_vi() and audioreach_sp_shutdown(), changes
watchdog cancellation in audioreach_sp_finish_calibration(), and adjusts
the signature of audioreach_speaker_protection_vi().
> diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
> index be37681f467fb..3555c97c2000d 100644
> --- a/sound/soc/qcom/qdsp6/audioreach.c
> +++ b/sound/soc/qcom/qdsp6/audioreach.c
[ ... ]
> @@ -1475,37 +1493,20 @@ u32 audioreach_get_sp_operation_mode(void)
> static void audioreach_sp_cal_watchdog_fn(struct work_struct *work);
> static DECLARE_DELAYED_WORK(sp_cal_watchdog, audioreach_sp_cal_watchdog_fn);
>
> -static void audioreach_sp_disarm_vi(void)
> -{
> - guard(mutex)(&sp_vi_r0_lock);
> - sp_vi_r0.armed = false;
> -}
> -
> static void audioreach_sp_cal_watchdog_fn(struct work_struct *work)
> {
> if (cmpxchg(&sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_CALIBRATION,
> - PARAM_ID_SP_VI_OP_MODE_NORMAL) !=
> + PARAM_ID_SP_VI_OP_MODE_NORMAL) ==
> PARAM_ID_SP_VI_OP_MODE_CALIBRATION)
> - return;
> -
> - audioreach_sp_disarm_vi();
> - pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
> + pr_info("audioreach: SP calibration watchdog fired, back to Normal\n");
> }
[Severity: Medium]
Does removing audioreach_sp_disarm_vi() from audioreach_sp_cal_watchdog_fn()
leave sp_vi_r0.armed set to true when the 60-second watchdog expires?
If a timed-out VI graph remains open and emits a late
EVENT_ID_VI_PER_SPKR_CALIBRATION event, audioreach_vi_calibration_event()
passes its sp_vi_r0.armed check, overwrites sp_vi_r0 and sp_vi_r0t0_cfg,
and calls audioreach_sp_finish_calibration(), aborting any newly triggered
calibration run.
>
> -/* Finish before writing the mode so a trigger racing in cannot be clobbered */
> static void audioreach_sp_finish_calibration(void)
> {
> - cancel_delayed_work_sync(&sp_cal_watchdog);
> WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL);
> + cancel_delayed_work(&sp_cal_watchdog);
> }
[Severity: Medium]
Can writing PARAM_ID_SP_VI_OP_MODE_NORMAL before calling
cancel_delayed_work() cancel a newly triggered calibration's watchdog?
CPU0 CPU1
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
..._NORMAL)
audioreach_trigger_sp_calibration()
cmpxchg(NORMAL -> CALIBRATION)
schedule_delayed_work(...)
cancel_delayed_work(&sp_cal_watchdog)
<-- cancels CPU1's watchdog
Without its watchdog, sp_operation_mode can remain stuck in calibration
mode indefinitely if no calibration playback completes, rejecting later
triggers with -EBUSY. If cancel_delayed_work_sync() is restored together
with disarming sp_vi_r0 under sp_vi_r0_lock in the watchdog, callers such
as audioreach_vi_calibration_event() must drop sp_vi_r0_lock before
calling audioreach_sp_finish_calibration() to avoid an ABBA deadlock.
[Severity: Medium]
Can switching from cancel_delayed_work_sync() to asynchronous
cancel_delayed_work() allow an already-running watchdog to abort a newly
triggered calibration run?
CPU0 kworker
audioreach_sp_finish_calibration()
WRITE_ONCE(sp_operation_mode,
..._NORMAL)
cancel_delayed_work(&sp_cal_watchdog)
(does not wait for running worker)
audioreach_sp_cal_watchdog_fn()
audioreach_trigger_sp_calibration()
cmpxchg(NORMAL -> CALIBRATION)
cmpxchg(CALIBRATION -> NORMAL)
<-- aborts new run
Cancelling synchronously before publishing Normal mode prevents the stale
worker from observing the new calibration state.
[ ... ]
> @@ -1559,6 +1560,86 @@ static int sp_vi_q24_to_int_frac(s32 val, int *frac)
> return val >> 24;
> }
[ ... ]
> + for (i = 0; i < num_ch; i++) {
> + long r0 = vals[2 * i];
> + long t0 = vals[2 * i + 1];
> + int r0_int, r0_frac;
> +
> + if (r0 < SP_VI_R0_MIN_Q24 || r0 > SP_VI_R0_MAX_Q24) {
> + r0_int = sp_vi_q24_to_int_frac(r0, &r0_frac);
> + dev_err(dev, "Channel %u R0 %d.%03d ohms (Q24 %ld) out of range\n",
> + i, r0_int, r0_frac, r0);
> + return -ERANGE;
> + }
> +
> + if (t0 < SP_VI_T0_MIN_Q6 || t0 > SP_VI_T0_MAX_Q6) {
> + dev_err(dev, "Channel %u T0 %ld.%03ld degC (Q6 %ld) out of range\n",
> + i, t0 / 64, abs((t0 % 64) * 1000 / 64), t0);
> + return -ERANGE;
> + }
> +
> + new.r0_cali_q24[i] = r0;
> + new.t0_cali_q6[i] = t0;
> + }
[Severity: Low]
Will these logs misformat negative fractional T0 values and out-of-range
R0 values?
For valid negative temperatures between -1 and 0 degC (t0 in [-63, -1]),
t0 / 64 is 0, so %d.%03d drops the minus sign (for example, -32 logs as
0.500 degC here and in audioreach_speaker_protection_vi()). When r0 is
out of range, passing a 64-bit long to sp_vi_q24_to_int_frac(s32, ...)
truncates values outside s32 range, and negative Q24 values are printed
with the wrong magnitude (for example, -(1 << 23) logs as -1.500 ohms).
[ ... ]
> @@ -1623,6 +1704,14 @@ void audioreach_vi_calibration_event(struct device *dev,
> i, r0_int, r0_frac, sp_vi_r0.r0_cali_q24[i]);
> }
>
> + /* Only a run where every speaker succeeded gives a usable R0/T0 set */
> + if (success) {
> + guard(mutex)(&sp_vi_r0t0_cfg_lock);
> + sp_vi_r0t0_cfg.num_ch = num_ch;
> + for (i = 0; i < num_ch; i++)
> + sp_vi_r0t0_cfg.r0_cali_q24[i] = cali->cali_param[i].r0_cali_q24;
> + }
> +
> dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "failed");
[Severity: Medium]
Can a zero-channel calibration event wipe a previously stored R0/T0 set
here?
q6apm_vi_calibration_event() forwards num_ch = 0 when cali->num_ch is 0
or the payload contains no cali_param entries. Without an early return
for !num_ch in audioreach_vi_calibration_event(), decisive and success
both stay true, so this block overwrites sp_vi_r0t0_cfg.num_ch with 0 and
ends the calibration run.
[ ... ]
> @@ -1675,9 +1764,9 @@ static void audioreach_arm_vi_calibration(void)
>
> static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> const struct audioreach_module *module,
> - const struct audioreach_module_config *mcfg,
> - u32 mode)
> + const struct audioreach_module_config *mcfg)
> {
> + u32 mode = READ_ONCE(sp_operation_mode);
> u32 num_channels = mcfg->num_channels;
[Severity: Medium]
Is there a TOCTOU race between reading sp_operation_mode here and the
watchdog or SP module configuration?
CPU0 kworker
audioreach_speaker_protection_vi()
mode = READ_ONCE(sp_operation_mode)
(sees CALIBRATION)
audioreach_sp_cal_watchdog_fn()
cmpxchg(CALIBRATION -> NORMAL)
audioreach_arm_vi_calibration()
audioreach_register_events(...)
q6apm_send_cmd_sync(...)
<-- DSP runs in calibration mode
while mode is Normal
A subsequent audioreach_trigger_sp_calibration() can then start while
events from CPU0's run are arriving and prematurely finish the new run.
Separately, audioreach_speaker_protection() and
audioreach_speaker_protection_vi() each read sp_operation_mode
independently across blocking DSP IPCs, so the SP and VI modules in one
graph can be configured in mismatched modes.
[ ... ]
> @@ -1705,8 +1794,11 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
> audioreach_arm_vi_calibration();
>
> rc = audioreach_register_events(graph, module);
> - if (rc)
> + if (rc) {
> + audioreach_sp_finish_calibration();
> + audioreach_sp_disarm_vi();
> return rc;
> + }
> }
[Severity: High]
Does calling audioreach_sp_disarm_vi() here break the build now that this
commit deleted its only definition?
Commit "ASoC: qcom: audioreach: add live speaker temperature (T0)
readback" later removes this error path, so intermediate patches fail to
compile and break git bisect.
[Severity: Medium]
Even once audioreach_sp_disarm_vi() is restored, can calling
audioreach_sp_finish_calibration() before audioreach_sp_disarm_vi()
disarm a concurrently triggered calibration run?
Publishing Normal mode first lets another caller trigger and arm a new
calibration before this error path clears sp_vi_r0.armed; disarming first
avoids that race. Separately, audioreach_sp_cal_watchdog_fn() also needs
to clear sp_vi_r0.armed on timeout so late DSP events cannot pass the
armed check.
[ ... ]
> @@ -1767,6 +1859,73 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph,
>
> kfree(pkt);
>
> + if (rc)
> + return rc;
[Severity: Medium]
If audioreach_alloc_apm_cmd_pkt() or q6apm_send_cmd_sync() fails in
calibration mode, does returning here leave sp_operation_mode in
calibration mode and sp_vi_r0.armed set?
Calibration retries then fail with -EBUSY for up to 60 seconds and normal
playbacks run without R0/T0 protection, while capture callers that keep
the graph open on prepare failure leave sp_vi_r0.armed set.
> +
> + if (mode == PARAM_ID_SP_VI_OP_MODE_NORMAL) {
> + struct apm_module_sp_th_vi_r0t0_cfg *r0t0_cfg;
> + struct sp_vi_r0t0_cfg snap;
> + int r0t0_sz;
> +
> + /* Snapshot the cache so q6apm_send_cmd_sync runs with no locks held */
> + scoped_guard(mutex, &sp_vi_r0t0_cfg_lock)
> + snap = sp_vi_r0t0_cfg;
> +
> + if (!snap.num_ch)
> + return 0;
[Severity: Low]
Because this treats snap.num_ch == 0 as unconfigured, won't a zero-channel
calibration event that overwrites sp_vi_r0t0_cfg.num_ch with 0 cause
Normal-mode playback to silently skip sending PARAM_ID_SP_TH_VI_R0T0_CFG?
Rejecting num_ch == 0 in audioreach_vi_calibration_event() prevents a
truncated or empty DSP event from disabling thermal protection.
> +
> + if (snap.num_ch != num_speakers) {
> + dev_err(graph->dev,
> + "SP R0T0 is for %u speakers, graph has %u\n",
> + snap.num_ch, num_speakers);
> + return -EINVAL;
> + }
[Severity: Medium]
Doesn't this speaker-count check run after the first q6apm_send_cmd_sync()
has already configured OP_MODE, CHANNEL_MAP, and EX_MODE on the DSP?
That contradicts the commit message's claim that a mismatched graph is
refused instead of being partly configured, and capture callers such as
q6apm_lpass_dai_prepare() leave the open graph intact on error.
Snapshotting and validating sp_vi_r0t0_cfg before sending the first
APM_CMD_SET_CFG avoids partial DSP configuration and allows bundling
PARAM_ID_SP_TH_VI_R0T0_CFG instead of taking a second synchronous IPC
round-trip under apm->lock.
[ ... ]
> @@ -1822,14 +1981,14 @@ int audioreach_set_media_format(struct q6apm_graph *graph,
> rc = audioreach_gapless_set_media_format(graph, module, cfg);
> break;
> case MODULE_ID_SPEAKER_PROTECTION:
> - rc = audioreach_speaker_protection(graph, module,
> - READ_ONCE(sp_operation_mode));
> + rc = audioreach_speaker_protection(graph, module);
> if (!rc)
> rc = audioreach_module_enable(graph, module, true);
>
> break;
> case MODULE_ID_SPEAKER_PROTECTION_VI:
> - rc = audioreach_speaker_protection_vi(graph, module, cfg);
> + rc = audioreach_speaker_protection_vi(graph, module, cfg,
> + READ_ONCE(sp_operation_mode));
> if (!rc)
> rc = audioreach_module_enable(graph, module, true);
[Severity: High]
Does passing 4 arguments to audioreach_speaker_protection_vi() break the
build now that its definition above takes only 3 parameters?
Commit "ASoC: qcom: audioreach: add live speaker temperature (T0)
readback" later reverts this call site to 3 arguments, leaving the
intermediate commits unbuildable and breaking git bisect.
> diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
> index 6494eb80f0897..c410e2f6e6a3f 100644
> --- a/sound/soc/qcom/qdsp6/q6apm.c
> +++ b/sound/soc/qcom/qdsp6/q6apm.c
> @@ -950,8 +950,6 @@ static int apm_probe(gpr_device_t *gdev)
>
> static void apm_remove(gpr_device_t *gdev)
> {
> - /* Release the SP calibration watchdog before the module goes away */
> - audioreach_sp_shutdown();
> g_apm = NULL;
> of_platform_depopulate(&gdev->dev);
> snd_soc_unregister_component(&gdev->dev);
[Severity: High]
Can removing audioreach_sp_shutdown() cause a use-after-free when
snd-q6apm is unloaded while the 60-second sp_cal_watchdog is pending?
CPU0 kworker / timer
audioreach_trigger_sp_calibration()
schedule_delayed_work(&sp_cal_watchdog, ...)
apm_remove()
(sp_cal_watchdog not cancelled)
<module snd-q6apm unloaded>
audioreach_sp_cal_watchdog_fn()
<-- executes freed module text
CONFIG_SND_SOC_QDSP6_APM is tristate, so unloading the module within 60
seconds of triggering calibration crashes when the timer fires; deleting
the definition also leaves an orphaned audioreach_sp_shutdown() prototype
in audioreach.h. Restoring audioreach_sp_shutdown() after
of_platform_depopulate() and snd_soc_unregister_component() prevents
userspace controls from re-arming the watchdog after cancellation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=14
next prev parent reply other threads:[~2026-12-04 13:43 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:30 [PATCH v5 00/24] ASoC: qcom: AudioReach Active speaker protection for WSA88xx Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 01/24] ASoC: soc-core: bump MAX_DEFAULT_CH_MAP_SIZE to 18 Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 02/24] ASoC: soc-pcm: add multi_direction_codecs link flag Srinivas Kandagatla
2026-12-04 12:01 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 03/24] ASoC: soc-dai: export snd_soc_dai_stream_valid Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 04/24] ASoC: qcom: sdw: add per-direction stream runtimes for multi_direction links Srinivas Kandagatla
2026-12-04 12:12 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 05/24] ASoC: dt-bindings: qcom,wsa8840: allow one sound DAI cell Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 06/24] ASoC: codecs: wsa884x: add VI sense capture DAI Srinivas Kandagatla
2026-12-04 12:38 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 07/24] ASoC: codecs: wsa883x: " Srinivas Kandagatla
2026-12-04 12:33 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone Srinivas Kandagatla
2026-12-04 13:34 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 09/24] ASoC: qcom: audioreach: add control link support to graphs Srinivas Kandagatla
2026-12-04 13:35 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 10/24] ASoC: qcom: audioreach: run VI module in calibration mode with per-speaker events Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 11/24] ASoC: qcom: q6apm-dai: add S32_LE format support Srinivas Kandagatla
2026-12-04 11:30 ` [PATCH v5 12/24] ASoC: qcom: audioreach: cache VI calibration results per speaker Srinivas Kandagatla
2026-12-04 13:32 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 13/24] ASoC: qcom: audioreach: add speaker protection calibration trigger infrastructure Srinivas Kandagatla
2026-12-04 13:25 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Srinivas Kandagatla
2026-12-04 13:43 ` sashiko-bot [this message]
2026-12-04 11:30 ` [PATCH v5 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Srinivas Kandagatla
2026-12-04 13:50 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls Srinivas Kandagatla
2026-12-04 14:01 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 17/24] ASoC: qcom: audioreach: pin SPEAKER_PROTECTION_VI media format Srinivas Kandagatla
2026-12-04 13:56 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 18/24] ASoC: qcom: audioreach: add live speaker temperature (T0) readback Srinivas Kandagatla
2026-12-04 14:04 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control Srinivas Kandagatla
2026-12-04 13:59 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 20/24] ASoC: qcom: x1e80100: carry WSA VI feedback on the WSA Playback BE link Srinivas Kandagatla
2026-12-04 14:11 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 21/24] ASoC: qcom: x1e80100: register WSA speaker thermal zones for speaker protection Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 22/24] arm64: dts: qcom: glymur-crd: add WSA speaker protection VI feedback Srinivas Kandagatla
2026-12-04 14:18 ` sashiko-bot
2026-12-04 11:30 ` [PATCH v5 23/24] arm64: dts: qcom: mahua-t14s: " Srinivas Kandagatla
2026-12-04 14:16 ` sashiko-bot
2026-12-04 11:31 ` [PATCH v5 24/24] arm64: dts: qcom: x1e78100-t14s: " Srinivas Kandagatla
2026-12-04 14:24 ` 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-249890@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=srinivas.kandagatla@oss.qualcomm.com \
/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.