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=1796179938; b=HJBPQcK9qDOUnQWj5v5m9OIp2otE0LWVtHRDGlmJyWrITziUW1vn8VQafp3CBmsxJ2bJ 5RQqqHlpFQ19hgim4TOs37ZpDOtHNThi9LqtkHitOzHCW2OgSsis+a0/7AJMLjLMtu+Rx sXc9pQHfu31VIfJxXou1CLtDWijfyASVuVXTaKpb38aVEFAzOzjHoacA0ZuXKEDxHzlik W0Th6dJ0cXials+nK/gKOL/zeLqKYiQr/nRnGwADJaMPvweDpzVJL1lNClZb2RWgIkaNs +IuV9/O1EdhMZgU1Pk0rI1nU+tcSqlBAl4S/vfXReg8+h0SUM//b9/5ZhgMVzm/3Nuw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796179938; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=AUy+B0Z1QpH1Sv47IGwJlhzJwNagSTOqBE1r4YJ+YXY=; b=Ep4A7n0GkcTW7BZ41FK+ioxftcQqX8xmZj7ZlF/9r/R8ULOwJWuAVK8Uae3qmHxn1AMA 8Xy3sSobSruUKu2FqR8HDZdsQF92H5wNV0M1Z5vQq3zQfMLZuhJ73A3VK8l81ENpvckUr 0OsoRlncDCRBpqJrUsdosb/D9ewK6Kse73k6vPVxcrfdED/lyntHpwxpPwNGpR08ZVw3y Nyo+NzcgGt9/nQjH334gCWfacV9dNl71LIVufISP7aID7qlljDdHufR+C4kmemAhGTpfh HwVFguB0UygXMGtmZna/P1HLV8fmDGsekxnb2xkHIvTRdRIkm14f7dfeLr0Hn4h43/A== 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=E6avGdxz; 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 D2F45606A31A for ; Wed, 2 Dec 2026 02:52:18 +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=E6avGdxz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B90D1F00897; Wed, 2 Dec 2026 02:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796179938; bh=AUy+B0Z1QpH1Sv47IGwJlhzJwNagSTOqBE1r4YJ+YXY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=E6avGdxzrHrvXb3wkWAKXPOD5mHhZGM61ph/23skgw87DKA8DxBwG5xuzY2wbUNEJ dJsoSTrL5Q+sMIqGMlgZzRYu+0IVTepEhvE3YZJZ88vTAEYzaPdg1SWY43vuVssVwe 6mBDn7BBU8MKCaejO55g1wt3e4NzEvQYE6CWTKFZPLEDMnANtHulfyTOGLLl6UrTBz 8NaBrajtuONp7IAkjymDm5mAo8N20drCJt5jizQhmuZeIcO1uNEtr2YFby6DJGRHmB Uaa8C5KazGYnZbGvu8FuL1juXTWXrsw96Q8ETQcE/+sH4u2MepyZYcrbjIgYntQthk XPQJLHbhz3ocA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 1/3] ASoC: codecs: add SN622x SDCA SoundWire codec support Reply-To: sashiko-reviews@lists.linux.dev To: "Qianghua Wang" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202022209.77448-2-qianghua.wang@senarytech.com> References: <20261202022209.77448-1-qianghua.wang@senarytech.com> <20261202022209.77448-2-qianghua.wang@senarytech.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 02:52:17 +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 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 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 > 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 :=3D sigmadsp-regmap.o > snd-soc-si476x-y :=3D si476x.o > snd-soc-sma1303-y :=3D sma1303.o > snd-soc-sma1307-y :=3D sma1307.o > +snd-soc-sn622x-sdca-y :=3D sn622x-sdca-sdw.o senary-sdca-sdw-common.o > snd-soc-sn624x-sdca-y :=3D 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 *slav= e, > + 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=3D%u status=3D%s\n", > + log_prefix, slave->unattach_request, > + senary_sdca_status_str(slave->status)); > + > + if (slave->unattach_request) { > + ret =3D sdw_slave_wait_for_init(slave, probe_timeout_ms); > + if (ret) > + return ret; > + slave->unattach_request =3D 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 =3D regmap_write(sn622x->regmap, SN622X_REG_MUTE, 0); > + if (ret < 0) > + dev_warn(dev, "sn622x: speaker unmute(L) failed (%d)\n", ret); > + ret =3D 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 =3D 0; > + struct reg_sequence clear_dmic =3D > + 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) =3D=3D 0 && > + (st & (SN622X_FUN_NEEDS_INIT | SN622X_FUN_HAS_BEEN_RESET))) { > + sn622x->dmic_analog_restored =3D false; > + sn622x->dmic_cap_cfg_done =3D 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[] =3D { > + REG_SEQ0(0x00002126u, 0x18), > + REG_SEQ0(0x00002127u, 0x01), > + REG_SEQ0(0x000020f3u, 0x30), > + }; > + > + r =3D 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 =3D true; > + } > + > + sn622x->dmic_route_latched =3D true; > + sn622x->dmic_recover_until =3D 0; > + > +out_unlock: > + mutex_unlock(&sn622x->path_lock); > +} [Severity: Medium] Does setting dmic_route_latched =3D true and dmic_recover_until =3D 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 i= nt reg) > +{ > + if (!SDW_SDCA_VALID_CTL(reg)) > + return true; > + > + if (SDW_SDCA_CTL_CSEL(reg) =3D=3D SDCA_CTL_PDE_ACTUAL_PS) > + return true; > + > + return false; > +} [Severity: Medium] Does checking SDW_SDCA_CTL_CSEL(reg) =3D=3D SDCA_CTL_PDE_ACTUAL_PS (0x10) without checking SDW_SDCA_CTL_ENT(reg) =3D=3D 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[] =3D { > + 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 =3D 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 =E2=80=94 minimal re-attach= \n"); > + > + if (sn622x->playback_active) { > + ret =3D 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 =3D 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 =3D=3D 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 =3D 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 =3D > + container_of(work, struct sn622x_sdca_priv, bus_recover_work.work); > + struct device *dev; > + bool got_pm =3D false; > + int ret; > + > + if (!sn622x->slave) > + return; > + > + dev =3D &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 =3D pm_runtime_resume_and_get(dev); > + if (ret =3D=3D -EACCES) > + return; > + if (ret < 0) { > + dev_dbg(dev, "sn622x: bus_recover: rpm get skipped (%d)\n", ret); > + return; > + } > + if (ret =3D=3D 0) > + got_pm =3D 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 =3D=3D 0), the device is alrea= dy 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 =3D 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 =3D sn622x->last_unattach_jiffies + > + msecs_to_jiffies(SN622X_ATTACH_DEBOUNCE_MS); > + unsigned int remain_ms; > + > + remain_ms =3D 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 =3D=3D 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 =3D snd_soc_component_get_drvdata(dai->= component); > + struct sdw_stream_runtime *sdw_stream =3D > + snd_soc_dai_get_dma_data(dai, substream); > + > + if (!sn622x->slave) > + return -EINVAL; > + > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE && > + dai->id =3D=3D SN622X_DAI_DMIC) { > + mutex_lock(&sn622x->path_lock); > + sn622x->dmic_active =3D false; > + sn622x->dmic_route_latched =3D false; > + sn622x->dmic_recover_until =3D 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 =3D=3D SNDRV_PCM_STREAM_PLAYBACK && > + dai->id =3D=3D SN622X_DAI_SPEAKER) > + sn622x->playback_active &=3D ~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 =3D=3D SNDRV_PCM_STREAM_PLAYBACK && > + dai->id =3D=3D SN622X_DAI_SPEAKER) > + sn622x_speaker_fu_unmute(dai->dev, sn622x); > + else if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE && > + dai->id =3D=3D SN622X_DAI_DMIC) { > + sn622x->dmic_active =3D 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 =3D 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 =3D true sn622x_bus_recover_work() sn622x_dmic_needs_recover() /* dmic_active && !dmic_route_latched * && dmic_recover_until =3D=3D 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 =3D dev_get_drvdata(&slave->dev); > + > + SN622X_DBG(&slave->dev, "SoundWire driver remove\n"); > + sn622x->dmic_active =3D 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 =3D 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 =3D 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 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202022209.7744= 8-1-qianghua.wang@senarytech.com?part=3D1