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=1796392893; b=alVA7eeYEtcl5L5xY/kVKKirfkYvfJOKmWNTf+XUv5yKxWuA3TtIBi+pgJVT1s2MgNe4 xT0GhaprCfph6e4MbBad1MoxgbIXLe0zl+3gX2jXyU6tG1lk/tNCANyAetVmhKDiRk++y UEqDE508A7r9dmR0OzpuIeXAUQVB8IV+9ThyY84Du2hmz5G3AVQ41P/lrU7H3FPTbP/hJ L41E1zdonFcKF109wjPr0Kw7b2bbBvzwc2j4XNkfHFfd2w3nj17+XkqeUtD0FulwekkpS +mex+N3+tFJiHHaYpfYVZimMwBUtIQZj049b1pbqhrHiDFbfnX/xKH+jQ+rNPuwKzoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796392893; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=j/fdwY370pkhvgM7+be7nICLBA48+uY61SOZdOIrwzo=; b=Etkd29T9R8uxdZcelwPkB7jbzLKpDkSXVuv9vXRLbEeRcQVol31QJGlMsveLZRa2Kc1W LJrF8x2bD39g7mAtOvM9ZwV6n+bP4bsocAE0cyd7XlG+Ku/FTV0/tXZ/TOSu1WovNewGG HbsHakZwqWj8r9zWAD2amy5FFrQ4typotN/9GbGIdEXLX2VSgIQTQ1X5nPQyOEsO5ZKi8 xjqYwPtZfJCX20rM0cekApHkU/YLtlV4XSVO32tj4Tel0378az66REsOGCMYrWRzYkUtL 7MI+rjq0ptyzRX5pu2en5kjE5CdnjZD94yBJW6MY+hwM3p1qURujGZksIpJuULimHmg== 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=V6GHIZCb; 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 3C065606A322; Fri, 4 Dec 2026 14:01:33 +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=V6GHIZCb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85B401F0092C; Fri, 4 Dec 2026 14:01:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796392892; bh=j/fdwY370pkhvgM7+be7nICLBA48+uY61SOZdOIrwzo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=V6GHIZCbEOklc3+lIjZ6KzEakyP5YDK75UKVwS32UZk+Ea/wbi85tsHTCUcKwhouJ ciwJf+Z2szjs6psTcrhfllBhvHWNARy7I+aGYx+SXaA9j5cNpN+HG3culdOI6hW4PB wAotMEaqinPeV/S+iYoM5+VxB2URZNR8/+/3SdK8DB09c2ht4MmiWKwbH6+N2JB39G 1otgYmniek9WYrkScwYPyiWy5FDu6/iLZouFk6t4nQHgD8Evg9k/Nsrx5FyCce33R5 Wn3a4Fh3Uz+yQj/cGYBx/mEcAboAUDK4PN+7w0mD5iY08EVb35h4ZBiUaE3/w8Sr31 6Cn344keBvlfA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 16/24] ASoC: qcom: audioreach: add speaker protection mixer controls 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-17-srinivas.kandagatla@oss.qualcomm.com> References: <20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com> <20261204113101.1141644-17-srinivas.kandagatla@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:01:32 +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 6 potential issues to consider: - [High] ASoC: qcom: audioreach: missing sp_cal_watchdog cancel in apm_remove() - [Medium] ASoC: qcom: audioreach: watchdog race in audioreach_sp_finish_calibration() - [Medium] ASoC: qcom: missing RO/volatile flags in audioreach_control_load() - [Medium] ASoC: qcom: unchecked hdr->type cast in audioreach_control_load() - [Medium] ASoC: qcom: unratelimited log flood via audioreach_put_sp_r0t0() - [Medium] ASoC: qcom: sp_op_mode enum count mismatch in audioreach_get_sp_op_mode() -- commit a161a89d518c1d4827e5dbf7333beb85038a9af6 Author: Ravi Hothi ASoC: qcom: audioreach: add speaker protection mixer controls This commit adds topology kcontrol IDs and handlers for the speaker protection operation mode and per-speaker R0/T0 calibration values in audioreach. > diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topol= ogy.c > index 5dd7f2c51d5cf..f9a3e9cf4119e 100644 > --- a/sound/soc/qcom/qdsp6/topology.c > +++ b/sound/soc/qcom/qdsp6/topology.c > @@ -1465,6 +1465,68 @@ static int audioreach_put_vol_ctrl_audio_mixer(str= uct snd_kcontrol *kcontrol, > return 1; > } > =20 > +static int audioreach_get_sp_op_mode(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + ucontrol->value.enumerated.item[0] =3D audioreach_get_sp_operation_mode= (); > + > + return 0; > +} [Severity: Medium] Can snd_soc_info_enum_double() advertise a 2-channel enum while audioreach_get_sp_op_mode() only populates item[0]? In soc_tplg_control_denum_create(), se->shift_l and se->shift_r come from tplg_chan_get_shift() for SNDRV_CHMAP_FL and SNDRV_CHMAP_FR. When a topolo= gy defines only SNDRV_CHMAP_FL, se->shift_r is assigned (unsigned char)-EINVAL, so se->shift_l !=3D se->shift_r and snd_soc_info_enum_double() reports uinfo->count =3D 2. Because item[1] is left untouched from the caller buff= er, reads echo stale caller data or fail with -EINVAL under CONFIG_SND_CTL_DEBUG in sanity_check_elem_value(). Normalizing se->shift_r =3D se->shift_l in audioreach_control_load() (or us= ing a single-channel enum info callback) avoids the mismatch. [Severity: High] Does unloading snd-q6apm while sp_cal_watchdog is pending cause a use-after-free? audioreach_trigger_sp_calibration() schedules the module-static sp_cal_watchdog delayed work for 60 seconds, but commit "ASoC: qcom: audioreach: send cached R0/T0 to the VI module in normal mode" removed audioreach_sp_shutdown() and its call from apm_remove() in sound/soc/qcom/qdsp6/q6apm.c. If snd-q6apm is unloaded within 60 seconds of triggering calibration, sp_cal_watchdog fires against freed module text and data. Calling cancel_delayed_work_sync(&sp_cal_watchdog) from apm_remove() avoids leaving the timer active across unbind and module unload. [Severity: Medium] Can audioreach_sp_finish_calibration() cancel a newly started calibration's watchdog or race with a running watchdog callback? In sound/soc/qcom/qdsp6/audioreach.c, audioreach_sp_finish_calibration() resets sp_operation_mode to Normal before calling non-synchronous cancel_delayed_work(&sp_cal_watchdog): CPU0 CPU1 audioreach_sp_finish_calibration() WRITE_ONCE(sp_operation_mode, NORMAL) audioreach_trigger_sp_calibration() cmpxchg(NORMAL -> CALIBRATION) schedule_delayed_work( &sp_cal_watchdog, ...) cancel_delayed_work( &sp_cal_watchdog) <-- cancels CPU1's watchdog That leaves CPU1's calibration running with no timeout guard. In addition, because cancel_delayed_work() does not wait for an in-flight audioreach_sp_cal_watchdog_fn(), an older watchdog callback can run its cmpxchg(CALIBRATION -> NORMAL) and prematurely abort a newly triggered calibration. > +/* > + * "Speaker Protection Operation Mode" is read-only status. Enter > + * Calibration via the "Speaker Protection Calibrate" trigger instead, > + * so a stale alsactl state file cannot flip the DSP into Calibration > + * and nothing can leave the system stuck there. > + */ > +static int audioreach_put_sp_op_mode(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + return -EACCES; > +} [Severity: Medium] Should audioreach_control_load() enforce read-only access on SND_SOC_AR_TPLG_SP_OP_MODE_CTL instead of returning -EACCES from put? When a topology omits hdr.access (0), snd_ctl_new1() defaults it to SNDRV_CTL_ELEM_ACCESS_READWRITE, so alsactl saves and tries to restore the control and fails with -EACCES (and ALSA read-only controls are expected to reject writes with -EPERM in snd_ctl_elem_write()). Stripping SNDRV_CTL_ELEM_ACCESS_WRITE, setting SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, and clearing kc->put =3D NULL in audioreach_control_load() gives standard read-only semantics. Because both sp_operation_mode and sp_vi_r0t0_cfg change asynchronously from DSP events and timers without snd_ctl_notify(), SND_SOC_AR_TPLG_SP_R0T0_CTL should also set SNDRV_CTL_ELEM_ACCESS_VOLATILE. [ ... ] > +static int audioreach_put_sp_r0t0(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + struct snd_soc_component *scomp =3D snd_kcontrol_chip(kcontrol); > + long cur[AR_SP_R0T0_CTL_COUNT]; > + int ret; > + > + audioreach_get_sp_vi_r0t0(cur, AR_SP_R0T0_CTL_COUNT); > + if (!memcmp(cur, ucontrol->value.integer.value, sizeof(cur))) > + return 0; > + > + ret =3D audioreach_set_sp_vi_r0t0(scomp->dev, ucontrol->value.integer.v= alue, > + AR_SP_R0T0_CTL_COUNT); > + if (ret < 0) > + return ret; > + > + return 1; > +} [Severity: Medium] Can userspace flood the kernel log through audioreach_put_sp_r0t0()? audioreach_set_sp_vi_r0t0() emits unratelimited dev_err() messages on inval= id values and up to MAX_SP_VI_SPEAKERS unratelimited dev_info() lines on each valid change, so any user with access to /dev/snd/controlC* can flood dmesg at ioctl speed by repeating out-of-range writes or alternating two valid R0/T0 sets. Using dev_err_ratelimited() and dev_dbg() in audioreach_set_sp_vi_r0t0() avoids unbounded kernel logging. [ ... ] > @@ -1524,6 +1587,14 @@ static int audioreach_control_load(struct snd_soc_= component *scomp, int index, > sm =3D (struct soc_mixer_control *)kc->private_value; > dobj =3D &sm->dobj; > break; > + case SND_SOC_AR_TPLG_SP_R0T0_CTL: > + sm =3D (struct soc_mixer_control *)kc->private_value; > + dobj =3D &sm->dobj; > + break; > + case SND_SOC_AR_TPLG_SP_OP_MODE_CTL: > + se =3D (struct soc_enum *)kc->private_value; > + dobj =3D &se->dobj; > + break; > default: > dev_warn(scomp->dev, "control type not supported %d:%d:%d\n", > hdr->ops.get, hdr->ops.put, hdr->ops.info); > @@ -1550,6 +1621,10 @@ static const struct snd_soc_tplg_kcontrol_ops audi= oreach_io_ops[] =3D { > audioreach_put_audio_mixer, snd_soc_info_volsw}, > {SND_SOC_AR_TPLG_VOL_CTL, audioreach_get_vol_ctrl_audio_mixer, > audioreach_put_vol_ctrl_audio_mixer, snd_soc_info_volsw}, > + {SND_SOC_AR_TPLG_SP_OP_MODE_CTL, audioreach_get_sp_op_mode, > + audioreach_put_sp_op_mode, snd_soc_info_enum_double}, > + {SND_SOC_AR_TPLG_SP_R0T0_CTL, audioreach_get_sp_r0t0, > + audioreach_put_sp_r0t0, audioreach_info_sp_r0t0}, > }; [Severity: Medium] Can a mismatched hdr->type cause type confusion and an out-of-bounds write = in audioreach_control_load()? soc_tplg_kcontrol_elems_load() allocates kc->private_value according to control_hdr->type, whereas audioreach_control_load() casts kc->private_value to struct soc_mixer_control or struct soc_enum based only on hdr->ops.get. If a topology pairs SND_SOC_AR_TPLG_SP_R0T0_CTL or SND_SOC_AR_TPLG_SP_OP_MODE_CTL with SND_SOC_TPLG_TYPE_BYTES, writing dobj->private =3D scontrol writes 8 bytes past the end of the smaller struct soc_bytes_ext allocation and leaks scontrol on unload. In addition, pairing SND_SOC_AR_TPLG_SP_OP_MODE_CTL with SND_SOC_TPLG_TYPE_MIXER lets soc_tplg_kcontrol_bind_io() bind snd_soc_info_enum_double() onto a struct soc_mixer_control (dereferencing mixer fields as e->texts), while legitimate SND_SOC_TPLG_TYPE_ENUM controls cannot use vendor ops.info ID 258 because soc_tplg_control_denum_create() rejects non-standard enum info IDs first. Checking le32_to_cpu(hdr->type) against SND_SOC_TPLG_TYPE_MIXER or SND_SOC_TPLG_TYPE_ENUM before casting prevents this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204113101.1141= 644-1-srinivas.kandagatla@oss.qualcomm.com?part=3D16