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=1796027845; b=Wb5RQhG0eXyQFYPURD41/o63FGj3R0Sc+Na1m1J+EZ79RMzmeY0V+LEG4G+2gJQRA2bx 7OoNfoFSZd5npXmIxtrv04laUf0v+M7vuetf42NID3lRlZHe1K3RdwdOzUDvvPuL+zajl EQqOaeIDKd332UC5JkySg/+DeHNkveoXvPs4QRqksaP9QSd+SnR9uaopTrK6muXLQ2GSL M/MICZs+5vNNbBgaKGe6cLSIXhPZ/4aYWl3JWC4mmXvDtWztWfQv8SnatjwEUfudH39Wz yywzkMO/1kqWgWxMGs0JyMcj/mi61iBplkhWodtQpYx38z2MXX25IWwe4T9ijA2BuCA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796027845; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=OszVJhY2o6CUIv4Mp3HHgCjsL07V3bxSmcYSWTwGOHc=; b=vgV1xYu/FKsalXwXteneOFz7UHOBvEdsn67oZOIJL6/SE82tgIVl//thqQyNdQShrBRO 5OnHSjMou5B3doQBxQuQwYsofgNQZIiPxb/GhfSRjajRa95t20XEtT1o8Pv4MTSFN3K3F NrSQP48PyupQ3MdwEmDtjZwvz3vzjORAYk+zYMRtvtT0fAwuOZ84xwoYAwisSZ1vKTrHT OUUmkhqIacTY2izVxRo0Gusc8Ju1dh0l8426z0p3Q2wMJh2NAJSmwAysP0e1hRCj8Dn/C m3RZ8CDLRiXrT3YVR27sCPa9AoGGUG4y4tK4kUklrZiPNgejKFAYvu+PttdzcroXyng== 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=PrRSvItJ; 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 834F9606A31C for ; Mon, 30 Nov 2026 08:37:25 +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=PrRSvItJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3B2F1F00897; Mon, 30 Nov 2026 08:37:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796027844; bh=OszVJhY2o6CUIv4Mp3HHgCjsL07V3bxSmcYSWTwGOHc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=PrRSvItJVN7fmrJ7VBO8lGhBZAF7eG/AwspcwKKSRSNydcU4sueKZ41ecru4liBSN 37kYAlRGIO6q6QXK8OyhPwY0xbXTPDgsxYvnz0rLwFCzog9krebhDw0Bi4QFt4dvb8 qJABmdvhEaCrlHsJ+ux1NWAXsS/FlHvf/fRtYC7fjRCCsFGzPhnVKtgZ8/6x9lw8+N gJhlalU+w2xWfGvuKH483fzVkSVdJ8eadVY33yGZuwLkeoaaPnrX2dcS7IbEPnnUEv zk20gTOFlJJQMLipd9j8uPN+eS1tvdIBbexjNStkRYhkuG0cWbN/R52OXXmBzunfxE dC54I34or8JUw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/1] 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: <20261130081210.40316-2-qianghua.wang@senarytech.com> References: <20261130081210.40316-1-qianghua.wang@senarytech.com> <20261130081210.40316-2-qianghua.wang@senarytech.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 08:37:24 +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 21 potential issues to consider: - [High] ASoC: sn622x: pm_runtime_set_active() fails in sn622x_sdca_io_init() - [High] ASoC: sn622x: uninitialized stream_config.type in sn622x_sdca_pcm_hw_params() - [High] ASoC: sn622x: sn622x_dmic_capture_prepare() mutes active duplex playback - [High] ASoC: sn622x: unsafe dev_num mutation and init wait in prepare_paged_access() - [High] ASoC: sn622x: raw register mixer controls overflow 32-bit long and write HW - [High] ASoC: sn622x: uncancelled work and unguarded bus writes on probe and suspend - [High] ASoC: sdw_utils: sn624x DMIC route in asoc_sdw_senary_dmic_rtd_init() fails - [High] ASoC: sn622x-sdca: sn622x_settle_work() re-queues dmic_on_work after cancel - [High] ASoC: sn622x-sdca: sn622x_dmic_capture_prepare() mutes active duplex speaker - [Medium] ASoC: sn622x: unbalanced PM and mutex teardown in sn622x_sdca_sdw_remove() - [Medium] ASoC: sn622x: unreachable DMIC recovery block in sn622x_sdca_io_init() - [Medium] ASoC: sn622x: sn622x_sdca_pcm_hw_free() powers on and unmutes idle speaker - [Medium] ASoC: sn622x: sn622x_clear_dp0_int() races with SoundWire core DP0 handling - [Medium] ASoC: sn622x: DMIC DAI advertises 4 channels while hardware only enables 2 - [Medium] ASoC: sn622x-sdca: sn622x_sdca_clk_stop() requests D0 before clock stop - [Medium] ASoC: sn622x-sdca: sn622x_sdca_sdw_probe() writes IRQ masks while unattached - [Medium] ASoC: sn622x-sdca: sn622x_hw_params_speaker_playback() defeats anti-pop ramp - [Medium] ASoC: sn622x-sdca: blocking poll and debug reads in sn622x_sdca_trigger() - [Medium] ASoC: sn622x-sdca: sn622x_sdca_trigger() leaves dmic_on_work active on stop - [Low] ASoC: sn622x: unreachable cap_on sequence and dead S16_LE bps check - [Low] ASoC: sn622x-sdca: dummy reg 0x0 default in sn622x_sdca_reg_defaults[] -- commit d8fa0feecd5024e8cc4e4a5b319a3435b8d976b0 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 sdw_utils integration and Intel Panther Lake and Nova Lake ACPI match table entries. > diff --git a/sound/soc/codecs/sn622x-sdca-sdw.c b/sound/soc/codecs/sn622x= -sdca-sdw.c > new file mode 100644 > index 0000000000000..0fcf4845e1335 > --- /dev/null > +++ b/sound/soc/codecs/sn622x-sdca-sdw.c [ ... ] > +/* > + * Paged SCP needs non-zero dev_num. Never wait on initialization_comple= te from > + * update_status -> io_init -> uaj_apply (that completion is signaled on= ly after > + * update_status returns =E2=80=94 would deadlock). Use wait_sd_init=3Df= alse there. > + * @timeout_ms: total poll budget; SN622X_INIT_WAIT_MS for resume; > + * SN622X_PROBE_PAGED_MS or SN622X_PAGED_QUICK_MS for probe / diag. > + */ > +static int sn622x_sdw_prepare_paged_access(struct device *dev, struct sd= w_slave *slave, > + bool wait_sd_init, unsigned int timeout_ms) > +{ > + unsigned long deadline =3D jiffies + msecs_to_jiffies(timeout_ms); > + > + if (!slave) > + return -EINVAL; > + > + /* Fail fast when SoftAmp is off the bus =E2=80=94 do not wait 30s. */ > + if (slave->status =3D=3D SDW_SLAVE_UNATTACHED) > + return -ENODEV; > + > + if (slave->dev_num_sticky && !slave->dev_num) { > + slave->dev_num =3D slave->dev_num_sticky; > + SN622X_DBG(dev, > + "sync dev_num from dev_num_sticky=3D%u for paged SCP\n", > + slave->dev_num_sticky); > + } > + > + for (;;) { > + struct sn622x_sdca_priv *sn622x =3D dev_get_drvdata(&slave->dev); > + > + if (slave->status =3D=3D SDW_SLAVE_UNATTACHED) > + return -ENODEV; > + > + if (slave->dev_num) { > + if (sn622x) > + sn622x->last_dev_num =3D slave->dev_num; > + return 0; > + } > + > + /* > + * Do not spin while bus is servicing ALERT/DevID: codec IRQ handler > + * must not hammer SDCA/DP0 in that window (see interrupt_callback). > + */ > + if (slave->status =3D=3D SDW_SLAVE_ALERT) { > + if (sn622x && sn622x->last_dev_num) { > + slave->dev_num =3D sn622x->last_dev_num; > + SN622X_DBG(dev, > + "restore dev_num=3D%u after ALERT for paged SCP\n", > + sn622x->last_dev_num); > + return 0; > + } > + return -EAGAIN; > + } > + > + if (slave->dev_num_sticky) { > + slave->dev_num =3D slave->dev_num_sticky; > + SN622X_DBG(dev, > + "sync dev_num from dev_num_sticky=3D%u for paged SCP\n", > + slave->dev_num_sticky); > + return 0; > + } > + if (!time_before(jiffies, deadline)) > + break; > + if (wait_sd_init) > + wait_for_completion_timeout(&slave->initialization_complete, > + msecs_to_jiffies(25)); > + wait_for_completion_timeout(&slave->enumeration_complete, > + msecs_to_jiffies(25)); > + usleep_range(500, 1500); > + } [Severity: High] Can sn622x_sdw_prepare_paged_access() corrupt device-0 enumeration by overwriting slave->dev_num, and stall the SoundWire bus thread for 30 seconds when called from sn622x_sdca_io_init()? In sdw_assign_device_num(), the SoundWire core temporarily sets slave->dev_num =3D 0 while slave->dev_num_sticky is non-zero so that it can write SDW_SCP_DEVNUMBER to device 0 before restoring slave->dev_num. Mutating slave->dev_num here without bus_lock or programming hardware races with sdw_assign_device_num() and directs paged SCP transfers to an unprogrammed device address. In addition, despite the comment above warning never to wait on initialization_complete from update_status -> io_init, both sn622x_pwr_request_d0() and sn622x_sdca_io_init() pass wait_sd_init =3D true with SN622X_INIT_WAIT_MS (30000 ms) while running inside update_status before sdw_handle_slave_status() can signal initialization_complete. [ ... ] > +static void sn622x_hw_params_speaker_playback(struct snd_soc_dai *dai, > + struct snd_pcm_substream *substream, > + struct sn622x_sdca_priv *sn622x) > +{ > + struct device *dev =3D dai->dev; > + unsigned int v, vlo, vhi; > + int r, rlo, rhi; > + bool paged_ok; > + > + if (!sn622x_codec_diag || !sn622x->regmap) > + return; [ ... ] > + { > + const struct reg_sequence mute_vol[] =3D { > + REG_SEQ0(SN622X_REG_MUTE, 0), > + REG_SEQ0(SN622X_REG_RIGHT_MUTE, 0), > + REG_SEQ0(SN622X_REG_VOL_SECOND, > + SN622X_SPK_VOL_SECOND_DEFAULT), > + REG_SEQ0(SN622X_REG_VOL_PRIM, > + SN622X_SPK_VOL_PRIM_DEFAULT), > + REG_SEQ0(SN622X_REG_CHR_VOL_SECOND, > + SN622X_SPK_CHR_VOL_SECOND_DEFAULT), > + REG_SEQ0(SN622X_REG_CHR_VOL_PRIM, > + SN622X_SPK_CHR_VOL_PRIM_DEFAULT), > + }; > + > + r =3D regmap_multi_reg_write_bypassed(sn622x->regmap, mute_vol, > + ARRAY_SIZE(mute_vol)); [Severity: Medium] Does writing SN622X_REG_MUTE =3D 0 here in sn622x_hw_params_speaker_playbac= k() cause sn622x_speaker_playback_prepare() to skip its spk_ramp sequence? Because sn622x_codec_diag defaults to true, sn622x_sdca_pcm_hw_params() runs this block without holding sn622x->path_lock and clears SN622X_REG_MUTE before sdw_stream_add_slave(), charge-pump setup, or the D0 transition. When sn622x_speaker_playback_prepare() subsequently checks whether SN622X_REG_MUTE is non-zero before running spk_ramp, it always sees 0 and skips the ramp. [ ... ] > +static void sn622x_dmic_capture_prepare(struct device *dev, > + struct sn622x_sdca_priv *sn622x, > + unsigned int pcm_rate, > + bool bringup) > +{ [ ... ] > + if (!sn622x->playback_active) { > + static const struct reg_sequence spk_mute_on[] =3D { > + REG_SEQ0(SN622X_REG_MUTE, SN622X_MUTE_ON), > + REG_SEQ0(SN622X_REG_RIGHT_MUTE, SN622X_MUTE_ON), > + }; > + unsigned int spk_pwr =3D 0xff; > + > + regmap_multi_reg_write_bypassed(sn622x->regmap, spk_mute_on, > + ARRAY_SIZE(spk_mute_on)); > + if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_PWR_STATE, > + &spk_pwr) =3D=3D 0 && > + (spk_pwr & 0xffu) !=3D SN622X_PWR_D3) > + sn622x_speaker_pwr_request_d3(dev, sn622x); > + sn622x->spk_parked_for_dmic =3D true; > + } else { > + dev_info(dev, > + "sn622x: dmic prepare: duplex =E2=80=94 leave Speakers, SoftMic 48k/= 16\n"); > + } [ ... ] > + { > + bool muted_spk =3D false; > + static const struct reg_sequence spk_mute_on[] =3D { > + REG_SEQ0(SN622X_REG_MUTE, SN622X_MUTE_ON), > + REG_SEQ0(SN622X_REG_RIGHT_MUTE, SN622X_MUTE_ON), > + }; > + > + if (sn622x->playback_active && > + sn622x_slave_attached(sn622x->slave)) { > + unsigned int spk_mute =3D 0; > + > + if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_MUTE, > + &spk_mute) =3D=3D 0 && > + (spk_mute & 0xffu) =3D=3D 0) { > + regmap_multi_reg_write_bypassed(sn622x->regmap, > + spk_mute_on, > + ARRAY_SIZE(spk_mute_on)); > + muted_spk =3D true; > + } > + } > + > + r =3D sn622x_dmic_cap_pwr_request_d0(dev, sn622x); > + if (r < 0) > + dev_warn(dev, > + "sn622x: dmic prepare: PWR D0 failed (%d)\n", > + r); > + > + /* Keep Speakers muted while SoftMic is capturing if Speakers PCM open= */ > + (void)muted_spk; > + } [Severity: High] Does starting DMIC capture while speaker playback is active leave the speakers muted for the rest of the playback stream? When sn622x->playback_active is non-zero, the first check above leaves sn622x->spk_parked_for_dmic false for duplex operation, but this block then writes spk_mute_on to mute both speaker channels around sn622x_dmic_cap_pwr_request_d0() and discards muted_spk without unmuting them. Because spk_parked_for_dmic is false, sn622x_sdca_pcm_hw_free() does not restore the speakers when capture closes either. [ ... ] > + if (!bringup || sn622x->playback_active || sn622x->dmic_analog_restored= ) { [ ... ] > + goto out_unlock; > + } > + > + usleep_range(SN622X_ROUTE_BEFORE_ACTIVE_US_MIN, > + SN622X_ROUTE_BEFORE_ACTIVE_US_MAX); > + > + if (!sn622x_slave_attached(sn622x->slave)) > + goto out_unlock; > + > + r =3D regmap_multi_reg_write_bypassed(sn622x->regmap, cap_on, > + ARRAY_SIZE(cap_on)); [Severity: Low] Is the cap_on[] sequence after this if block reachable? All callers of sn622x_dmic_capture_prepare() pass bringup =3D false, and even if bringup were true, sn622x_restore_dmic_analog() earlier in this function sets sn622x->dmic_analog_restored =3D true, so this branch always jumps to out_unlock. [ ... ] > +static const struct reg_default sn622x_sdca_reg_defaults[] =3D { > + {} > +}; > + > +static const struct regmap_config sn622x_sdca_regmap =3D { > + .reg_bits =3D 32, > + .val_bits =3D 8, > + .readable_reg =3D sn622x_sdca_readable_register, > + .volatile_reg =3D sn622x_sdca_volatile_register, > + .max_register =3D 0xffffffff, > + .reg_defaults =3D sn622x_sdca_reg_defaults, > + .num_reg_defaults =3D ARRAY_SIZE(sn622x_sdca_reg_defaults), [Severity: Low] Does sn622x_sdca_reg_defaults[] populate a dummy default of 0 for register 0x0 (SDW_DP0_INT) in both regmap caches? ARRAY_SIZE() of { {} } is 1; omitting .reg_defaults and .num_reg_defaults starts the Maple cache empty (and mbq_regmap appears unused). [ ... ] > +static int sn622x_dmic_init_table(struct device *dev, struct sn622x_sdca= _priv *sn622x) > +{ [ ... ] > + for (size_t i =3D 0; i < ARRAY_SIZE(dmic_init_table); i++) { > + ret =3D regmap_read_bypassed(sn622x->regmap, dmic_init_table[i].reg, > + &v); > + dev_dbg(dev, "sn622x: dmic init[0x%x]=3D0x%x err=3D%d\n", > + dmic_init_table[i].reg, v, ret); > + } > + > + return 0; > +} > + > +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; > + } > + /* > + * Reattach while Speakers or SoftMic PCM is open: do not touch the > + * bus. Reading FUN / ACK here UNATTACHes SoftAmp again, settle calls > + * io_init, and the GNOME test tone never stays up. > + */ > + if (sn622x->first_hw_init && > + (sn622x->playback_active || sn622x->dmic_active)) { > + dev_info(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; > + } > + /* > + * SoftMic stream already open (HP insert flaps SoftAmp mid-record). > + * Skip Speakers PDE (avoids UNATTACH loop) but must re-enable paging > + * and ACK SoftMic FUN =E2=80=94 otherwise Cap stays quiet until SoftMi= c is > + * stopped and reopened. SoftMic prepare (settle) restores analog/CHEN. > + */ > + if (sn622x->dmic_active) { > + dev_info(dev, > + "sn622x: io_init: SoftMic active =E2=80=94 FUN ACK for recover\n"); [Severity: Medium] Is the if (sn622x->dmic_active) recovery block here reachable? sn622x->dmic_active is only set in sn622x_sdca_trigger() after the initial sn622x_sdca_io_init() has already set sn622x->first_hw_init =3D true. The preceding check for (sn622x->first_hw_init && (sn622x->playback_active || sn622x->dmic_active)) therefore always returns early when dmic_active is true, skipping regcache_cache_only(..., false), IRQ masking, and the DMIC FUN status ACK on reattach. [ ... ] > + pm_runtime_set_active(dev); > + > + sn622x->hw_init =3D true; > + sn622x->first_hw_init =3D true; > + > + pm_runtime_put_autosuspend(dev); [Severity: High] Does pm_runtime_set_active(dev) always fail with -EAGAIN here in sn622x_sdca_io_init()? sn622x_sdca_init() already called pm_runtime_set_suspended(dev) and pm_runtime_enable(dev) at probe time, so dev->power.disable_depth is 0 when sn622x_sdca_io_init() runs. __pm_runtime_set_status() rejects status changes with -EAGAIN when runtime PM is enabled and runtime_error is 0, leaving the device in RPM_SUSPENDED while its regmaps have exited cache-only mode. Also, in sn622x_sdca_init(), calling pm_runtime_disable(dev) when dev->power.runtime_error is set on a freshly probed device (where disable_depth is already 1) increments disable_depth to 2, so the single pm_runtime_enable(dev) call leaves runtime PM disabled. [ ... ] > +static void sn622x_settle_work(struct work_struct *work) > +{ > + struct sn622x_sdca_priv *sn622x =3D > + container_of(work, struct sn622x_sdca_priv, settle_work.work); > + struct device *dev; > + > + if (!sn622x->slave || !sn622x_slave_attached(sn622x->slave)) > + return; > + > + dev =3D &sn622x->slave->dev; > + sn622x_pm_recover(dev); > + if (!sn622x->hw_init) { > + dev_info(dev, "sn622x: settle: io_init after bus flap\n"); > + sn622x_sdca_io_init(dev, sn622x->slave); > + } [ ... ] > + if (sn622x->dmic_active && !sn622x->playback_active && > + sn622x_slave_attached(sn622x->slave)) { > + dev_info(dev, "sn622x: settle: SoftMic still open =E2=80=94 re-latch\n= "); > + sn622x_dmic_capture_prepare(dev, sn622x, sn622x->dmic_rate, > + false); > + mod_delayed_work(system_wq, &sn622x->dmic_on_work, > + msecs_to_jiffies(150)); > + } > + /* > + * Do not re-run speaker prepare while Speakers PCM stays open. > + * That re-latch UNATTACHes SoftAmp, settle runs again, and the UI > + * test tone never stays on the bus. > + */ > +} [Severity: High] Can sn622x_settle_work() re-arm dmic_on_work after sn622x_sdca_sdw_remove() or sn622x_sdca_pcm_hw_free() has already cancelled it, leading to a use-after-free on driver removal? kworker CPU0 sn622x_settle_work() if (sn622x->dmic_active && ...) sn622x_dmic_capture_prepare() sn622x_sdca_sdw_remove() sn622x->dmic_active =3D false; cancel_delayed_work_sync(&dmic_on_w= ork) mod_delayed_work(..., &dmic_on_work, ...) cancel_delayed_work_sync(&settle_wo= rk) /* devm frees sn622x */ sn622x_dmic_on_work() sn622x->slave <-- use-after-free Cancelling settle_work before dmic_on_work in sn622x_sdca_sdw_remove() and updating/checking dmic_active under sn622x->path_lock before queueing dmic_on_work would avoid re-arming dmic_on_work after teardown. [ ... ] > +/* 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] Does sn622x_clear_dp0_int() race with the SoundWire bus core's DP0 interrupt handling? sdw_handle_dp0_interrupt() in drivers/soundwire/bus.c owns SDW_DP0_INT and slave->port_ready[0], whereas SDW_DP0_SDCA_CASCADE clears when the codec's SDW_SCP_SDCA_INT1..4 bits are cleared. Clearing SDW_DP0_INT and calling complete(&slave->port_ready[0]) from sn622x_sdca_interrupt_callback= () and sn622x_sdca_clk_stop() can discard DP0 status bits or complete port_ready[0] prematurely. [ ... ] > +static int sn622x_sdca_clk_stop(struct sdw_slave *slave, > + enum sdw_clk_stop_mode mode, > + enum sdw_clk_stop_type type) > +{ > + struct sn622x_sdca_priv *sn622x =3D dev_get_drvdata(&slave->dev); > + > + if (!sn622x) > + return 0; > + > + switch (type) { > + case SDW_CLK_PRE_PREPARE: > + sn622x_pwr_request_d0(&slave->dev, sn622x); > + mutex_lock(&sn622x->disable_irq_lock); > + sn622x_sdca_flush_pending_irqs(sn622x, &slave->dev); > + mutex_unlock(&sn622x->disable_irq_lock); > + dev_info(&slave->dev, "sn622x: clk_stop PRE_PREPARE done\n"); > + break; [Severity: Medium] Should sn622x_sdca_clk_stop() request D0 on the speaker power domain during SDW_CLK_PRE_PREPARE? sdw_bus_prep_clk_stop() runs right before stopping the SoundWire clock, and sn622x_pwr_request_d0() unconditionally writes 0 to SN622X_REG_PWR_STATE_WRITE without checking if the speaker PDE is already in D0 (which the comments in sn622x_speaker_pwr_request_d0() and sn622x_hw_params_speaker_playback() note resets FUN status to 0x63 and can drop the slave off the bus). [ ... ] > +static int sn622x_sdca_pcm_hw_params(struct snd_pcm_substream *substream, > + struct snd_pcm_hw_params *params, > + 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_config stream_config; > + struct sdw_port_config port_config; [ ... ] > + stream_config.frame_rate =3D 48000; > + stream_config.ch_count =3D ch; > + stream_config.bps =3D snd_pcm_format_width(params_format(params)); > + if (stream_config.bps > 16 && > + params_format(params) =3D=3D SNDRV_PCM_FORMAT_S16_LE) > + stream_config.bps =3D 16; > + stream_config.direction =3D direction; > + port_config.ch_mask =3D GENMASK(ch - 1, 0); > + port_config.num =3D port; [ ... ] > + ret =3D sdw_stream_add_slave(sn622x->slave, &stream_config, > + &port_config, 1, sdw_stream); [Severity: High] Is stream_config.type left uninitialized on the stack before sdw_stream_add_slave()? sdw_config_stream() copies stream_config->type into stream->type. If stack garbage equals SDW_STREAM_BPT (2), sdw_slave_port_config() rejects the port configuration with -EINVAL and sdw_master_rt_free() decrements bus->bpt_stream_refcount without a matching increment. Zero-initializing stream_config (e.g. struct sdw_stream_config stream_config =3D {};) ensures SDW_STREAM_PCM. [Severity: Low] Also, can (stream_config.bps > 16 && params_format(params) =3D=3D SNDRV_PCM_FORMAT_S16_LE) ever be true when stream_config.bps comes from snd_pcm_format_width(params_format(params))? [ ... ] > +static int sn622x_sdca_pcm_hw_free(struct snd_pcm_substream *substream, > + struct snd_soc_dai *dai) > +{ [ ... ] > + /* > + * SoftMic parked Speakers in D3 =E2=80=94 restore Speakers (D0 + charge > + * pump + CHEN). Skip if SoftMic never parked Speakers (e.g. refused > + * while Speakers were already open). > + */ > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE && > + dai->id =3D=3D SN622X_DAI_DMIC && > + sn622x->spk_parked_for_dmic && > + sn622x_slave_attached(sn622x->slave)) { > + sn622x->spk_parked_for_dmic =3D false; > + sn622x_speaker_playback_prepare(dai->dev, sn622x); > + } [Severity: Medium] Does closing a solo DMIC capture stream power up and unmute the speaker path even when no playback stream is active? sn622x->spk_parked_for_dmic is only set when capture starts while sn622x->playback_active is 0. Calling sn622x_speaker_playback_prepare() unconditionally here transitions the speaker PDE to D0, enables the charge pump (0x2086 =3D 0x0b), unmutes both speaker channels, and sets SN622X_REG_CH_ENABLE_B =3D 0x03 while playback is idle. [ ... ] > +static int sn622x_sdca_trigger(struct snd_pcm_substream *substream, int = cmd, > + 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); > + bool got_pm =3D false; > + int ret; > + > + /* > + * hw_params already latched Speakers and queued spk_chen_work. > + * Writing CHEN again from TRIGGER_START, as the port is enabled, > + * flaps SoftAmp. SoftMic still retries PDE after the port is moving. > + */ > + if (cmd !=3D SNDRV_PCM_TRIGGER_START && > + cmd !=3D SNDRV_PCM_TRIGGER_RESUME && > + cmd !=3D SNDRV_PCM_TRIGGER_PAUSE_RELEASE) > + return 0; > + > + 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_rate =3D substream->runtime->rate; > + sn622x->dmic_active =3D true; > + sn622x_dmic_capture_prepare(dai->dev, sn622x, sn622x->dmic_rate, > + false); > + schedule_delayed_work(&sn622x->dmic_on_work, > + msecs_to_jiffies(200)); > + } [Severity: Medium] When SNDRV_PCM_TRIGGER_STOP, SNDRV_PCM_TRIGGER_SUSPEND, or SNDRV_PCM_TRIGGER_PAUSE_PUSH runs on the DMIC DAI before hw_free, doesn't returning early leave sn622x->dmic_active set and dmic_on_work re-arming itself every 150 ms while SoundWire port 3 is stopped? [Severity: Medium] Also, does calling sn622x_dmic_capture_prepare() synchronously from sn622x_sdca_trigger() block the PCM trigger callback for 12-30+ ms? sn622x_dmic_cap_pwr_request_d0() polls 5 times with usleep_range(2000, 3000) for a D0 transition that comments note only completes after port 3 is transporting (handled by dmic_on_work), and sn622x_dmic_init_table() perfor= ms 20 unconditional paged register readbacks over SoundWire just for dev_dbg(). [ ... ] > +static struct snd_soc_dai_driver sn622x_sdca_dai[] =3D { > + { > + .name =3D "sn622x-sdca-aif", > + .id =3D SN622X_DAI_SPEAKER, > + .playback =3D { > + .stream_name =3D "Speaker Playback", > + .channels_min =3D 1, > + .channels_max =3D 2, > + .rates =3D SN622X_STEREO_RATES, > + .formats =3D SN622X_FORMATS, > + }, > + .ops =3D &sn622x_sdca_ops, > + }, > + { > + .name =3D "sn622x-sdca-aif2", > + .id =3D SN622X_DAI_DMIC, > + .capture =3D { > + .stream_name =3D "DMic Capture", > + .channels_min =3D 1, > + .channels_max =3D 4, > + .rates =3D SN622X_STEREO_RATES, > + .formats =3D SN622X_FORMATS, > + }, > + .ops =3D &sn622x_sdca_ops, > + }, > +}; [Severity: Medium] Should sn622x-sdca-aif2 advertise .channels_max =3D 2 instead of 4? sn622x_dmic_capture_prepare() only enables two channels in SN622X_REG_DMIC_CAP_CH_ENABLE_B (0x03) and only configures mute and volume for two channels. [ ... ] > +static int sn622x_vendor_reg_cache_info(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_info *uinfo) > +{ > + uinfo->type =3D SNDRV_CTL_ELEM_TYPE_INTEGER; > + uinfo->count =3D 1; > + uinfo->value.integer.min =3D 0; > + uinfo->value.integer.max =3D 0xffffffff; > + return 0; > +} [ ... ] > +static int sn622x_vendor_reg_addr_info(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_info *uinfo) > +{ > + uinfo->type =3D SNDRV_CTL_ELEM_TYPE_INTEGER; > + uinfo->count =3D 3; > + uinfo->value.integer.min =3D 0; > + uinfo->value.integer.max =3D 0xffffffff; > + return 0; > +} [ ... ] > +static int sn622x_vendor_reg_addr_get(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + struct snd_soc_component *component =3D snd_kcontrol_chip(kcontrol); > + struct sn622x_sdca_priv *sn622x =3D snd_soc_component_get_drvdata(compo= nent); > + u32 addr =3D (u32)ucontrol->value.integer.value[0]; > + > + if (!component || !sn622x) > + return -ENODEV; > + > + if (!addr) > + addr =3D sn622x->vendor_reg_addr; > + > + /* > + * No SCP access here: amixer cset always snd_ctl_elem_read() before wr= ite. > + * A failing bus read in .get() makes cset abort with "Cannot read the = given > + * element". Hardware read/write is done only in .put (cset). > + */ > + ucontrol->value.integer.value[0] =3D addr; > + ucontrol->value.integer.value[1] =3D SN622X_VENDOR_REG_RW_READ; > + ucontrol->value.integer.value[2] =3D 0; > + return 0; > +} [ ... ] > +static const struct snd_kcontrol_new sn622x_sdca_controls[] =3D { > + { > + .iface =3D SNDRV_CTL_ELEM_IFACE_MIXER, > + .name =3D "Vendor Reg Addr", > + .info =3D sn622x_vendor_reg_cache_info, > + .get =3D sn622x_vendor_reg_cache_get, > + .put =3D sn622x_vendor_reg_cache_put, > + }, > + { > + .iface =3D SNDRV_CTL_ELEM_IFACE_MIXER, > + .name =3D "Vendor Reg Address", > + .access =3D SNDRV_CTL_ELEM_ACCESS_READWRITE, > + .info =3D sn622x_vendor_reg_addr_info, > + .get =3D sn622x_vendor_reg_addr_get, > + .put =3D sn622x_vendor_reg_addr_put, > + }, > + { > + .iface =3D SNDRV_CTL_ELEM_IFACE_MIXER, > + .name =3D "Vendor Reg Address write 1", > + .access =3D SNDRV_CTL_ELEM_ACCESS_READWRITE, > + .info =3D sn622x_vendor_reg_cache_info, > + .get =3D sn622x_vendor_reg_cache_get, > + .put =3D sn622x_vendor_reg_write1_put, > + }, > +}; [Severity: High] Should arbitrary register read/write debug access be handled through regmap debugfs rather than standard ALSA mixer controls? Exposing these as mixer controls causes several problems: - "Vendor Reg Address write 1" returns sn622x->vendor_reg_addr (initialized to SN622X_REG_PWR_STATE =3D 0x40400188) from .get and writes 0x01 to the passed address in .put, so a standard alsactl store/restore writes 0x01 to SN622X_REG_PWR_STATE_WRITE. - uinfo->value.integer.max is a signed long (and s32 for 32-bit compat ioctls), so 0xffffffff overflows to -1 on 32-bit kernels and compat ioctls (max < min), causing control validation to reject all writes. - sn622x_vendor_reg_addr_get() reads ucontrol->value.integer.value[0] from the caller's output buffer before falling back to sn622x->vendor_reg_addr. - The .get and .put callbacks dereference component in snd_soc_component_get_drvdata(component) before checking if (!component), and the .put callbacks return 0 instead of 1 when changing sn622x->vendor_reg_addr. [ ... ] > +int sn622x_sdca_init(struct device *dev, struct regmap *regmap, > + struct regmap *mbq_regmap, struct sdw_slave *slave) > +{ [ ... ] > + mutex_init(&sn622x->disable_irq_lock); > + mutex_init(&sn622x->path_lock); > + INIT_DELAYED_WORK(&sn622x->dmic_on_work, sn622x_dmic_on_work); > + INIT_DELAYED_WORK(&sn622x->spk_chen_work, sn622x_spk_chen_work); > + INIT_DELAYED_WORK(&sn622x->settle_work, sn622x_settle_work); > + > + regcache_cache_only(sn622x->regmap, true); > + regcache_cache_only(sn622x->mbq_regmap, true); > + > + ret =3D devm_snd_soc_register_component(dev, > + &soc_sdca_dev_sn622x, sn622x_sdca_dai, > + ARRAY_SIZE(sn622x_sdca_dai)); > + if (ret < 0) > + return ret; > + > + 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); > + > + SN622X_TRC(dev, "snd_soc_register_component OK (DAI sn622x-sdca-aif)\n"= ); > + return 0; > +} > + > +static int sn622x_sdca_sdw_probe(struct sdw_slave *slave, > + const struct sdw_device_id *id) > +{ [ ... ] > + ret =3D sn622x_sdca_init(&slave->dev, regmap, mbq_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_mask_sdca_irqs) > + sn622x_sdca_sdca_irq_mask_all(sn622x); > + SN622X_TRC(&slave->dev, "SoundWire probe finished OK\n"); > + } > + > + return ret; > +} [Severity: Medium] Does calling sn622x_sdca_sdca_irq_mask_all() in sn622x_sdca_sdw_probe() issue sdw_write_no_pm() writes to device 0 while the slave is still unattached? Unlike sn622x_sdca_probe(), which checks sn622x_slave_attached(slave) && slave->dev_num before touching the bus to avoid NACKing Slave 0 during enumeration, sn622x_sdca_sdw_probe() writes SDW_SCP_SDCA_INTMASK1..4 unconditionally before the slave has attached. > + > +static void sn622x_sdca_sdw_remove(struct sdw_slave *slave) > +{ > + struct sn622x_sdca_priv *sn622x =3D dev_get_drvdata(&slave->dev); > + > + SN622X_TRC(&slave->dev, "SoundWire driver remove\n"); > + sn622x->dmic_active =3D false; > + cancel_delayed_work_sync(&sn622x->dmic_on_work); > + cancel_delayed_work_sync(&sn622x->spk_chen_work); > + cancel_delayed_work_sync(&sn622x->settle_work); > + if (sn622x->first_hw_init) > + pm_runtime_disable(&slave->dev); > + mutex_destroy(&sn622x->disable_irq_lock); > +} [Severity: Medium] Does sn622x_sdca_sdw_remove() leave runtime PM enabled if the driver is removed before the slave attaches? sn622x_sdca_init() calls pm_runtime_use_autosuspend(dev) and pm_runtime_enable(dev) unconditionally during probe, but sn622x_sdca_sdw_remove() only calls pm_runtime_disable(&slave->dev) when sn622x->first_hw_init is true. It also omits pm_runtime_dont_use_autosuspend(&slave->dev) and mutex_destroy(&sn622x->path_lock). [ ... ] > +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"); > + > + regcache_cache_only(sn622x->regmap, true); > + regcache_cache_only(sn622x->mbq_regmap, true); > + > + return 0; > +} > + > +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_dev_system_suspend() issue SoundWire writes while the bus is already runtime-suspended or unattached, and can pending delayed works run while suspended? sn622x_sdca_dev_system_suspend() calls sn622x_sdca_sdca_irq_mask_all() whenever sn622x->first_hw_init is true, without checking whether the slave is currently attached or already runtime-suspended (clock-stopped). In addition, neither suspend callback cancels settle_work or dmic_on_work, and sn622x_settle_work() performs SoundWire I/O and calls regcache_cache_only(..., false) via sn622x_sdca_io_init() without taking a runtime PM reference. > diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/so= c_sdw_utils.c > index b6acf7616d147..68d57be59ea12 100644 > --- a/sound/soc/sdw_utils/soc_sdw_utils.c > +++ b/sound/soc/sdw_utils/soc_sdw_utils.c > @@ -1700,6 +1700,165 @@ struct asoc_sdw_codec_info codec_info_list[] =3D { [ ... ] > + /* SN6220, part_id 0x184c */ > + { > + .vendor_id =3D 0x0496, > + .part_id =3D 0x184c, > + .name_prefix =3D "sn622x", > + .ignore_internal_dmic =3D true, > + .dais =3D { [ ... ] > + { > + .direction =3D {false, true}, > + .dai_name =3D "sn622x-sdca-aif2", > + .dai_type =3D SOC_SDW_DAI_TYPE_MIC, > + .dailink =3D {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID}, > + .rtd_init =3D asoc_sdw_senary_dmic_rtd_init, > + .widgets =3D generic_dmic_widgets, > + .num_widgets =3D ARRAY_SIZE(generic_dmic_widgets), > + .quirk =3D SOC_SDW_CODEC_MIC, > + .quirk_exclude =3D true, > + }, > + }, > + .dai_num =3D 2, > + }, [Severity: High] Will card registration fail with -ENODEV in asoc_sdw_senary_dmic_rtd_init() for all four SN622x codec_info_list entries? These entries use .name_prefix =3D "sn622x" and generic_dmic_widgets (which creates card widget "DMIC", while the codec input widget is prefixed as "sn622x DMIC"), but asoc_sdw_senary_dmic_rtd_init() unconditionally adds the SN624x route: sound/soc/sdw_utils/soc_sdw_senary_dmic.c:asoc_sdw_senary_dmic_rtd_init() { ... if (component->name_prefix) { ret =3D snd_soc_dapm_add_routes(dapm, senary_dmic_map, ARRAY_SIZE(senary_dmic_map)); ... } Because senary_dmic_map is hardcoded to { "sn624x DMIC", NULL, "Dmic" } and neither widget exists on SN622x, snd_soc_dapm_add_routes() fails and aborts card probe. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130081210.4031= 6-1-qianghua.wang@senarytech.com?part=3D1