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 08/24] ASoC: codecs: wsa884x: register the die temperature as a thermal zone
Date: Fri, 04 Dec 2026 13:34:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-249878@kernel.org> (raw)
In-Reply-To: <20261204113101.1141644-9-srinivas.kandagatla@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ASoC: codecs: wsa884x: data race and TOCTOU on hw_init in
wsa884x_get_temp()
- [Medium] ASoC: wsa884x: enabling tripless thermal zone wakes idle
codecs on resume
- [Low] ASoC: codecs: wsa884x: unrelated wsa884x_vi_hw_params() change
in commit
- [Low] ASoC: codecs: wsa884x: 0 degC cache sentinel collision in
wsa884x_get_temp()
--
commit 513c87fe3e3a0f98ef09430a4d09e5f54d857839
Author: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
ASoC: codecs: wsa884x: register the die temperature as a thermal zone
This commit registers a tripless thermal zone for the WSA884x amplifier
die temperature so in-kernel speaker protection can look it up by name,
and updates wsa884x_get_temp() to return -EAGAIN before initialization or
when the PA is on without a cached reading.
> diff --git a/sound/soc/codecs/wsa884x.c b/sound/soc/codecs/wsa884x.c
> index abf9d88ec7a8a..e5813ed139b34 100644
> --- a/sound/soc/codecs/wsa884x.c
> +++ b/sound/soc/codecs/wsa884x.c
[ ... ]
> @@ -1779,21 +1780,19 @@ static int wsa884x_vi_hw_params(struct snd_pcm_substream *substream,
> struct snd_soc_dai *dai)
> {
> struct wsa884x_priv *wsa884x = dev_get_drvdata(dai->dev);
> - unsigned int num_ports = 0;
>
> + if (!wsa884x->port_enable[WSA884X_PORT_VISENSE])
> + return 0;
> +
> + wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
> wsa884x->vi_sconfig.frame_rate = params_rate(params);
> wsa884x->vi_sconfig.ch_count = 2;
> wsa884x->vi_sconfig.bps = 1;
> wsa884x->vi_sconfig.type = SDW_STREAM_PDM;
> wsa884x->vi_sconfig.direction = SDW_DATA_DIR_TX;
>
> - if (wsa884x->port_enable[WSA884X_PORT_VISENSE]) {
> - wsa884x->vi_port_config = wsa884x_pconfig[WSA884X_PORT_VISENSE];
> - num_ports = 1;
> - }
> -
> return sdw_stream_add_slave(wsa884x->slave, &wsa884x->vi_sconfig,
> - &wsa884x->vi_port_config, num_ports,
> + &wsa884x->vi_port_config, 1,
> wsa884x->vi_sruntime);
> }
[Severity: Low]
This change to wsa884x_vi_hw_params() is unrelated to thermal zone
registration and is not mentioned in the commit message. Should it be
folded into commit "ASoC: codecs: wsa884x: add VI sense capture DAI" or
split into its own patch?
[ ... ]
> @@ -1934,11 +1933,17 @@ static int wsa884x_get_temp(struct wsa884x_priv *wsa884x, long *temp)
>
> guard(mutex)(&wsa884x->sp_lock);
>
> + /* OTP trims read back as zero until the codec is initialised. */
> + if (!wsa884x->hw_init)
> + return -EAGAIN;
[Severity: Medium]
Can wsa884x->hw_init race with SoundWire status updates here?
wsa884x_get_temp() reads hw_init under wsa884x->sp_lock, while
wsa884x_init() sets it and wsa884x_update_status() clears it under
slave->sdw_dev_lock:
CPU0 (temp read) CPU1 (SoundWire status)
wsa884x_get_temp()
mutex_lock(&wsa884x->sp_lock)
if (!wsa884x->hw_init)
sdw_update_slave_status()
mutex_lock(&slave->sdw_dev_lock)
wsa884x_update_status(...)
wsa884x->hw_init = false
regcache_cache_only(..., true)
mutex_unlock(&slave->sdw_dev_lock)
pm_runtime_resume_and_get()
regcache_sync() <-- runs on unattached slave
regmap_read(WSA884X_OTP_REG_*) <-- d1 == d2 == 0, returns -EINVAL
Returning -EINVAL from a thermal zone read also feeds into
thermal_zone_recheck(), which polls the zone with backoff until disabling
it. On an attach transition, the plain read also lacks acquire/release
ordering against wsa884x_init(). Note that taking sp_lock inside
wsa884x_update_status() would risk an ABBA deadlock with
pm_runtime_resume_and_get() -> swrm_runtime_resume() ->
sdw_handle_slave_status() -> sdw_update_slave_status().
> if (wsa884x->pa_on) {
> /*
> * Reading temperature is possible only when Power Amplifier is
> - * off. Report last cached data.
> + * off. Report last cached data if we have one, -EAGAIN otherwise.
> */
> + if (!wsa884x->temperature)
> + return -EAGAIN;
> *temp = wsa884x->temperature * 1000;
> return 0;
> }
[Severity: Low]
Does using zero as the uncached sentinel reject a valid cached reading of
0 degC?
wsa884x_get_temp() caches values across WSA884X_LOW_TEMP_THRESHOLD (-10)
to WSA884X_HIGH_TEMP_THRESHOLD (150), so a cached 0 degC reading fails
with -EAGAIN in hwmon and -ENODATA via thermal_zone_get_temp() while pa_on
is true. Because wsa884x->temperature is an unsigned int, cached negative
temperatures in [-10, -1] also wrap when multiplied by 1000 before
widening to long on 64-bit hwmon reads. Making temperature a signed int
with a separate bool validity flag (or initializing it to an out-of-range
sentinel such as THERMAL_TEMP_INVALID) avoids both issues.
[ ... ]
> @@ -2196,6 +2233,35 @@ static int wsa884x_probe(struct sdw_slave *pdev,
> if (ret)
> return ret;
>
> + if (IS_REACHABLE(CONFIG_THERMAL)) {
> + char tz_name[THERMAL_NAME_LENGTH];
> + struct thermal_zone_device *tz;
> +
> + /*
> + * Register after runtime PM is enabled, as the zone is read
> + * right away. dev_name() is too long for a zone name.
> + */
> + scnprintf(tz_name, sizeof(tz_name), "wsa-%d-%u",
> + pdev->bus->id, pdev->id.unique_id);
> + tz = thermal_tripless_zone_device_register(tz_name,
> + wsa884x,
> + &wsa884x_tz_ops,
> + &wsa884x_tzp);
> + if (IS_ERR(tz)) {
> + dev_warn(dev,
> + "thermal zone '%s' registration failed (%ld); SP T0 kcontrol will read 0 for this codec\n",
> + tz_name, PTR_ERR(tz));
> + } else {
> + ret = devm_add_action_or_reset(dev,
> + wsa884x_tz_unregister,
> + tz);
> + if (ret)
> + return ret;
> +
> + thermal_zone_device_enable(tz);
[Severity: Medium]
Does calling thermal_zone_device_enable(tz) wake every idle WSA884x
amplifier and its parent Qualcomm SoundWire controller on every system
resume?
Because wsa884x and qcom_swrm only implement runtime PM, an idle amplifier
stays runtime-suspended across system suspend/resume with hw_init true and
pa_on false. On every system resume, dpm_complete() ->
thermal_pm_complete() -> thermal_zone_device_resume() ->
__thermal_zone_device_update() invokes wsa884x_tz_get_temp() whenever
tz->mode is THERMAL_DEVICE_ENABLED, calling pm_runtime_resume_and_get()
only to discard the reading for a tripless zone.
If that resume read returns any error other than -EAGAIN (such as -EINVAL
or a runtime resume failure), __thermal_zone_device_update() also calls
thermal_zone_recheck(), repeatedly waking and polling the codec with
exponential backoff up to 120 seconds before disabling the zone. Leaving
the zone in its default THERMAL_DEVICE_DISABLED state avoids resume
updates while keeping thermal_zone_get_zone_by_name(),
thermal_zone_get_temp(), and sysfs temp reads working.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204113101.1141644-1-srinivas.kandagatla@oss.qualcomm.com?part=8
next prev parent reply other threads:[~2026-12-04 13:34 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 [this message]
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
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-249878@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.