Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Qianghua Wang" <qianghua.wang@senarytech.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 1/1] ASoC: codecs: add SN622x SDCA SoundWire codec support
Date: Mon, 30 Nov 2026 08:37:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-240693@kernel.org> (raw)
In-Reply-To: <20261130081210.40316-2-qianghua.wang@senarytech.com>

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 <qianghua.wang@senarytech.com>

ASoC: codecs: add SN622x SDCA SoundWire codec support

This commit adds the snd-soc-sn622x-sdca SoundWire codec driver for Senary
SN6220 and SN6224 SDCA devices, along with 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_complete from
> + * update_status -> io_init -> uaj_apply (that completion is signaled only after
> + * update_status returns — would deadlock). Use wait_sd_init=false 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 sdw_slave *slave,
> +					   bool wait_sd_init, unsigned int timeout_ms)
> +{
> +	unsigned long deadline = jiffies + msecs_to_jiffies(timeout_ms);
> +
> +	if (!slave)
> +		return -EINVAL;
> +
> +	/* Fail fast when SoftAmp is off the bus — do not wait 30s. */
> +	if (slave->status == SDW_SLAVE_UNATTACHED)
> +		return -ENODEV;
> +
> +	if (slave->dev_num_sticky && !slave->dev_num) {
> +		slave->dev_num = slave->dev_num_sticky;
> +		SN622X_DBG(dev,
> +			   "sync dev_num from dev_num_sticky=%u for paged SCP\n",
> +			   slave->dev_num_sticky);
> +	}
> +
> +	for (;;) {
> +		struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
> +
> +		if (slave->status == SDW_SLAVE_UNATTACHED)
> +			return -ENODEV;
> +
> +		if (slave->dev_num) {
> +			if (sn622x)
> +				sn622x->last_dev_num = 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 == SDW_SLAVE_ALERT) {
> +			if (sn622x && sn622x->last_dev_num) {
> +				slave->dev_num = sn622x->last_dev_num;
> +				SN622X_DBG(dev,
> +					   "restore dev_num=%u after ALERT for paged SCP\n",
> +					   sn622x->last_dev_num);
> +				return 0;
> +			}
> +			return -EAGAIN;
> +		}
> +
> +		if (slave->dev_num_sticky) {
> +			slave->dev_num = slave->dev_num_sticky;
> +			SN622X_DBG(dev,
> +				   "sync dev_num from dev_num_sticky=%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 = 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 = 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 = 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[] = {
> +				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 = regmap_multi_reg_write_bypassed(sn622x->regmap, mute_vol,
> +							    ARRAY_SIZE(mute_vol));

[Severity: Medium]
Does writing SN622X_REG_MUTE = 0 here in sn622x_hw_params_speaker_playback()
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[] = {
> +			REG_SEQ0(SN622X_REG_MUTE, SN622X_MUTE_ON),
> +			REG_SEQ0(SN622X_REG_RIGHT_MUTE, SN622X_MUTE_ON),
> +		};
> +		unsigned int spk_pwr = 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) == 0 &&
> +		    (spk_pwr & 0xffu) != SN622X_PWR_D3)
> +			sn622x_speaker_pwr_request_d3(dev, sn622x);
> +		sn622x->spk_parked_for_dmic = true;
> +	} else {
> +		dev_info(dev,
> +			 "sn622x: dmic prepare: duplex — leave Speakers, SoftMic 48k/16\n");
> +	}

[ ... ]

> +	{
> +		bool muted_spk = false;
> +		static const struct reg_sequence spk_mute_on[] = {
> +			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 = 0;
> +
> +			if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_MUTE,
> +						 &spk_mute) == 0 &&
> +			    (spk_mute & 0xffu) == 0) {
> +				regmap_multi_reg_write_bypassed(sn622x->regmap,
> +								spk_mute_on,
> +								ARRAY_SIZE(spk_mute_on));
> +				muted_spk = true;
> +			}
> +		}
> +
> +		r = 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 = 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 = false, and
even if bringup were true, sn622x_restore_dmic_analog() earlier in this
function sets sn622x->dmic_analog_restored = true, so this branch always
jumps to out_unlock.

[ ... ]

> +static const struct reg_default sn622x_sdca_reg_defaults[] = {
> +	{}
> +};
> +
> +static const struct regmap_config sn622x_sdca_regmap = {
> +	.reg_bits = 32,
> +	.val_bits = 8,
> +	.readable_reg = sn622x_sdca_readable_register,
> +	.volatile_reg = sn622x_sdca_volatile_register,
> +	.max_register = 0xffffffff,
> +	.reg_defaults = sn622x_sdca_reg_defaults,
> +	.num_reg_defaults = 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 = 0; i < ARRAY_SIZE(dmic_init_table); i++) {
> +		ret = regmap_read_bypassed(sn622x->regmap, dmic_init_table[i].reg,
> +					   &v);
> +		dev_dbg(dev, "sn622x: dmic init[0x%x]=0x%x err=%d\n",
> +			dmic_init_table[i].reg, v, ret);
> +	}
> +
> +	return 0;
> +}
> +
> +static int sn622x_sdca_io_init(struct device *dev, struct sdw_slave *slave)
> +{
> +	struct sn622x_sdca_priv *sn622x = 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 — skip bus access\n");
> +		sn622x->hw_init = 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 — otherwise Cap stays quiet until SoftMic is
> +	 * stopped and reopened. SoftMic prepare (settle) restores analog/CHEN.
> +	 */
> +	if (sn622x->dmic_active) {
> +		dev_info(dev,
> +			 "sn622x: io_init: SoftMic active — 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 = 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 = true;
> +	sn622x->first_hw_init = 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 =
> +		container_of(work, struct sn622x_sdca_priv, settle_work.work);
> +	struct device *dev;
> +
> +	if (!sn622x->slave || !sn622x_slave_attached(sn622x->slave))
> +		return;
> +
> +	dev = &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 — 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 = false;
                                        cancel_delayed_work_sync(&dmic_on_work)
    mod_delayed_work(..., &dmic_on_work, ...)
                                        cancel_delayed_work_sync(&settle_work)
                                        /* 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 assign). */
> +static int sn622x_clear_dp0_int(struct sdw_slave *slave)
> +{
> +	int status, status2, ret, count = 0;
> +	u8 clear, impl_int_mask;
> +
> +	status = sdw_read_no_pm(slave, SDW_DP0_INT);
> +	if (status < 0)
> +		return status;
> +
> +	do {
> +		clear = status & ~(SDW_DP0_INTERRUPTS | SDW_DP0_SDCA_CASCADE);
> +
> +		if (status & SDW_DP0_INT_TEST_FAIL)
> +			clear |= SDW_DP0_INT_TEST_FAIL;
> +
> +		if (status & SDW_DP0_INT_PORT_READY) {
> +			complete(&slave->port_ready[0]);
> +			clear |= 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 = 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 = dai->component;
> +	struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
> +	struct sdw_stream_config stream_config;
> +	struct sdw_port_config port_config;

[ ... ]

> +	stream_config.frame_rate = 48000;
> +	stream_config.ch_count = ch;
> +	stream_config.bps = snd_pcm_format_width(params_format(params));
> +	if (stream_config.bps > 16 &&
> +	    params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
> +		stream_config.bps = 16;
> +	stream_config.direction = direction;
> +	port_config.ch_mask = GENMASK(ch - 1, 0);
> +	port_config.num = port;

[ ... ]

> +	ret = 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 = {};) ensures
SDW_STREAM_PCM.

[Severity: Low]
Also, can (stream_config.bps > 16 && params_format(params) ==
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 — restore Speakers (D0 + charge
> +	 * pump + CHEN). Skip if SoftMic never parked Speakers (e.g. refused
> +	 * while Speakers were already open).
> +	 */
> +	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
> +	    dai->id == SN622X_DAI_DMIC &&
> +	    sn622x->spk_parked_for_dmic &&
> +	    sn622x_slave_attached(sn622x->slave)) {
> +		sn622x->spk_parked_for_dmic = 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 = 0x0b), unmutes both speaker channels, and sets
SN622X_REG_CH_ENABLE_B = 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 = dai->component;
> +	struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
> +	bool got_pm = 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 != SNDRV_PCM_TRIGGER_START &&
> +	    cmd != SNDRV_PCM_TRIGGER_RESUME &&
> +	    cmd != SNDRV_PCM_TRIGGER_PAUSE_RELEASE)
> +		return 0;
> +
> +	ret = pm_runtime_resume_and_get(component->dev);
> +	if (ret < 0 && ret != -EACCES)
> +		return ret;
> +	if (ret == 0)
> +		got_pm = true;
> +
> +	if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
> +	    dai->id == SN622X_DAI_DMIC) {
> +		sn622x->dmic_rate = substream->runtime->rate;
> +		sn622x->dmic_active = 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() performs
20 unconditional paged register readbacks over SoundWire just for dev_dbg().

[ ... ]

> +static struct snd_soc_dai_driver sn622x_sdca_dai[] = {
> +	{
> +		.name = "sn622x-sdca-aif",
> +		.id = SN622X_DAI_SPEAKER,
> +		.playback = {
> +			.stream_name = "Speaker Playback",
> +			.channels_min = 1,
> +			.channels_max = 2,
> +			.rates = SN622X_STEREO_RATES,
> +			.formats = SN622X_FORMATS,
> +		},
> +		.ops = &sn622x_sdca_ops,
> +	},
> +	{
> +		.name = "sn622x-sdca-aif2",
> +		.id = SN622X_DAI_DMIC,
> +		.capture = {
> +			.stream_name = "DMic Capture",
> +			.channels_min = 1,
> +			.channels_max = 4,
> +			.rates = SN622X_STEREO_RATES,
> +			.formats = SN622X_FORMATS,
> +		},
> +		.ops = &sn622x_sdca_ops,
> +	},
> +};

[Severity: Medium]
Should sn622x-sdca-aif2 advertise .channels_max = 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 = SNDRV_CTL_ELEM_TYPE_INTEGER;
> +	uinfo->count = 1;
> +	uinfo->value.integer.min = 0;
> +	uinfo->value.integer.max = 0xffffffff;
> +	return 0;
> +}

[ ... ]

> +static int sn622x_vendor_reg_addr_info(struct snd_kcontrol *kcontrol,
> +				       struct snd_ctl_elem_info *uinfo)
> +{
> +	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
> +	uinfo->count = 3;
> +	uinfo->value.integer.min = 0;
> +	uinfo->value.integer.max = 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 = snd_kcontrol_chip(kcontrol);
> +	struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
> +	u32 addr = (u32)ucontrol->value.integer.value[0];
> +
> +	if (!component || !sn622x)
> +		return -ENODEV;
> +
> +	if (!addr)
> +		addr = sn622x->vendor_reg_addr;
> +
> +	/*
> +	 * No SCP access here: amixer cset always snd_ctl_elem_read() before write.
> +	 * 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] = addr;
> +	ucontrol->value.integer.value[1] = SN622X_VENDOR_REG_RW_READ;
> +	ucontrol->value.integer.value[2] = 0;
> +	return 0;
> +}

[ ... ]

> +static const struct snd_kcontrol_new sn622x_sdca_controls[] = {
> +	{
> +		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
> +		.name = "Vendor Reg Addr",
> +		.info = sn622x_vendor_reg_cache_info,
> +		.get = sn622x_vendor_reg_cache_get,
> +		.put = sn622x_vendor_reg_cache_put,
> +	},
> +	{
> +		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
> +		.name = "Vendor Reg Address",
> +		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
> +		.info = sn622x_vendor_reg_addr_info,
> +		.get = sn622x_vendor_reg_addr_get,
> +		.put = sn622x_vendor_reg_addr_put,
> +	},
> +	{
> +		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
> +		.name = "Vendor Reg Address write 1",
> +		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
> +		.info = sn622x_vendor_reg_cache_info,
> +		.get = sn622x_vendor_reg_cache_get,
> +		.put = 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 = 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 = 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 = 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 = 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 = dev_get_drvdata(&slave->dev);
> +
> +	SN622X_TRC(&slave->dev, "SoundWire driver remove\n");
> +	sn622x->dmic_active = 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 = 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 = 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 = 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/soc_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[] = {

[ ... ]

> +	/* SN6220, part_id 0x184c */
> +	{
> +		.vendor_id = 0x0496,
> +		.part_id = 0x184c,
> +		.name_prefix = "sn622x",
> +		.ignore_internal_dmic = true,
> +		.dais = {

[ ... ]

> +			{
> +				.direction = {false, true},
> +				.dai_name = "sn622x-sdca-aif2",
> +				.dai_type = SOC_SDW_DAI_TYPE_MIC,
> +				.dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
> +				.rtd_init = asoc_sdw_senary_dmic_rtd_init,
> +				.widgets = generic_dmic_widgets,
> +				.num_widgets = ARRAY_SIZE(generic_dmic_widgets),
> +				.quirk = SOC_SDW_CODEC_MIC,
> +				.quirk_exclude = true,
> +			},
> +		},
> +		.dai_num = 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 = "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 = 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130081210.40316-1-qianghua.wang@senarytech.com?part=1

      reply	other threads:[~2026-11-30  8:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  8:12 [PATCH 0/1] ASoC: codecs: add SN622x SDCA SoundWire codec support Qianghua Wang
2026-11-30  8:12 ` [PATCH 1/1] " Qianghua Wang
2026-11-30  8:37   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-240693@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=qianghua.wang@senarytech.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox