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=1796075248; b=NvhRyZhvOvZT6CpXuG1jPt6VLQtkrutqekFtWXpkykZlDJgB3Mh/aiz+m6xVRxRgo2rL zgYPlXT40DfLAlYQqduZNEluaxAFguANLkd7dws6ui4UY5OW/NVhQoK6CJjIZNcGuJVTJ RwMYmwqUJkT0PYxgXvU52ASMk8LLOM2oUUD6HAuo1ABwL4Gad3os6NBMLZIoelSu1DfqR frjFQIs/nqhZjeiECjwItESx2Om7J12KhvDyMlyMFwvCXRaDbTkcwaItDATCaL0m/BYhe lKmD6P3M2o9JiNFyNzQxN3SA3wXb13aH6KtD5g4YLZIabGvlR422zuzWtUGwcalgAsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075248; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=+zlsNTbtRp+FHOdRxmCycA7w6TAXzAswqWY6Uol6Ptk=; b=257o29SsqbaTk09AuziadESuAqNTkWQ7VSSUqpCcvRamukwpMbUZP3YODlYGZGsygA7O Lhcoa+kNATfNq656P1Yf7VfG9qFEcduUoC845lWbKQxOzY7C3OrLNSwHzYbQz+ElyDHJl flig1Y4QKZPBsLRINZS3A7r4P3WgOtYQwvrRSBbp9+aEa8wLfnRb/px3EFy5wtzJNudNE lhBRfC/mUKgKzMZ3l6L43XeAX0eslQI4ggG1zBADYfd9fdmtLeKhqr1UVap8C6NqzUahB EQRNEOfnJ/g7ixnhUIICIyoMGRI+/+EqI9lX+JiafDU2qRABkJoPYKJEBtqi8+iWymA== 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="Rj4n/sy8"; 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 DA7A2606A320; Mon, 30 Nov 2026 21:47:28 +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=Rj4n/sy8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D61FB1F00896; Mon, 30 Nov 2026 21:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796075248; bh=+zlsNTbtRp+FHOdRxmCycA7w6TAXzAswqWY6Uol6Ptk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Rj4n/sy8gL/i0xdAKu1hynyzFWbK3WZj3A/j9eZrNSI+TkbVAG0j44rhK2tJFpUPo U01PjAxQ62STstTW/MP/tAIomGfuVuMz2hPyX234plDQKTOUXirWh9aOOmYwxBGDbL NfhIlt92MhHRQwREXWkbkIUDZQVTt+3yVegY88kWinyjbOsfIWK2V2SlW/DP2ryNmH vVa6tOtxEOSLLrvCV8BGpi/kgbqe6zRSM5G0RwuPhRFSqN6KJGrI4H0YSKQ0iTJeVP ukHxZkCyFIZNuh784gIk7a7V4MkB5HXqxXZPSxvawK4oO6OsHGZBQljaAjJ81nzXpz iqo6OoaXIQvdg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 19/24] ASoC: qcom: audioreach: add speaker protection calibration state control 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: <20261130212258.7376-20-srinivas.kandagatla@oss.qualcomm.com> References: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> <20261130212258.7376-20-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 21:47:27 +0000 X-Mailing-List: devicetree@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 5 potential issues to consider: - [Medium] ASoC: qcom: audioreach: early return in audioreach_vi_calibration_abort() - [Medium] ASoC: qcom: audioreach: unsynchronized sp_operation_mode reads across sleep - [Medium] ASoC: qcom: audioreach: uncancelled sp_cal_watchdog work on module removal - [Low] ASoC: qcom: mode reset before cancel in audioreach_sp_finish_calibration() - [Low] ASoC: qcom: audioreach: commit message omits calibrate control and abort logic -- commit c58591aa133913ac270206bd175386cd596ee808 Author: Srinivas Kandagatla > ASoC: qcom: audioreach: add speaker protection calibration state control > > Add a read-only "Speaker Protection Calibration State" control with > each speaker's last calibration state, so userspace can follow a run. > > Signed-off-by: Srinivas Kandagatla [Severity: Low] This isn't a bug, but the commit message only mentions the read-only "Speaker Protection Calibration State" control while the patch also adds the "Speaker Protection Calibrate" trigger control and VI calibration abort handling on graph stop and close. > diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/aud= ioreach.c > index 789f9fc3c9795..0a6c881f5cd46 100644 > --- a/sound/soc/qcom/qdsp6/audioreach.c > +++ b/sound/soc/qcom/qdsp6/audioreach.c [ ... ] > @@ -1806,6 +1826,46 @@ void audioreach_vi_calibration_event(struct device= *dev, > audioreach_sp_finish_calibration(); > } > =20 > +/* A run cut short never reports a final state, close it out */ > +void audioreach_vi_calibration_abort(struct device *dev) > +{ > + unsigned int i; > + > + guard(mutex)(&sp_vi_r0_lock); > + > + if (!sp_vi_r0.armed) > + return; > + > + sp_vi_r0.armed =3D false; > + > + /* The DSP never reported on this run: keep the previous result */ > + if (!memchr_inv(sp_vi_r0.seen_states, 0, sizeof(sp_vi_r0.seen_states))) > + return; [Severity: Medium] Does returning here before calling audioreach_sp_finish_calibration() leave sp_operation_mode stuck in PARAM_ID_SP_VI_OP_MODE_CALIBRATION when a graph is closed or stopped before the first DSP event arrives? When q6apm_graph_close() aborts an armed graph that was never started (or q6apm_graph_stop() runs before any EVENT_ID_VI_PER_SPKR_CALIBRATION event is received), sp_vi_r0.seen_states is still all zeros. Returning after clearing sp_vi_r0.armed skips audioreach_sp_finish_calibration(), so sp_operation_mode remains in calibration mode until the 60-second sp_cal_watchdog expires: retries of "Speaker Protection Calibrate" fail with -EBUSY, and any normal playback started in the meantime configures the DSP in calibration mode without sending PARAM_ID_SP_TH_VI_R0T0_CFG. Calling audioreach_sp_finish_calibration() before returning when seen_states is all zeros avoids leaving calibration mode active. > + > + sp_vi_r0.state =3D SP_VI_CALI_ABORTED; > + > + for (i =3D 0; i < MAX_SP_VI_SPEAKERS; i++) { > + u32 state =3D sp_vi_r0.last_state[i]; > + > + /* Slot never reported: not part of this run */ > + if (!sp_vi_r0.seen_states[i]) > + continue; > + > + if (sp_vi_cali_state_is_terminal(state)) > + continue; > + > + dev_info(dev, "VI calibration channel %u: aborted while %s\n", > + i, sp_vi_cali_state_name(state)); > + sp_vi_r0.last_state[i] =3D VI_CALIBRATION_STATE_INACTIVE; > + } > + > + dev_info(dev, "VI calibration aborted: graph stopped before the DSP fin= ished\n"); > + > + /* Edge-triggered: the mode auto-returns to Normal on abort too. */ > + audioreach_sp_finish_calibration(); > +} [Severity: Low] Can audioreach_sp_finish_calibration() cancel the watchdog of a newly triggered calibration run if userspace writes to "Speaker Protection Calibrate" concurrently? sound/soc/qcom/qdsp6/audioreach.c:audioreach_sp_finish_calibration() { WRITE_ONCE(sp_operation_mode, PARAM_ID_SP_VI_OP_MODE_NORMAL); cancel_delayed_work(&sp_cal_watchdog); } Because sp_operation_mode is reset to NORMAL before cancel_delayed_work() runs, a concurrent audioreach_put_sp_calibrate() call can pass the cmpxchg() in audioreach_trigger_sp_calibration() and schedule sp_cal_watchdog, only for the finishing context to cancel it: CPU0 CPU1 audioreach_sp_finish_calibration() WRITE_ONCE(sp_operation_mode, ..._NORMAL) audioreach_put_sp_calibrate() audioreach_trigger_sp_calibration() cmpxchg(&sp_operation_mode, ...) schedule_delayed_work( &sp_cal_watchdog, ...) cancel_delayed_work(&sp_cal_watchdog) <-- cancels new run's watchdog Also, because cancel_delayed_work() does not wait for an in-flight audioreach_sp_cal_watchdog_fn() callback, an expiring watchdog from the previous run can execute its cmpxchg() right after CPU1 re-arms sp_operation_mode and reset the new run back to NORMAL. > diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topol= ogy.c > index 0e28c68c735d2..a19efbb889a8e 100644 > --- a/sound/soc/qcom/qdsp6/topology.c > +++ b/sound/soc/qcom/qdsp6/topology.c [ ... ] > @@ -1548,6 +1548,45 @@ static int audioreach_get_sp_t0(struct snd_kcontro= l *kcontrol, [ ... ] > +static int audioreach_put_sp_calibrate(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + if (!ucontrol->value.integer.value[0]) > + return 0; > + > + return audioreach_trigger_sp_calibration() ? : 1; > +} [Severity: Medium] Can toggling sp_operation_mode from userspace while q6apm_graph_media_format_pcm() is sleeping in synchronous GPR commands configure the speaker protection modules inconsistently? In audioreach_speaker_protection_vi(), sp_operation_mode is snapshotted into mode at function entry, but re-read from the global variable after q6apm_send_cmd_sync() sleeps: sound/soc/qcom/qdsp6/audioreach.c:audioreach_speaker_protection_vi() { u32 mode =3D READ_ONCE(sp_operation_mode); ... op_cfg->cfg.operation_mode =3D mode; ... rc =3D q6apm_send_cmd_sync(graph->apm, pkt, 0); ... if (sp_operation_mode =3D=3D PARAM_ID_SP_VI_OP_MODE_NORMAL) { ... } If audioreach_put_sp_calibrate() flips sp_operation_mode from NORMAL to CALIBRATION while q6apm_send_cmd_sync() is waiting, the DSP receives NORMAL in PARAM_ID_SP_VI_OP_MODE_CFG (without calibration events registered), while the post-sleep check sees CALIBRATION and skips sending PARAM_ID_SP_TH_VI_R0T0_CFG. Similarly, because q6apm_graph_media_format_pcm() calls audioreach_speaker_protection() and audioreach_speaker_protection_vi() across sleeping GPR commands without a shared mode snapshot, MODULE_ID_SPEAKER_PROTECTION and MODULE_ID_SPEAKER_PROTECTION_VI can be configured in different modes for the same graph. > @@ -1557,6 +1596,30 @@ static const struct snd_kcontrol_new audioreach_sp= _telemetry_controls[] =3D { [ ... ] > + { > + /* > + * Write-only edge trigger. Writing 1 arms a calibration run > + * for the next (or current) WSA playback graph; the mode > + * returns to Normal on its own once the DSP reports terminal > + * state, on graph abort, or on the watchdog timeout. > + */ > + .iface =3D SNDRV_CTL_ELEM_IFACE_MIXER, > + .name =3D "Speaker Protection Calibrate", > + .access =3D SNDRV_CTL_ELEM_ACCESS_READWRITE | > + SNDRV_CTL_ELEM_ACCESS_VOLATILE, > + .info =3D audioreach_info_sp_calibrate, > + .get =3D audioreach_get_sp_calibrate, > + .put =3D audioreach_put_sp_calibrate, > + }, > }; [Severity: Medium] Can unloading snd-q6apm after arming "Speaker Protection Calibrate" cause a use-after-free when sp_cal_watchdog fires? Writing 1 to this control schedules the static 60-second sp_cal_watchdog delayed work in audioreach_trigger_sp_calibration(), but neither apm_remove() nor module teardown calls cancel_delayed_work_sync(&sp_cal_watchdog). If snd-q6apm is unloaded while the watchdog timer is still pending or its work callback is in flight, audioreach_sp_cal_watchdog_fn() will execute after the module text and data have been unmapped. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130212258.7376= -1-srinivas.kandagatla@oss.qualcomm.com?part=3D19