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=1796391793; b=lYmAt7g3bl4ih2McfWSDzP9Qrpuq6aQVluhNuEGcVi9PfLBK+5NPRD4L22hf9waLKqU+ vhDtUKWbR07ABc3Ah1+vglGvtx59/yZJHwQczn+wTTugYA6RwKKBBWhnMZqblsUeqa5OJ 9SvCWWpLQV+L6Yqv4o+fznwyafaX1O8lNQubK7zRxsBaYn9F52mNxNHPsd8JWEIc8XtJG KtROERbf6SFemaaWRAZudtLXD+vgmHluignthIK5O9FuKO5TyC6Vg02I1MuHAb0ggkUN/ 3d1ACb9TJ+nw8A+JFeG+rlfML2PClhzstgtXjSM8bDq1CyRaipvJ51zhq7HGqmqanZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391793; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Ur0BL+wuWgPt0iXo9aVvUuUuvxccb3bsHzc8QeX5Mkc=; b=V4XAHXyG/YJQ0qTDkio/fcc2D/71rtTOCE6g0LVE0kBNAGnJQSyW515ijNIW55gWkkS7 fp+1+bz8Y6jSQTqp61MhpIwklm6ur/NZINvY91arQNBKjiBkMRXDQu5I7dPZbC1IjT7k/ xJYYowkhsIU1ydINq1wJEDzGnDM9Dm3ogbEusYuntzsvP+muCEaPZqbxmgaKjvZdBXAPl 7f/PWfVcLrceJ5Dki/qahGFkxVBIgjelIxkJCYiobYa6usHJu2/wLQAL7hxcl6f/7nE9s idGY+vfwTow9VSTqBcMZo7ThUaI6dJdUvjVYmpAmZxi+rT1Qp1LZctHz/F0TYLVMTHA== 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=JGO6MWNM; 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 B86EC606A32D; Fri, 4 Dec 2026 13:43:13 +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=JGO6MWNM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08D341F0092C; Fri, 4 Dec 2026 13:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796391793; bh=Ur0BL+wuWgPt0iXo9aVvUuUuvxccb3bsHzc8QeX5Mkc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JGO6MWNMcb9B9Du/0A6s6FwxkaPCj9B+XZYGOLcdaXXM8hnQa6oL2iIlrCXOZ0CrK ro/81W6IeOKIpe0QzND0Q2ha+jtqpeGi/ZtBR1wbKhUQdaR85Wl+5y2EGy/G7qNApF 6nZiSqKUGMtGxpxpPpDp+uuyofe/muv9fPwbp/GLkbouKXdOJP0BQ9iv8cO4qSfQeT lot+n3LWLDQ26iC56xtW1CWTy/BY8T4DsGcx9IpHkwXArsogNZp+s1Vmg5r7k0LtYF ZiJQ6KUcQ/JJoM2B1/kQ0Jxls04cRPf+0WyoPadS97tf6HUUmm3Q0ndhF5o7J7ZxBr /foRwWDA7uuLg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 14/24] ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode Reply-To: sashiko-reviews@lists.linux.dev To: "Srinivas Kandagatla" Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204113101.1141644-15-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-15-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 13:43:12 +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 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 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/aud= ioreach.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); > =20 > -static void audioreach_sp_disarm_vi(void) > -{ > - guard(mutex)(&sp_vi_r0_lock); > - sp_vi_r0.armed =3D 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) !=3D > + PARAM_ID_SP_VI_OP_MODE_NORMAL) =3D=3D > 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. > =20 > -/* Finish before writing the mode so a trigger racing in cannot be clobb= ered */ > 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 *fra= c) > return val >> 24; > } [ ... ] > + for (i =3D 0; i < num_ch; i++) { > + long r0 =3D vals[2 * i]; > + long t0 =3D vals[2 * i + 1]; > + int r0_int, r0_frac; > + > + if (r0 < SP_VI_R0_MIN_Q24 || r0 > SP_VI_R0_MAX_Q24) { > + r0_int =3D 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] =3D r0; > + new.t0_cali_q6[i] =3D 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]); > } > =20 > + /* 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 =3D num_ch; > + for (i =3D 0; i < num_ch; i++) > + sp_vi_r0t0_cfg.r0_cali_q24[i] =3D cali->cali_param[i].r0_cali_q24; > + } > + > dev_info(dev, "VI calibration complete: %s\n", success ? "success" : "f= ailed"); [Severity: Medium] Can a zero-channel calibration event wipe a previously stored R0/T0 set here? q6apm_vi_calibration_event() forwards num_ch =3D 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) > =20 > 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 =3D READ_ONCE(sp_operation_mode); > u32 num_channels =3D 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 =3D 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(); > =20 > rc =3D 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, > =20 > kfree(pkt); > =20 > + 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 =3D=3D 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 =3D sp_vi_r0t0_cfg; > + > + if (!snap.num_ch) > + return 0; [Severity: Low] Because this treats snap.num_ch =3D=3D 0 as unconfigured, won't a zero-chan= nel 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 =3D=3D 0 in audioreach_vi_calibration_event() prevents a truncated or empty DSP event from disabling thermal protection. > + > + if (snap.num_ch !=3D 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_grap= h *graph, > rc =3D audioreach_gapless_set_media_format(graph, module, cfg); > break; > case MODULE_ID_SPEAKER_PROTECTION: > - rc =3D audioreach_speaker_protection(graph, module, > - READ_ONCE(sp_operation_mode)); > + rc =3D audioreach_speaker_protection(graph, module); > if (!rc) > rc =3D audioreach_module_enable(graph, module, true); > =20 > break; > case MODULE_ID_SPEAKER_PROTECTION_VI: > - rc =3D audioreach_speaker_protection_vi(graph, module, cfg); > + rc =3D audioreach_speaker_protection_vi(graph, module, cfg, > + READ_ONCE(sp_operation_mode)); > if (!rc) > rc =3D 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) > =20 > static void apm_remove(gpr_device_t *gdev) > { > - /* Release the SP calibration watchdog before the module goes away */ > - audioreach_sp_shutdown(); > g_apm =3D 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) 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D14