From: sashiko-bot@kernel.org
To: "Qianghua Wang" <qianghua.wang@senarytech.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v3 1/3] ASoC: codecs: add SN622x SDCA SoundWire codec support
Date: Wed, 02 Dec 2026 02:52:17 +0000 [thread overview]
Message-ID: <sashiko-outbox-244730@kernel.org> (raw)
In-Reply-To: <20261202022209.77448-2-qianghua.wang@senarytech.com>
Thank you for your contribution! Sashiko AI review found 15 potential
issues to consider:
- [High] ASoC: sn622x: 5s self-deadlock in sn622x_sdca_update_status()
PM recovery
- [High] ASoC: sn622x: ABBA deadlock between runtime suspend and
bus_recover_work
- [Medium] ASoC: sn622x: missing regcache_sync() in
senary_sdca_regmap_resume()
- [Medium] ASoC: sn622x: teardown ordering race in
sn622x_sdca_sdw_remove()
- [Medium] ASoC: sn622x: sn622x_dmic_capture_prepare() latches route on
I/O failure
- [Medium] ASoC: sn622x: speaker init table skipped after DMIC-only
re-attach
- [Medium] ASoC: sn622x: skipped speaker init in sn622x_sdca_io_init()
on re-attach
- [Medium] ASoC: sn622x: entity-unqualified csel check in
sn622x_sdca_volatile_register()
- [Medium] ASoC: sn622x: unreachable senary_sdca_pm_recover() in
sn622x_bus_recover_work()
- [Medium] ASoC: sn622x: zero volume writes in
sn622x_dmic_oem_fallback_init() on recover
- [Medium] ASoC: sn622x: unlocked shared state and PM recovery races
across PCM and bus
- [Medium] ASoC: sn622x: 400 ms synchronous sleep in
sn622x_sdca_update_status()
- [Medium] ASoC: sn622x: SDW_SLAVE_ALERT rejected by
sn622x_slave_attached() checks
- [Low] MAINTAINERS: add senary-sdca-sdw-common pattern to Senarytech
entry
- [Low] ASoC: sn622x: duplicated SDCA helpers with sn624x and in
sn622x_sdca_io_init()
--
commit 9271d71708abcb4f44c346eec88673e26b133d1c
Author: Qianghua Wang <qianghua.wang@senarytech.com>
ASoC: codecs: add SN622x SDCA SoundWire codec support
This commit adds the snd-soc-sn622x-sdca SoundWire codec driver for Senary
SN6220 and SN6224 SDCA devices along with shared SDCA SoundWire helpers in
senary-sdca-sdw-common.c.
> diff --git a/MAINTAINERS b/MAINTAINERS
> index e7e3c31cd0cfa..258549db8f5ae 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -30998,6 +30998,7 @@ M: qianghua.wang <qianghua.wang@senarytech.com>
> S: Maintained
> T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
> F: sound/hda/codecs/senarytech.c
> +F: sound/soc/codecs/sn622x*
> F: sound/soc/codecs/sn624x*
> F: sound/soc/sdw_utils/soc_sdw_senary*
[Severity: Low]
Should this entry also include a pattern for
sound/soc/codecs/senary-sdca-sdw-common* so get_maintainer.pl matches the
new shared helper files?
> diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
> index 6d865448428f9..d9eb4210c4052 100644
> --- a/sound/soc/codecs/Makefile
> +++ b/sound/soc/codecs/Makefile
> @@ -307,6 +307,7 @@ snd-soc-sigmadsp-regmap-y := sigmadsp-regmap.o
> snd-soc-si476x-y := si476x.o
> snd-soc-sma1303-y := sma1303.o
> snd-soc-sma1307-y := sma1307.o
> +snd-soc-sn622x-sdca-y := sn622x-sdca-sdw.o senary-sdca-sdw-common.o
> snd-soc-sn624x-sdca-y := sn624x-sdca-sdw.o
[Severity: Low]
As reported by Pierre-Louis Bossart on v2 [1], senary-sdca-sdw-common.o is
only linked into snd-soc-sn622x-sdca while sn624x-sdca-sdw.c still keeps
its own duplicate copy of these SDCA helpers (as well as near-identical
code such as sn622x_parse_sdca_functions()). In addition, inside
sn622x_sdca_io_init(), the speaker and DMIC FUN_STATUS handling in the
active-stream re-attach branch duplicates the normal initialization block
immediately below it.
> diff --git a/sound/soc/codecs/senary-sdca-sdw-common.c b/sound/soc/codecs/senary-sdca-sdw-common.c
> new file mode 100644
> index 0000000000000..77d86a54ceff8
> --- /dev/null
> +++ b/sound/soc/codecs/senary-sdca-sdw-common.c
[ ... ]
> +int senary_sdca_regmap_resume(struct device *dev, struct sdw_slave *slave,
> + struct regmap *regmap, bool first_hw_init,
> + unsigned int probe_timeout_ms,
> + const char *log_prefix)
> +{
> + int ret;
> +
> + if (!first_hw_init)
> + return 0;
> +
> + dev_dbg(dev, "%s: resume: unattach_request=%u status=%s\n",
> + log_prefix, slave->unattach_request,
> + senary_sdca_status_str(slave->status));
> +
> + if (slave->unattach_request) {
> + ret = sdw_slave_wait_for_init(slave, probe_timeout_ms);
> + if (ret)
> + return ret;
> + slave->unattach_request = 0;
> + }
> +
> + if (!senary_sdca_slave_bus_ready(slave))
> + return -ENODEV;
> +
> + regcache_cache_only(regmap, false);
> +
> + return 0;
> +}
[Severity: Medium]
Should senary_sdca_regmap_resume() call regcache_sync(regmap) after
disabling cache-only mode, and should sn622x_sdca_dev_suspend() and the
idle re-attach path in sn622x_sdca_io_init() call regcache_mark_dirty()?
Nothing in sn622x-sdca-sdw.c or senary-sdca-sdw-common.c calls
regcache_sync(), so cached SDCA controls (PDE power state, CS sample rate
index, FU mute and volume) are never written back to hardware after
suspend or bus reset.
> diff --git a/sound/soc/codecs/sn622x-sdca-sdw.c b/sound/soc/codecs/sn622x-sdca-sdw.c
> new file mode 100644
> index 0000000000000..043eae8d47d78
> --- /dev/null
> +++ b/sound/soc/codecs/sn622x-sdca-sdw.c
[ ... ]
> +#define sn622x_slave_attached senary_sdca_slave_attached
> +#define sn622x_slave_bus_ready senary_sdca_slave_bus_ready
[ ... ]
> +/* FU unmute after SDW transport is running (see .trigger START). */
> +static void sn622x_speaker_fu_unmute(struct device *dev,
> + struct sn622x_sdca_priv *sn622x)
> +{
> + int ret;
> +
> + if (!sn622x || !sn622x->regmap || !sn622x_slave_attached(sn622x->slave))
> + return;
> +
> + ret = regmap_write(sn622x->regmap, SN622X_REG_MUTE, 0);
> + if (ret < 0)
> + dev_warn(dev, "sn622x: speaker unmute(L) failed (%d)\n", ret);
> + ret = regmap_write(sn622x->regmap, SN622X_REG_RIGHT_MUTE, 0);
> + if (ret < 0)
> + dev_warn(dev, "sn622x: speaker unmute(R) failed (%d)\n", ret);
> +}
> +
> +static void sn622x_dmic_fu_unmute(struct device *dev,
> + struct sn622x_sdca_priv *sn622x)
> +{
> + int ret;
> +
> + if (!sn622x || !sn622x->regmap || !sn622x_slave_attached(sn622x->slave))
> + return;
[Severity: Medium]
Should these checks (along with sn622x_speaker_playback_prepare(),
sn622x_restore_dmic_analog(), sn622x_dmic_capture_prepare(), and
sn622x_sdca_pcm_hw_params()) use sn622x_slave_bus_ready() instead of
sn622x_slave_attached()? When sdw_handle_slave_alerts() services an alert
(such as initial parity or a DPN port-ready interrupt), slave->status
remains SDW_SLAVE_ALERT until the next status poll, causing hw_params() to
fail with -ENODEV or trigger() to silently leave the stream muted.
[ ... ]
> +/* DMIC vendor/analog after sdw_stream_add_slave; PDE/FU via DAPM. */
> +static void sn622x_dmic_capture_prepare(struct device *dev,
> + struct sn622x_sdca_priv *sn622x,
> + bool bringup)
> +{
> + unsigned int st = 0;
> + struct reg_sequence clear_dmic =
> + REG_SEQ0(SN622X_REG_DMIC_FUN_STATUS_CTL, 0x61);
> + int r;
> +
> + if (!sn622x || !sn622x->regmap || !sn622x->slave)
> + return;
> + if (sn622x_sdca_disco_omits_mic(sn622x->slave))
> + return;
> +
> + mutex_lock(&sn622x->path_lock);
> +
> + if (!sn622x_slave_attached(sn622x->slave)) {
> + dev_dbg(dev, "sn622x: dmic prepare: skip (not ATTACHED)\n");
> + goto out_unlock;
> + }
> +
> + if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_FUN_STATUS_CTL,
> + &st) == 0 &&
> + (st & (SN622X_FUN_NEEDS_INIT | SN622X_FUN_HAS_BEEN_RESET))) {
> + sn622x->dmic_analog_restored = false;
> + sn622x->dmic_cap_cfg_done = false;
> + regmap_multi_reg_write_bypassed(sn622x->regmap, &clear_dmic, 1);
> + usleep_range(1000, 1500);
> + }
> +
> + if (bringup || !sn622x->dmic_analog_restored)
> + sn622x_restore_dmic_analog(dev, sn622x,
> + bringup ? "dmic_pmu" : "dmic_recover");
> +
> + if (!sn622x->dmic_cap_cfg_done) {
> + static const struct reg_sequence cap_cfg[] = {
> + REG_SEQ0(0x00002126u, 0x18),
> + REG_SEQ0(0x00002127u, 0x01),
> + REG_SEQ0(0x000020f3u, 0x30),
> + };
> +
> + r = regmap_multi_reg_write_bypassed(sn622x->regmap, cap_cfg,
> + ARRAY_SIZE(cap_cfg));
> + if (r < 0)
> + dev_warn(dev,
> + "sn622x: dmic prepare: cap vendor cfg failed (%d)\n",
> + r);
> + else
> + sn622x->dmic_cap_cfg_done = true;
> + }
> +
> + sn622x->dmic_route_latched = true;
> + sn622x->dmic_recover_until = 0;
> +
> +out_unlock:
> + mutex_unlock(&sn622x->path_lock);
> +}
[Severity: Medium]
Does setting dmic_route_latched = true and dmic_recover_until = 0
unconditionally here disable DMIC recovery when an I/O write in
sn622x_restore_dmic_analog() or cap_cfg fails? Because
sn622x_dmic_needs_recover() returns false once dmic_route_latched is true,
neither sn622x_bus_recover_work() nor sn622x_sdca_trigger() will retry if
dmic_analog_restored or dmic_cap_cfg_done remains false.
[ ... ]
> +static bool sn622x_sdca_volatile_register(struct device *dev, unsigned int reg)
> +{
> + if (!SDW_SDCA_VALID_CTL(reg))
> + return true;
> +
> + if (SDW_SDCA_CTL_CSEL(reg) == SDCA_CTL_PDE_ACTUAL_PS)
> + return true;
> +
> + return false;
> +}
[Severity: Medium]
Does checking SDW_SDCA_CTL_CSEL(reg) == SDCA_CTL_PDE_ACTUAL_PS (0x10)
without checking SDW_SDCA_CTL_ENT(reg) == SN622X_SDCA_ENT_PDE03 mark
non-PDE registers as volatile? SDCA control selectors are scoped per
entity type, and SDCA_CTL_CS_SAMPLERATEINDEX is also 0x10, so
SN622X_REG_RATE_SEL (entity CS01) and SN622X_REG_DMIC_CAP_RATE_SEL (entity
CS02) are treated as volatile and excluded from REGCACHE_MAPLE.
[ ... ]
> +static int sn622x_dmic_oem_fallback_init(struct device *dev,
> + struct sn622x_sdca_priv *sn622x)
> +{
> + int ret;
> + const struct reg_sequence dmic_oem_table[] = {
> + REG_SEQ0(0x00002041, 0x00),
> + /* Omit PPU11 0x40880380 (NACK on SN6220). */
> + REG_SEQ0(0x00002105, 0x66),
> + REG_SEQ0(0x00002107, 0x26),
> + REG_SEQ0(0x00002109, 0x62),
> + REG_SEQ0(SN622X_REG_DMIC_CAP_MUTE, 0x00),
> + REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_MUTE, 0x00),
> + REG_SEQ0(SN622X_REG_DMIC_CAP_VOL, 0x00),
> + REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_VOL, 0x00),
> + REG_SEQ0(0x408029d8, 0x0c),
> + REG_SEQ0(0x408009d8, 0x00),
> + REG_SEQ0(0x408029d9, 0x0c),
> + REG_SEQ0(0x408009d9, 0x00),
> + REG_SEQ0(0x00002140, 0x18),
> + REG_SEQ0(0x00002045, 0x01),
> + };
> +
> + if (!sn622x || !sn622x->regmap || !sn622x->slave)
> + return -ENODEV;
> +
> + dev_warn_once(dev,
> + "sn622x: using DMIC OEM init fallback (no ACPI init table)\n");
> + ret = regmap_multi_reg_write_bypassed(sn622x->regmap, dmic_oem_table,
> + ARRAY_SIZE(dmic_oem_table));
[Severity: Medium]
When sn622x_dmic_capture_prepare() runs during sn622x_sdca_trigger() or
sn622x_bus_recover_work() after DAPM SND_SOC_DAPM_POST_PMU has already
executed sn622x_fu_dmic_event(), won't writing 0x00 to
SN622X_REG_DMIC_CAP_VOL and SN622X_REG_DMIC_CAP_CHR_VOL via
regmap_multi_reg_write_bypassed() overwrite SN622X_DMIC_VOL_DEFAULT
(0xfb4d) in hardware without updating the regmap cache? It also unmutes
SN622X_REG_DMIC_CAP_MUTE and SN622X_REG_DMIC_CAP_CHR_MUTE during
hw_params() before DAPM power-up and TRIGGER_START.
[ ... ]
> + /*
> + * Re-attach while PCM is open: skip heavy speaker tables, but still
> + * re-enable regmap I/O, IRQ masks, and FUN status handling (same bus).
> + */
> + if (sn622x->first_hw_init &&
> + (sn622x->playback_active || sn622x->dmic_active)) {
> + unsigned int spk_func_status;
> +
> + dev_dbg(dev, "sn622x: io_init: stream open — minimal re-attach\n");
> +
> + if (sn622x->playback_active) {
> + ret = regmap_read_bypassed(sn622x->regmap,
> + SN622X_REG_SPEAKER_FUN_STATUS_CTL,
> + &spk_func_status);
> + if (ret < 0) {
> + dev_dbg(dev,
> + "sn622x: io_init: SPEAKER FUN STATUS read failed (%d)\n",
> + ret);
> + } else if (spk_func_status & (SN622X_FUN_NEEDS_INIT |
> + SN622X_FUN_HAS_BEEN_RESET)) {
> + ret = sn622x_speaker_apply_defaults(dev, sn622x);
> + if (ret < 0)
> + dev_warn(dev,
> + "sn622x: io_init: speaker init table failed (%d)\n",
> + ret);
> + usleep_range(5000, 8000);
> + if (sn622x->slave->status == SDW_SLAVE_ATTACHED)
> + sn622x_speaker_fun_ack_if_needed(dev, sn622x);
> + }
> + }
[Severity: Medium]
If the codec resets and re-attaches while only DMIC capture is active
(dmic_active is true and playback_active is 0), doesn't this branch skip
sn622x_speaker_apply_defaults() and still set hw_init = true?
When speaker playback is started later, sn622x_speaker_playback_prepare()
calls sn622x_speaker_fun_ack_if_needed(), which clears
SN622X_FUN_NEEDS_INIT and SN622X_FUN_HAS_BEEN_RESET without applying the
speaker initialization table.
[Severity: Medium]
Can gating speaker initialization on playback_active here leave the
speaker SmartAmp function uninitialized after a reset during DMIC-only
capture because sn622x_speaker_playback_prepare() subsequently clears the
speaker function's needs-init status bits without running
sn622x_speaker_apply_defaults()?
[ ... ]
> +static void sn622x_bus_recover_work(struct work_struct *work)
> +{
> + struct sn622x_sdca_priv *sn622x =
> + container_of(work, struct sn622x_sdca_priv, bus_recover_work.work);
> + struct device *dev;
> + bool got_pm = false;
> + int ret;
> +
> + if (!sn622x->slave)
> + return;
> +
> + dev = &sn622x->slave->dev;
> +
> + if (!sn622x_slave_attached(sn622x->slave)) {
> + if (sn622x_dmic_needs_recover(sn622x))
> + sn622x_schedule_bus_recover(sn622x,
> + SN622X_BUS_RECOVER_DMIC_MS);
> + return;
> + }
> +
> + if (pm_runtime_enabled(dev)) {
> + ret = pm_runtime_resume_and_get(dev);
> + if (ret == -EACCES)
> + return;
> + if (ret < 0) {
> + dev_dbg(dev, "sn622x: bus_recover: rpm get skipped (%d)\n", ret);
> + return;
> + }
> + if (ret == 0)
> + got_pm = true;
> + } else if (sn622x->hw_init) {
> + return;
> + }
> +
> + senary_sdca_pm_recover(dev, SN622X_LOG_PREFIX);
[Severity: Medium]
Doesn't returning early whenever pm_runtime_resume_and_get(dev) < 0 make
senary_sdca_pm_recover() unreachable when runtime PM is in an error state?
If pm_runtime_resume_and_get() succeeds (ret == 0), the device is already
RPM_ACTIVE, and if runtime PM is disabled, senary_sdca_pm_recover()
returns immediately, so a sticky runtime PM error from an earlier resume
while unattached is never cleared here.
> +
> + if (!sn622x->hw_init)
> + sn622x_sdca_io_init(dev, sn622x->slave);
> +
> + if (sn622x_dmic_needs_recover(sn622x) &&
> + (!sn622x->playback_active || !sn622x->dmic_route_latched)) {
> + dev_dbg(dev, "sn622x: bus_recover: DMIC capture prepare\n");
> + sn622x_dmic_capture_prepare(dev, sn622x, false);
> + if (sn622x_dmic_needs_recover(sn622x))
> + sn622x_schedule_bus_recover(sn622x,
> + SN622X_BUS_RECOVER_DMIC_MS);
> + }
> +
> + if (got_pm) {
> + pm_runtime_mark_last_busy(dev);
> + pm_runtime_put_autosuspend(dev);
> + }
> +}
> +
> +static int sn622x_sdca_update_status(struct sdw_slave *slave,
> + enum sdw_slave_status status)
> +{
> + struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
[ ... ]
> + if (sn622x->first_hw_init &&
> + time_before(jiffies, sn622x->last_unattach_jiffies +
> + msecs_to_jiffies(SN622X_ATTACH_DEBOUNCE_MS))) {
> + unsigned long deadline = sn622x->last_unattach_jiffies +
> + msecs_to_jiffies(SN622X_ATTACH_DEBOUNCE_MS);
> + unsigned int remain_ms;
> +
> + remain_ms = time_before(jiffies, deadline) ?
> + jiffies_to_msecs(deadline - jiffies) : 0;
> + if (remain_ms)
> + usleep_range(remain_ms * 1000, remain_ms * 1000 + 500);
[Severity: Medium]
Won't sleeping synchronously for up to 400 ms in
sn622x_sdca_update_status() stall the SoundWire bus status thread on every
runtime or system resume? Because bus resume calls
sdw_clear_slave_status() (recording last_unattach_jiffies) right before
re-enumerating the link, SDW_SLAVE_ATTACHED arrives a few milliseconds
later and blocks sdw_handle_slave_status() under slave->sdw_dev_lock for
~400 ms before complete_all(&slave->initialization_complete) or other
slaves on the link can be processed.
> +
> + dev_dbg(&slave->dev,
> + "sn622x: io_init after %u ms post-UNATTACH debounce\n",
> + remain_ms);
> + senary_sdca_pm_recover(&slave->dev, SN622X_LOG_PREFIX);
> + return sn622x_sdca_io_init(&slave->dev, slave);
> + }
> +
> + senary_sdca_pm_recover(&slave->dev, SN622X_LOG_PREFIX);
> + return sn622x_sdca_io_init(&slave->dev, slave);
> +}
[Severity: High]
Doesn't calling senary_sdca_pm_recover() inside
sn622x_sdca_update_status() self-deadlock for 5 seconds whenever the slave
re-attaches while runtime-suspended with slave->unattach_request set?
sdw_handle_slave_status()
sdw_update_slave_status(slave, SDW_SLAVE_ATTACHED)
sn622x_sdca_update_status()
senary_sdca_pm_recover()
pm_runtime_resume()
sn622x_sdca_dev_resume()
senary_sdca_regmap_resume()
sdw_slave_wait_for_init()
wait_for_completion_timeout(&slave->initialization_complete)
<-- waits 5000 ms for sdw_handle_slave_status() to finish
sdw_handle_slave_status() does not signal slave->initialization_complete
until after sn622x_sdca_update_status() returns. After
sdw_slave_wait_for_init() times out with -ETIMEDOUT,
senary_sdca_pm_recover() resets the device runtime PM state to
RPM_SUSPENDED right before sn622x_sdca_io_init() disables cache-only mode
and performs register I/O with first_hw_init == true (which skips
pm_runtime_set_active()).
[ ... ]
> +static int sn622x_sdca_pcm_hw_free(struct snd_pcm_substream *substream,
> + struct snd_soc_dai *dai)
> +{
> + struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(dai->component);
> + struct sdw_stream_runtime *sdw_stream =
> + snd_soc_dai_get_dma_data(dai, substream);
> +
> + if (!sn622x->slave)
> + return -EINVAL;
> +
> + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
> + dai->id == SN622X_DAI_DMIC) {
> + mutex_lock(&sn622x->path_lock);
> + sn622x->dmic_active = false;
> + sn622x->dmic_route_latched = false;
> + sn622x->dmic_recover_until = 0;
> + mutex_unlock(&sn622x->path_lock);
> + cancel_delayed_work_sync(&sn622x->bus_recover_work);
> + /*
> + * Closing capture must not drop a deferred io_init (ATTACH
> + * debounce) while the slave is still on the bus.
> + */
> + if (sn622x_slave_attached(sn622x->slave) && !sn622x->hw_init)
> + sn622x_schedule_bus_recover(sn622x,
> + SN622X_BUS_RECOVER_SETTLE_MS);
> + }
> + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
> + dai->id == SN622X_DAI_SPEAKER)
> + sn622x->playback_active &= ~SN622X_PB_ACTIVE_SPK;
> +
> + return sdw_stream_remove_slave(sn622x->slave, sdw_stream);
> +}
[ ... ]
> +static int sn622x_sdca_trigger(struct snd_pcm_substream *substream, int cmd,
> + struct snd_soc_dai *dai)
> +{
[ ... ]
> + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
> + dai->id == SN622X_DAI_SPEAKER)
> + sn622x_speaker_fu_unmute(dai->dev, sn622x);
> + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
> + dai->id == SN622X_DAI_DMIC) {
> + sn622x->dmic_active = true;
> + if (!sn622x->dmic_route_latched)
> + sn622x_dmic_capture_prepare(dai->dev, sn622x, false);
> + sn622x_dmic_fu_unmute(dai->dev, sn622x);
> + }
[Severity: Medium]
Can accessing dmic_active and dmic_route_latched without path_lock here
(as well as playback_active and dmic_route_latched in
sn622x_sdca_pcm_hw_params()/hw_free(), dmic_* flags in
sn622x_sdca_dev_system_suspend(), and last_unattach_jiffies in
sn622x_sdca_update_status()) race with UNATTACH/ATTACH handling and
bus_recover_work?
CPU0 CPU1
sn622x_sdca_pcm_hw_params()
dmic_route_latched = false
sn622x_sdca_update_status(UNATTACHED)
mutex_lock(&sn622x->path_lock)
/* dmic_active is still false:
* dmic_recover_until stays 0 */
mutex_unlock(&sn622x->path_lock)
sn622x_schedule_bus_recover(..., 400)
sn622x_sdca_trigger(START)
dmic_active = true
sn622x_bus_recover_work()
sn622x_dmic_needs_recover()
/* dmic_active && !dmic_route_latched
* && dmic_recover_until == 0 */
sn622x_schedule_bus_recover(..., 150)
<-- reschedules every 150 ms forever
In addition, because SDW_SLAVE_UNATTACHED schedules bus_recover_work for
400 ms and SDW_SLAVE_ATTACHED does not cancel bus_recover_work before
sleeping for the same 400 ms SN622X_ATTACH_DEBOUNCE_MS deadline, both
threads can wake simultaneously and run senary_sdca_pm_recover() (which
disables and resets runtime PM) concurrently.
[ ... ]
> +static void sn622x_sdca_sdw_remove(struct sdw_slave *slave)
> +{
> + struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
> +
> + SN622X_DBG(&slave->dev, "SoundWire driver remove\n");
> + sn622x->dmic_active = false;
> + cancel_delayed_work_sync(&sn622x->bus_recover_work);
> + if (sn622x->first_hw_init) {
> + pm_runtime_dont_use_autosuspend(&slave->dev);
> + pm_runtime_disable(&slave->dev);
> + }
> + mutex_destroy(&sn622x->path_lock);
> + mutex_destroy(&sn622x->disable_irq_lock);
> +}
[Severity: Medium]
Can destroying path_lock and cancelling bus_recover_work in
sn622x_sdca_sdw_remove() cause a use-after-free if the driver is unbound
while a DMIC capture stream is open? Because the ASoC component is
registered with devm_snd_soc_register_component(), devres unregisters the
component after sn622x_sdca_sdw_remove() returns, which closes active
substreams and invokes sn622x_sdca_pcm_hw_free() ->
mutex_lock(&sn622x->path_lock) and sn622x_schedule_bus_recover() right
before devres frees sn622x.
[ ... ]
> +static int sn622x_sdca_dev_suspend(struct device *dev)
> +{
> + struct sn622x_sdca_priv *sn622x = dev_get_drvdata(dev);
> +
> + if (!sn622x->first_hw_init)
> + return 0;
> +
> + SN622X_DBG(dev, "runtime suspend\n");
> +
> + cancel_delayed_work_sync(&sn622x->bus_recover_work);
> + regcache_cache_only(sn622x->regmap, true);
> +
> + return 0;
> +}
[Severity: High]
Can cancel_delayed_work_sync(&sn622x->bus_recover_work) inside the
.runtime_suspend callback cause an ABBA deadlock with
sn622x_bus_recover_work()?
CPU0 CPU1 (system_wq)
---- ----------------
rpm_suspend(dev)
/* runtime_status = RPM_SUSPENDING */
sn622x_sdca_dev_suspend(dev)
sn622x_bus_recover_work()
pm_runtime_resume_and_get(dev)
rpm_resume(dev)
/* waits for RPM_SUSPENDING */
cancel_delayed_work_sync(&sn622x->bus_recover_work)
*** DEADLOCK ***
When rpm_suspend() invokes sn622x_sdca_dev_suspend(), dev's runtime status
is RPM_SUSPENDING. If sn622x_bus_recover_work() is running on system_wq
and calls synchronous pm_runtime_resume_and_get(dev), rpm_resume() sleeps
waiting for RPM_SUSPENDING to finish while cancel_delayed_work_sync()
waits for sn622x_bus_recover_work() to finish.
[1] https://lore.kernel.org/r/59f99b1e-b1c5-4953-aab5-c6eb3e869f80@linux.dev
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202022209.77448-1-qianghua.wang@senarytech.com?part=1
next prev parent reply other threads:[~2026-12-02 2:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 2:22 [PATCH v3 0/3] ASoC: add Senary SN622x SDCA SoundWire support Qianghua Wang
2026-12-02 2:22 ` [PATCH v3 1/3] ASoC: codecs: add SN622x SDCA SoundWire codec support Qianghua Wang
2026-12-02 2:52 ` sashiko-bot [this message]
2026-12-02 2:22 ` [PATCH v3 2/3] ASoC: sdw_utils: add SN622x codec_info and DAPM hooks Qianghua Wang
2026-12-02 2:40 ` sashiko-bot
2026-12-02 2:22 ` [PATCH v3 3/3] ASoC: Intel: soc-acpi: add SN622x PTL/NVL SoundWire machines Qianghua Wang
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-244730@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=qianghua.wang@senarytech.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox