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=1796095383; b=fuzMi6FIQIE+SQC2DpM2cZjBut/mF/nlM0ude0TMksbYRzE5Bbuvd0dTdUluNglyw/Fg Gwq48ZAOsRslm72irUbXNuGYPv9IVo8BYA0yTiSe189GhSSfVhD3/4CVMUBgLngSqwmoS OXUK1x29iAJYB2WVhlAghcdAza97mvWsl9VFu9GNJZABxps8xsfB2sdE+hFow2SjXM46w CiYu+y5Zsc1MTydWyf5oprnltIO75iv2VYluqv/FAqE6rS4K5K9xYNlO2nKpLbVYcSkWv AGMbYKEHje0RDtwMDsV4WwH1uICyhYxC3lE4BE5CZbSo2sCoQdeZTg14GrQnR4g7MtA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796095383; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=BzZJv5idSS4dU63fsH/eIXGWiLuQPAQPJ4Y676TLbwI=; b=EVuDPK/ZL3WY0S35ZITTWB6kPtQg8MOrq8PJY98CZQLNHPrra8jCwfJo0hG40n+1r63b ZlSkiqzuuFRgLJ/PL7cai4LPMBmpxCJN/vfylbqU//ae3s/nlxjziDBX2H+pMOD7MWQOG qLb1Szqf1qT8Yf323EdIRE7nlelb1ag/pLEVT049rdRwWoW8vLsosT6K97NtOezsU6qnB gG6p0+JoBq+06jFvC+cw1jYtv1UEnEi6WikqOXq6cQ6WTVv9vMouZ0UkKH9CMTMTB+sw4 EaxkQNUrCsFFAnx7g40C0rmj2rUpX1Lv1L/Ad4C4cuK2OF+AT5vCclMJ7UkDkRf071w== 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=QHoh1So8; 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 E0451606A31A for ; Tue, 1 Dec 2026 03:23:02 +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=QHoh1So8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B1371F00897; Tue, 1 Dec 2026 03:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796095382; bh=BzZJv5idSS4dU63fsH/eIXGWiLuQPAQPJ4Y676TLbwI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QHoh1So82A0SSlmqX6Zrv7eCu1p/ypZIFmxcYkhzyJ7svDjlnxe0tksDDMPUEor5n YDsg1OfXkj0V8xiAGmM964vsAtD/Efajw4dd9za4wiUHDW+sPNau8saqph1R8Z5w2F LwkYtcHubCQGqrYZUIf/avEeafrQVibAbaqwzPLfeDRlLrkxqcy9HHH5PMkzPCxMmf CtJx01dUl+TcMbQ/Hb42qdaZL7cHGW4XPSgStU4hrddqGvj9C/GyiyBZv6G83/Y9mI Di1YRUxGPMG+KvLRSLcSov4ZZKmJrS+CytsmwYQ2amKxZiqVFslWx2OJTBeTy1a3bP +Df2B5mX/esbA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 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: <20261201025636.60506-2-qianghua.wang@senarytech.com> References: <20261201025636.60506-1-qianghua.wang@senarytech.com> <20261201025636.60506-2-qianghua.wang@senarytech.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 03:23:02 +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 16 potential issues to consider: - [High] ASoC: sn622x: broken MBQ sizing in sn622x_sdca_mbq_size() and volume write order - [High] ASoC: sn622x: unreachable dmic_active branch and skipped init in sn622x_sdca_io_init() - [High] ASoC: sn622x: dmic_analog_restored and dmic_cap_cfg_done never cleared on reset - [High] ASoC: sn622x: broken runtime PM lifecycle in sn622x_sdca_init() and io_init() - [High] ASoC: sn622x: sn622x_sdca_dev_resume() leaves regmap in cache-only mode - [High] ASoC: sn622x: unguarded sdw_write_no_pm() in probe and system suspend - [Medium] ASoC: sn622x: sn622x_clear_dp0_int() duplicates bus core DP0 interrupt handling - [Medium] ASoC: sn622x: missing stream rollback on error in sn622x_sdca_pcm_hw_params() - [Medium] ASoC: sn622x: skipped cleanup on runtime PM error in sn622x_sdca_pcm_hw_free() - [Medium] ASoC: sn622x: missing sn622x_sdca_disco_omits_mic() guards in prop and init - [Medium] ASoC: sn622x: broken bus_recover_work cancellation and state sync on unattach - [Medium] ASoC: sn622x: uncanceled bus_recover_work races with system suspend - [Medium] ASoC: sn622x: sn622x_sdca_dev_resume() returns 0 with regmap left cache-only - [Medium] ASoC: sn622x: repeated and unbounded polling in sn622x_dmic_needs_recover() - [Medium] ASoC: sn622x: missing cleanup on regmap_write() error in hw_params - [Low] ASoC: sn622x: dead S16_LE bps check in sn622x_sdca_pcm_hw_params() and unused definitions -- commit 460bd275ece026483bbb20b3f6335f1bd2ea73c2 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 supporting speaker playback and internal DMIC capture. > diff --git a/sound/soc/codecs/sn622x-sdca-sdw.c b/sound/soc/codecs/sn622x= -sdca-sdw.c > new file mode 100644 > index 0000000000000..b492fda63e37f > --- /dev/null > +++ b/sound/soc/codecs/sn622x-sdca-sdw.c [ ... ] > +#define SN622X_SPK_VOL_PRIM_DEFAULT 0x00u > +#define SN622X_SPK_VOL_SECOND_DEFAULT 0xfau > +#define SN622X_SPK_CHR_VOL_PRIM_DEFAULT 0x00u > +#define SN622X_SPK_CHR_VOL_SECOND_DEFAULT 0xfau > +#define SN622X_REG_SPEAKER_FUN_STATUS_CTL \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_SPEAKER, SN622X_SDCA_ENT_E= NTITY0, \ > + SN622X_SDCA_CTL_FUNCTION_STATUS, 0)) > + > +/* Speaker vendor SCP (not SDCA): charge-pump enable value per SN6220 ma= p */ > +#define SN622X_VENDOR_REG_CHARGE_PUMP 0x00002086u > +#define SN622X_CHARGE_PUMP_ENABLE 0x0bu > + > +/* DMIC capture (function 2) */ > +#define SN622X_REG_DMIC_CAP_MUTE \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT= _USER_FU20, \ > + SN622X_SDCA_CTL_FU_MUTE, SN622X_SDCA_CH_L)) > +#define SN622X_REG_DMIC_CAP_CHR_MUTE \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT= _USER_FU20, \ > + SN622X_SDCA_CTL_FU_MUTE, SN622X_SDCA_CH_R)) > +#define SN622X_REG_DMIC_CAP_VOL_FRAC \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT= _USER_FU20, \ > + SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_L)) > +#define SN622X_REG_DMIC_CAP_VOL_INT \ > + SN622X_SDCA_U32(SDW_SDCA_MBQ_CTL(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY= , \ > + SN622X_SDCA_ENT_USER_FU20, \ > + SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_L))) > +#define SN622X_REG_DMIC_CAP_CHR_VOL_FRAC \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT= _USER_FU20, \ > + SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_R)) > +#define SN622X_REG_DMIC_CAP_CHR_VOL_INT \ > + SN622X_SDCA_U32(SDW_SDCA_MBQ_CTL(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY= , \ > + SN622X_SDCA_ENT_USER_FU20, \ > + SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_R))) > +#define SN622X_REG_DMIC_CAP_RATE_SEL \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT= _CS02, \ > + SN622X_SDCA_CTL_SAMPLE_FREQ_INDEX, 0)) > +#define SN622X_REG_DMIC_MFPU_BYPASS \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT= _MFPU08, \ > + SN622X_SDCA_CTL_FU_MUTE, 0)) > +#define SN622X_REG_DMIC_MFPU_ALGO_ENABLE \ > + SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT= _MFPU08, \ > + SN622X_SDCA_CTL_FU_VOLUME, 0)) [ ... ] > +/* DMIC vendor init table; run when analog not yet restored for this att= ach. */ > +static void sn622x_restore_dmic_analog(struct device *dev, > + struct sn622x_sdca_priv *sn622x, > + const char *why) > +{ > + struct reg_sequence clear_dmic =3D > + REG_SEQ0(SN622X_REG_DMIC_FUN_STATUS_CTL, 0x61); > + int ret; > + > + if (!sn622x || !sn622x->regmap || !sn622x->slave) > + return; > + if (!sn622x_slave_attached(sn622x->slave)) { > + dev_dbg(dev, "sn622x: restore dmic skip (%s): not ATTACHED\n", > + why ? why : "?"); > + return; > + } > + if (sn622x->dmic_analog_restored) { > + dev_dbg(dev, "sn622x: restore dmic skip (%s): already done\n", > + why ? why : "?"); > + return; > + } > + > + dev_dbg(dev, "sn622x: restore dmic analog (%s)\n", why ? why : "?"); > + > + ret =3D sn622x_dmic_apply_defaults(dev, sn622x); > + if (ret < 0) { > + dev_warn(dev, "sn622x: restore dmic: init table failed (%d)\n", > + ret); > + return; > + } > + > + ret =3D regmap_multi_reg_write_bypassed(sn622x->regmap, &clear_dmic, 1); > + if (ret < 0) { > + dev_warn(dev, "sn622x: restore dmic: FUN STATUS clear failed (%d)\n", > + ret); > + return; > + } > + usleep_range(1000, 1500); > + sn622x->dmic_analog_restored =3D true; > +} > + > +/* 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, > + unsigned int pcm_rate, > + 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; > + > + 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))) { > + 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; > + (void)pcm_rate; > + > +out_unlock: > + mutex_unlock(&sn622x->path_lock); > +} [Severity: High] Are dmic_analog_restored and dmic_cap_cfg_done left set across device resets and system suspend? Once a first capture stream sets both flags, neither is ever cleared on SDW_SLAVE_UNATTACHED, system suspend, or when SN622X_REG_DMIC_FUN_STATUS_CTL reports SN622X_FUN_NEEDS_INIT | SN622X_FUN_HAS_BEEN_RESET. After a codec reset or power loss, sn622x_sdca_io_init() and sn622x_dmic_capture_prepare() acknowledge and clear the Function Status reset bits without re-running sn622x_dmic_apply_defaults() or reprogramming cap_cfg[]. [ ... ] > +static int sn622x_sdca_mbq_size(struct device *dev, unsigned int reg) > +{ > + if (!SDW_SDCA_VALID_CTL(reg)) > + return 1; > + > + switch (reg) { > + case SN622X_REG_VOL_SECOND: > + case SN622X_REG_CHR_VOL_SECOND: > + case SN622X_REG_DMIC_CAP_VOL_INT: > + case SN622X_REG_DMIC_CAP_VOL_FRAC: > + case SN622X_REG_DMIC_CAP_CHR_VOL_INT: > + case SN622X_REG_DMIC_CAP_CHR_VOL_FRAC: > + return 2; > + default: > + return 1; > + } > +} [Severity: High] Does sn622x_sdca_mbq_size() reject the SDW_SDCA_MBQ_CTL() volume addresses while sn622x_fu_mute_event() writes the MBQ bytes in reverse order? SDW_SDCA_MBQ_CTL() sets BIT(13), which makes SDW_SDCA_VALID_CTL(reg) false. As a result, the SN622X_REG_*_VOL_SECOND and SN622X_REG_DMIC_CAP_*_VOL_INT cases are unreachable, SN622X_REG_DMIC_CAP_*_VOL_FRAC returns 2, and SN622X_REG_*_VOL_PRIM returns 1. In addition, sn622x_fu_mute_event() writes the base address (BIT(13) =3D=3D= 0) before the MBQ staging address (BIT(13) =3D=3D 1) instead of letting regmap-sdw-mbq perform a single 2-byte write to the base control address (which stages the upper byte at BIT(13) =3D=3D 1 first and commits via BIT(13) =3D=3D 0 second). For DMIC, writing 0x4d to VOL_FRAC (size 2) latc= hes 0x004d and the subsequent 1-byte write of 0xfb to VOL_INT is left uncommitted in the MBQ latch; for speaker, writing 0x00 to VOL_PRIM commits a stale MBQ byte and leaves 0xfa in VOL_SECOND uncommitted. [ ... ] > +static void sn622x_sdca_sdca_irq_mask_all(struct sn622x_sdca_priv *sn622= x) > +{ > + if (!sn622x->slave) > + return; > + > + sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK1, 0); > + sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK2, 0); > + sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK3, 0); > + sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK4, 0); > + SN622X_DBG(&sn622x->slave->dev, > + "SDCA INTMASK1-4 =3D 0 (all SDCA sources masked)\n"); > +} > + > +static int sn622x_sdca_io_init(struct device *dev, struct sdw_slave *sla= ve) > +{ > + struct sn622x_sdca_priv *sn622x =3D dev_get_drvdata(dev); > + int ret; > + unsigned int dmic_func_status; > + if (sn622x->hw_init) { > + SN622X_DBG(dev, "io_init: skip (hw_init already true)\n"); > + return 0; > + } > + > + mutex_lock(&sn622x->path_lock); > + if (sn622x->hw_init) { > + mutex_unlock(&sn622x->path_lock); > + return 0; > + } > + /* PCM open: defer full io_init until streams close (same bus, no extra= SCP). */ > + if (sn622x->first_hw_init && > + (sn622x->playback_active || sn622x->dmic_active)) { > + dev_dbg(dev, "sn622x: io_init: stream open =E2=80=94 skip bus access\n= "); > + sn622x->hw_init =3D true; > + mutex_unlock(&sn622x->path_lock); > + return 0; > + } > + /* Capture still active: minimal cache/PM + DMIC FUN ACK; route in prep= are. */ > + if (sn622x->dmic_active) { [Severity: High] Does the first dmic_active check in sn622x_sdca_io_init() make the following if (sn622x->dmic_active) block unreachable and skip re-attach initialization? sn622x->dmic_active can only become true in sn622x_sdca_trigger() after initial attachment has already set sn622x->first_hw_init =3D true. When the slave detaches and re-attaches while a playback or capture stream is open, the first branch always matches, sets sn622x->hw_init =3D true, and returns without disabling regcache_cache_only, masking SDCA interrupts, or acknowledging Function Status, and io_init is never re-run when the stream closes. [ ... ] > +static bool sn622x_dmic_needs_recover(const struct sn622x_sdca_priv *sn6= 22x) > +{ > + if (!sn622x->dmic_active) > + return false; > + if (!sn622x->dmic_route_latched) > + return true; > + if (sn622x->dmic_recover_until && > + time_before(jiffies, sn622x->dmic_recover_until)) > + return true; > + return false; > +} > + > +/* > + * Deferred bring-up after UNATTACH (external HP mux): runtime PM cleanu= p, > + * io_init when re-attached, DMIC vendor prepare retries while capture i= s open. > + */ > +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; > + } > + > + ret =3D pm_runtime_resume_and_get(dev); > + if (ret < 0 && ret !=3D -EACCES) > + return; > + if (ret =3D=3D 0) > + got_pm =3D true; > + > + sn622x_pm_recover(dev); > + > + 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, sn622x->dmic_rate, false); > + if (sn622x_dmic_needs_recover(sn622x)) > + sn622x_schedule_bus_recover(sn622x, > + SN622X_BUS_RECOVER_DMIC_MS); > + } [Severity: Medium] Does sn622x_dmic_needs_recover() cause sn622x_bus_recover_work() to poll indefinitely while unattached and repeatedly after recovery? Because !sn622x->dmic_route_latched is checked before sn622x->dmic_recover_until, an unattached slave reschedules bus_recover_work every 150 ms without bound instead of stopping at the 2 second deadline. Once attached, sn622x_dmic_capture_prepare() sets dmic_route_latched =3D true without clearing dmic_recover_until, so sn622x_dmic_needs_recover() keeps returning true for the full 2 seconds and repeatedly re-runs sn622x_dmic_capture_prepare() every 150 ms when playback_active is 0. > + > + 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); > + > + SN622X_DBG(&slave->dev, "update_status: %s hw_init=3D%d dev_num=3D%u\n", > + sn622x_status_str(status), sn622x->hw_init, slave->dev_num); > + > + if (status =3D=3D SDW_SLAVE_UNATTACHED) { > + unsigned long prev_unattach =3D sn622x->last_unattach_jiffies; > + > + sn622x->hw_init =3D false; > + sn622x->last_unattach_jiffies =3D jiffies; > + /* After ATTACH, capture prepare re-latches route; keep dmic_analog_re= stored. */ > + sn622x->dmic_route_latched =3D false; > + if (prev_unattach && > + time_before(jiffies, prev_unattach + > + msecs_to_jiffies(SN622X_UNATTACH_STORM_WINDOW_MS))) > + sn622x->unattach_storm++; > + else > + sn622x->unattach_storm =3D 1; > + if (sn622x->dmic_active && > + sn622x->unattach_storm >=3D SN622X_UNATTACH_STORM_MAX) { > + dev_warn(&slave->dev, > + "sn622x: rapid UNATTACH =E2=80=94 stop DMIC recover\n"); > + sn622x->dmic_active =3D false; > + sn622x->dmic_recover_until =3D 0; > + cancel_delayed_work(&sn622x->bus_recover_work); > + } else if (sn622x->dmic_active) { > + sn622x->dmic_recover_until =3D jiffies + 2 * HZ; > + } > + sn622x_schedule_bus_recover(sn622x, SN622X_BUS_RECOVER_SETTLE_MS); > + } [Severity: Medium] Doesn't sn622x_schedule_bus_recover() immediately re-queue bus_recover_work right after the unattach-storm branch cancels it? Also, when SDW_SLAVE_ATTACHED occurs within SN622X_ATTACH_DEBOUNCE_MS, sn622x_sdca_update_status() defers sn622x_sdca_io_init() to bus_recover_work; if the capture stream closes during that window, cancel_delayed_work_sync(&sn622x->bus_recover_work) in sn622x_sdca_pcm_hw_free() cancels the pending io_init and leaves hw_init false while attached. In addition, dmic_active, dmic_route_latched, dmic_recover_until, dmic_rate, playback_active, and hw_init are accessed across PCM callbacks, update_status, and bus_recover_work without common locking. [ ... ] > +static int sn622x_sdca_read_prop(struct sdw_slave *slave) > +{ > + struct sdw_slave_prop *prop =3D &slave->prop; > + struct sdw_dpn_prop *dpn; > + unsigned long addr; > + unsigned int bit; > + int nval; > + int i, j; > + > + sdw_slave_read_lane_mapping(slave); > + prop->scp_int1_mask =3D SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY; > + prop->quirks =3D SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY; > + prop->paging_support =3D true; > + prop->use_domain_irq =3D true; > + /* dev_num 1 on this link: wake_capable is unsupported on Intel hosts. = */ > + prop->wake_capable =3D false; > + > + /* SN6220: speaker playback (port1) + DMIC capture (port3) only */ > + prop->source_ports =3D BIT(SN622X_PORT_DMIC_CAPTURE); [Severity: Medium] Should sn622x_sdca_read_prop(), sn622x_sdca_io_init(), and sn622x_restore_dmic_analog() check sn622x_sdca_disco_omits_mic(slave)? Currently only sn622x_dmic_apply_defaults() checks sn622x_sdca_disco_omits_mic(slave). On platforms where DisCo omits the mic function, sn622x_sdca_read_prop() still exposes SN622X_PORT_DMIC_CAPTURE, and sn622x_sdca_io_init() and sn622x_restore_dmic_analog() still read and write SN622X_REG_DMIC_FUN_STATUS_CTL on a non-existent SDCA function. [ ... ] > +/* PoC: clear DP0 sticky bits so bus alert handler can finish (DevNum as= sign). */ > +static int sn622x_clear_dp0_int(struct sdw_slave *slave) > +{ > + int status, status2, ret, count =3D 0; > + u8 clear, impl_int_mask; > + > + status =3D sdw_read_no_pm(slave, SDW_DP0_INT); > + if (status < 0) > + return status; > + > + do { > + clear =3D status & ~(SDW_DP0_INTERRUPTS | SDW_DP0_SDCA_CASCADE); > + > + if (status & SDW_DP0_INT_TEST_FAIL) > + clear |=3D SDW_DP0_INT_TEST_FAIL; > + > + if (status & SDW_DP0_INT_PORT_READY) { > + complete(&slave->port_ready[0]); > + clear |=3D SDW_DP0_INT_PORT_READY; > + } [Severity: Medium] Why does sn622x_clear_dp0_int() duplicate the SoundWire bus core's sdw_handle_dp0_interrupt()? The bus core already clears SDW_DP0_INT and completes slave->port_ready[0] in sdw_handle_slave_alerts() before invoking interrupt_callback, and SDW_DP0_SDCA_CASCADE clears once SDW_SCP_SDCA_INT1..4 are cleared. Clearing DP0 interrupt bits and signaling slave->port_ready[0] from the codec driver's interrupt_callback and clk_stop paths risks losing DP0 status notifications or causing spurious port_ready completions. [ ... ] > + snd_sdw_params_to_config(substream, params, &stream_config, &port_confi= g); > + stream_config.frame_rate =3D 48000; > + if (stream_config.bps > 16 && > + params_format(params) =3D=3D SNDRV_PCM_FORMAT_S16_LE) > + stream_config.bps =3D 16; [Severity: Low] Can stream_config.bps > 16 ever be true when params_format(params) is SNDRV_PCM_FORMAT_S16_LE? snd_sdw_params_to_config() sets stream_config.bps to snd_pcm_format_width(params_format(params)), which is already 16 for SNDRV_PCM_FORMAT_S16_LE. In addition, SN622X_SPK_CHR_VOL_PRIM_DEFAULT, SN622X_REG_DMIC_MFPU_BYPASS, SN622X_REG_DMIC_MFPU_ALGO_ENABLE, SN622X_SDCA_ENT_MFPU08, SN622X_ROUTE_AFTER_D3_US_MIN/MAX, SN622X_ROUTE_BEFORE_ACTIVE_US_MIN/MAX, SN622X_UAJ_DMIC_PPU11, and the pcm_rate parameter of sn622x_dmic_capture_prepare() (making sn622x->dmic_rate and sn622x->disable_irq write-only) are unused. > + port_config.num =3D port; > + > + ret =3D sdw_stream_add_slave(sn622x->slave, &stream_config, > + &port_config, 1, sdw_stream); > + > + if (ret) { > + dev_err(dai->dev, "%s: sdw_stream_add_slave port %d failed: %d\n", > + __func__, port, ret); > + goto out; > + } > + > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK && > + dai->id =3D=3D SN622X_DAI_SPEAKER) { > + sn622x->playback_active |=3D SN622X_PB_ACTIVE_SPK; > + ret =3D regmap_write(sn622x->regmap, SN622X_REG_RATE_SEL, 0x01); > + if (ret < 0) > + dev_warn(dai->dev, > + "sn622x: hw_params: speaker rate_sel failed (%d)\n", > + ret); > + sn622x_speaker_playback_prepare(dai->dev, sn622x); > + } else if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE && > + dai->id =3D=3D SN622X_DAI_DMIC) { > + sn622x->dmic_route_latched =3D false; > + sn622x->dmic_rate =3D params_rate(params); > + ret =3D regmap_write(sn622x->regmap, SN622X_REG_DMIC_CAP_RATE_SEL, > + 0x01); > + if (ret < 0) > + dev_warn(dai->dev, > + "sn622x: hw_params: dmic rate_sel failed (%d)\n", > + ret); > + sn622x_dmic_capture_prepare(dai->dev, sn622x, sn622x->dmic_rate, > + true); > + } > +out: > + if (got_pm) { > + pm_runtime_mark_last_busy(component->dev); > + pm_runtime_put_autosuspend(component->dev); > + } > + return ret; > +} [Severity: Medium] If regmap_write() fails here after sdw_stream_add_slave() succeeds, does sn622x_sdca_pcm_hw_params() leak the SoundWire stream runtime and leave SN622X_PB_ACTIVE_SPK set? When hw_params returns a negative error code, ASoC does not mark the DAI for hw_free rollback, so sdw_stream_remove_slave() is never called on stream teardown (leaving m_rt linked on bus->m_rt_list) and sn622x->playback_active remains stuck set. > + > +static int sn622x_sdca_pcm_hw_free(struct snd_pcm_substream *substream, > + struct snd_soc_dai *dai) > +{ > + struct snd_soc_component *component =3D dai->component; > + struct sn622x_sdca_priv *sn622x =3D snd_soc_component_get_drvdata(compo= nent); > + struct sdw_stream_runtime *sdw_stream =3D > + snd_soc_dai_get_dma_data(dai, substream); > + int port; > + bool got_pm =3D false; > + int ret; > + > + if (!sn622x->slave) > + return -EINVAL; > + > + port =3D sn622x_hw_params_port(dai, substream); > + if (port < 0) > + return port; > + > + ret =3D pm_runtime_resume_and_get(component->dev); > + if (ret < 0 && ret !=3D -EACCES) > + return ret; > + if (ret =3D=3D 0) > + got_pm =3D true; > + > + > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE && > + dai->id =3D=3D SN622X_DAI_DMIC) { > + sn622x->dmic_active =3D false; > + sn622x->dmic_route_latched =3D false; > + sn622x->dmic_recover_until =3D 0; > + cancel_delayed_work_sync(&sn622x->bus_recover_work); > + } > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK && > + dai->id =3D=3D SN622X_DAI_SPEAKER) { > + sn622x->playback_active &=3D ~SN622X_PB_ACTIVE_SPK; > + } > + > + sdw_stream_remove_slave(sn622x->slave, sdw_stream); [Severity: Medium] Does returning early when pm_runtime_resume_and_get() fails in sn622x_sdca_pcm_hw_free() skip sdw_stream_remove_slave() and work cancellation? sn622x_sdca_pcm_hw_free() performs no hardware register I/O, so aborting on a runtime resume failure leaks the slave stream runtime and leaves bus_recover_work and dmic_active / playback_active active after PCM close. [ ... ] > + pm_runtime_set_autosuspend_delay(dev, 3000); > + pm_runtime_use_autosuspend(dev); > + pm_runtime_mark_last_busy(dev); > + /* > + * Fresh probe: disable_depth is already 1. Only disable when a previous > + * instance left runtime_error set, then enable exactly once. > + */ > + if (dev->power.runtime_error) > + pm_runtime_disable(dev); > + pm_runtime_set_suspended(dev); > + pm_runtime_enable(dev); > + > + return 0; > +} [Severity: High] Does enabling runtime PM in RPM_SUSPENDED state during sn622x_sdca_init() cause pm_runtime_set_active() in sn622x_sdca_io_init() to always fail with -EAGAIN? __pm_runtime_set_status() rejects pm_runtime_set_active() with -EAGAIN when runtime PM is already enabled (disable_depth =3D=3D 0) and runtime_error = =3D=3D 0. When the slave attaches and sn622x_sdca_io_init() runs, pm_runtime_set_active(dev) fails, leaving dev->power.runtime_status at RPM_SUSPENDED while regcache_cache_only is false, so pm_runtime_put_autosuspend(dev) sees the device as already suspended and never invokes sn622x_sdca_dev_suspend(). In addition, if dev->power.runtime_error is set at probe when disable_depth is already 1, calling pm_runtime_disable(dev) increments disable_depth to 2 while pm_runtime_enable(dev) only decrements it to 1; sn622x_sdca_sdw_remove() only calls pm_runtime_disable() when first_hw_init is true (leaking the enable count if unbound before attach) and omits pm_runtime_dont_use_autosuspend(); sn622x_bus_recover_work() returns early when pm_runtime_resume_and_get() fails with -EINVAL before reaching sn622x_pm_recover(); and reading dev->power.runtime_error directly fails to compile when CONFIG_PM is disabled. > + > +static int sn622x_sdca_sdw_probe(struct sdw_slave *slave, > + const struct sdw_device_id *id) > +{ > + struct regmap *regmap; > + int ret; > + > + SN622X_DBG(&slave->dev, "sdw_probe: dev_num=3D%u status=3D%s\n", > + slave->dev_num, sn622x_status_str(slave->status)); > + > + /* > + * read_prop runs once at slave add; force again on driver bind so a > + * module reload picks up lane_control_support=3Dfalse without reboot. > + */ > + slave->prop.lane_control_support =3D false; > + > + regmap =3D devm_regmap_init_sdw_mbq_cfg(&slave->dev, slave, > + &sn622x_sdca_regmap, > + &sn622x_sdca_mbq_cfg); > + if (IS_ERR(regmap)) { > + dev_err(&slave->dev, > + "sn622x: devm_regmap_init_sdw_mbq_cfg failed (%ld)\n", > + PTR_ERR(regmap)); > + return PTR_ERR(regmap); > + } > + > + ret =3D sn622x_sdca_init(&slave->dev, regmap, slave); > + if (ret < 0) > + dev_err(&slave->dev, "sn622x: sn622x_sdca_init failed (%d)\n", ret); > + else { > + struct sn622x_sdca_priv *sn622x =3D dev_get_drvdata(&slave->dev); > + > + if (sn622x) > + sn622x_sdca_sdca_irq_mask_all(sn622x); > + SN622X_DBG(&slave->dev, "SoundWire probe finished OK\n"); > + } > + > + return ret; > +} [ ... ] > +static int sn622x_sdca_dev_system_suspend(struct device *dev) > +{ > + struct sn622x_sdca_priv *sn622x =3D dev_get_drvdata(dev); > + > + if (!sn622x->first_hw_init) > + return 0; > + > + SN622X_DBG(dev, "system suspend: mask SDCA IRQs\n"); > + mutex_lock(&sn622x->disable_irq_lock); > + sn622x->disable_irq =3D true; > + sn622x_sdca_sdca_irq_mask_all(sn622x); > + mutex_unlock(&sn622x->disable_irq_lock); > + > + return sn622x_sdca_dev_suspend(dev); > +} [Severity: High] Can sn622x_sdca_sdw_probe() and sn622x_sdca_dev_system_suspend() call sn622x_sdca_sdca_irq_mask_all() while the slave is unattached or the SoundWire bus is runtime-suspended? sn622x_sdca_sdca_irq_mask_all() issues four sdw_write_no_pm() transfers. In sn622x_sdca_sdw_probe(), the slave may still be SDW_SLAVE_UNATTACHED before update_status() runs. In sn622x_sdca_dev_system_suspend(), checking !sn622x->first_hw_init instead of !sn622x->hw_init means that if the codec and parent SoundWire controller have already runtime-suspended and stopped the clock, system suspend issues SoundWire transactions over a suspended/unattached bus. [Severity: Medium] Can sn622x->bus_recover_work run concurrently with or after sn622x_sdca_dev_system_suspend()? Neither sn622x_sdca_dev_system_suspend() nor sn622x_sdca_dev_suspend() cancels bus_recover_work. Because sn622x_bus_recover_work() continues when pm_runtime_resume_and_get(dev) returns -EACCES (which the PM core returns while runtime PM is disabled for system sleep), a pending work item can run during system suspend and call sn622x_sdca_io_init(), clearing disable_irq, disabling regcache_cache_only, and issuing bus transfers. > + > +static int sn622x_sdca_dev_resume(struct device *dev) > +{ > + struct sdw_slave *slave =3D dev_to_sdw_dev(dev); > + struct sn622x_sdca_priv *sn622x =3D dev_get_drvdata(dev); > + int ret; > + > + if (!sn622x->first_hw_init) > + return 0; > + > + SN622X_DBG(dev, "resume: unattach_request=3D%u status=3D%s\n", > + slave->unattach_request, sn622x_status_str(slave->status)); > + > + if (slave->unattach_request) { > + ret =3D sdw_slave_wait_for_init(slave, SN622X_PROBE_TIMEOUT_MS); > + if (ret) > + dev_dbg(dev, "sn622x: resume: init wait failed (%d)\n", ret); > + } > + > + mutex_lock(&sn622x->disable_irq_lock); > + sn622x->disable_irq =3D false; > + mutex_unlock(&sn622x->disable_irq_lock); > + > + slave->unattach_request =3D 0; > + if (!sn622x_slave_attached(slave)) > + return 0; > + > + /* Resume: enable regmap I/O; avoid regcache_sync (stale cache vs live = device). */ > + regcache_cache_only(sn622x->regmap, false); > + > + return 0; > +} [Severity: High] Does sn622x_sdca_dev_resume() leave sn622x->regmap stuck in cache-only mode when the slave resumes for a SoundWire alert or when sdw_slave_wait_for_init() fails? When a runtime-suspended slave raises an alert, sdw_handle_slave_alerts() sets slave->status =3D SDW_SLAVE_ALERT before calling pm_runtime_get_sync(&slave->dev). Because sn622x_slave_attached() only checks slave->status =3D=3D SDW_SLAVE_ATTACHED, sn622x_sdca_dev_resume() returns 0 without calling regcache_cache_only(sn622x->regmap, false), so the device transitions to RPM_ACTIVE while regmap stays cache-only (and when the slave returns to SDW_SLAVE_ATTACHED, sn622x_sdca_update_status() sees hw_init =3D=3D true and skips io_init). [Severity: Medium] Should sn622x_sdca_dev_resume() propagate errors when sdw_slave_wait_for_init() fails or the slave is still unattached instead of clearing slave->unattach_request and returning 0? Returning 0 when initialization has not completed marks the device RPM_ACTIVE with slave->unattach_request cleared and regcache_cache_only still set to true. Also, when the slave re-attaches within SN622X_ATTACH_DEBOUNCE_MS, sn622x_sdca_update_status() defers sn622x_sdca_io_init() to bus_recover_work and returns 0, which causes the SoundWire bus core to complete slave->initialization_complete and wake sdw_slave_wait_for_init() before io_init has run. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201025636.6050= 6-1-qianghua.wang@senarytech.com?part=3D1