From: sashiko-bot@kernel.org
To: "Ajay Kumar Nandam" <ajay.nandam@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ASoC: codecs: wcd9378: defer SoundWire SCP init until attachment
Date: Thu, 03 Dec 2026 14:45:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-248004@kernel.org> (raw)
In-Reply-To: <20261203-ak-gt-wcd9378-defer-scp-init-v1-1-33d834e8d307@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] ASoC: wcd9378: class_boot_work() races with deferred SCP init
on warm probe
- [Medium] ASoC: wcd9378: failed SCP init in update_status() is ignored
and never retried
- [Medium] ASoC: wcd9378: update_status() skips SCP init when probed in
SDW_SLAVE_ALERT
- [Low] ASoC: wcd9378: redundant scp_init_lock and dead enum
wcd9378_scp_init_state
- [Low] ASoC: wcd9378: missing Fixes trailer referencing commit
0c30b8ca84ae
--
commit 93531027bbe34ef9e8afd9391c50e46957480c54
Author: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
> ASoC: codecs: wcd9378: defer SoundWire SCP init until attachment
>
> wcd9378_sdca_probe() called sdw_slave_wait_for_init(slave, 5000) to
> gate two SCP register writes (TX PDM clock-div bank-1 shadow and
> SDW_SCP_COMMIT), waiting for the SoundWire core to signal that the
> peripheral has completed initial attachment and enumeration.
>
> This wait can only be satisfied once the SoundWire controller's own
> probe has progressed through bus enumeration and slave status
> handling. When the peripheral device is recreated and reprobed while
> the controller is still inside its own probe call (e.g. after the
> controller unbinds and rebinds its SoundWire master), the controller
> thread is blocked inside this codec's probe function, so it can never
> reach the status handling required to satisfy the wait. The probe
> then fails after the 5 second timeout.
>
> Move the SCP initialization out of .probe() and into a new
> update_status() callback, performing it only once the core reports
> SDW_SLAVE_ATTACHED, mirroring the pattern used by other SoundWire
> peripheral drivers (e.g. rt711-sdw.c). Initialization state is tracked
> explicitly so repeated ATTACHED notifications are idempotent, a
> transient failure remains retryable on a later ATTACHED event, and an
> UNATTACHED notification resets the state so a subsequent attach
> reinitializes correctly. A mutex guards the state against concurrent
> update_status invocations.
>
> Signed-off-by: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
[Severity: Low]
This fixes a warm re-probe deadlock introduced when the driver was added.
Should this include:
Fixes: 0c30b8ca84ae ("ASoC: codecs: add Qualcomm Tambora (WCD9378) SDCA codec")
> diff --git a/sound/soc/codecs/wcd9378-sdca.c b/sound/soc/codecs/wcd9378-sdca.c
> index efbbeb3dc721a..b00acae866541 100644
> --- a/sound/soc/codecs/wcd9378-sdca.c
> +++ b/sound/soc/codecs/wcd9378-sdca.c
> @@ -27,8 +27,24 @@
> #include <sound/soc-dai.h>
> #include "wcd9378-sdca.h"
>
> +/*
> + * SCP one-shot init state. WCD9378_SCP_INIT_* tracks the TX PDM
> + * clock-div + SCP_COMMIT pair below, which must run exactly once per
> + * attach session, after the slave reaches SDW_SLAVE_ATTACHED and
> + * before any port is enabled.
> + */
> +enum wcd9378_scp_init_state {
> + WCD9378_SCP_NOT_INITIALIZED = 0,
> + WCD9378_SCP_INITIALIZING,
> + WCD9378_SCP_INITIALIZED,
> + WCD9378_SCP_FAILED_RETRYABLE,
> +};
> +
> struct wcd9378_priv {
> struct sdca_class_drv class;
> + /* guards scp_init_state against concurrent update_status calls */
> + struct mutex scp_init_lock;
> + enum wcd9378_scp_init_state scp_init_state;
> };
[Severity: Low]
Is scp_init_lock or the four-state enum needed here? Every caller of
update_status() in the SoundWire core (sdw_bus_probe() and
sdw_update_slave_status()) already holds slave->sdw_dev_lock, so
update_status() cannot run concurrently.
WCD9378_SCP_INITIALIZING is overwritten before returning and never read,
and WCD9378_SCP_FAILED_RETRYABLE behaves the same as
WCD9378_SCP_NOT_INITIALIZED. The comment also names WCD9378_SCP_INIT_*,
which does not match the enumerators. A single bool flag would provide
the same behavior.
[ ... ]
> @@ -1012,24 +1034,12 @@ int wcd9378_sdca_probe(struct sdw_slave *slave,
> usleep_range(20, 30);
> }
>
> - /* SCP writes below need the slave attached. */
> - ret = sdw_slave_wait_for_init(slave, 5000);
> - if (ret)
> - return dev_err_probe(dev, ret,
> - "slave attach timeout: %d\n", ret);
> -
> /*
> - * TX PDM clock: bank-1 shadow + SCP_COMMIT. SCP survives PDE
> - * cycles; one-shot before any port is enabled.
> + * The SCP init below moved to wcd9378_sdca_update_status() on first
> + * ATTACHED: waiting here synchronously deadlocks a warm re-probe, since
> + * the controller thread that would satisfy the wait is blocked in this
> + * very probe call.
> */
> - ret = sdw_write_no_pm(slave, WCD9378_SCP_HOST_CLK_DIV2_CTL_B1, 0x01);
> - if (ret)
> - return dev_err_probe(dev, ret,
> - "HOST_CLK_DIV2_CTL_B1: %d\n", ret);
> -
> - ret = sdw_write_no_pm(slave, SDW_SCP_COMMIT, 0x02);
> - if (ret)
> - return dev_err_probe(dev, ret, "SCP_COMMIT: %d\n", ret);
[Severity: Medium]
Can class_boot_work() now race with or run ahead of
wcd9378_sdca_scp_init()?
When the peripheral attaches before slave->probed becomes true (for
example on late module load or driver rebind), sdw_handle_slave_status()
has already signaled slave->initialization_complete while skipping
update_status(). wcd9378_sdca_probe() then calls sdca_class_probe(),
which queues drv->boot_work before sdw_bus_probe() reaches
update_status():
CPU0 (sdw_bus_probe) kworker (class_boot_work)
wcd9378_sdca_probe()
sdca_class_probe()
queue_work(&drv->boot_work)
return 0
sdw_slave_wait_for_init()
/* already complete */
read_prop() / sysfs init class_function_boot()
<-- runs before SCP init
update_status(..., ATTACHED)
wcd9378_sdca_scp_init()
class_function_boot() writes wcd9378_sdca_init_table (including SCP clock
registers and RESET_FUNCTION_NOW) and registers the ASoC component and
DAIs without waiting for the bank-1 shadow and SDW_SCP_COMMIT writes,
risking misconfigured TX PDM clocking.
[ ... ]
> +int wcd9378_sdca_update_status(struct sdw_slave *slave,
> + enum sdw_slave_status status)
> +{
> + struct wcd9378_priv *priv = dev_get_drvdata(&slave->dev);
> + int ret;
> +
> + if (status == SDW_SLAVE_UNATTACHED) {
> + guard(mutex)(&priv->scp_init_lock);
> + priv->scp_init_state = WCD9378_SCP_NOT_INITIALIZED;
> + return 0;
> + }
> +
> + if (status != SDW_SLAVE_ATTACHED)
> + return 0;
[Severity: Medium]
Should SDW_SLAVE_ALERT also trigger wcd9378_sdca_scp_init()?
sdw_handle_slave_alerts() sets slave->status to SDW_SLAVE_ALERT and never
restores it to SDW_SLAVE_ATTACHED. On the Qualcomm SoundWire controller,
qcom_swrm_get_alert_slave_dev_num() does not update ctrl->slave_status,
so once the alert clears, qcom_swrm_irq_handler() sees
ctrl->slave_status == slave_status and leaves slave->status stuck at
SDW_SLAVE_ALERT.
If wcd9378 binds or rebinds in that state, sdw_bus_probe() passes
SDW_SLAVE_ALERT here and skips SCP init while class_boot_work() still
registers the codec, leaving TX PDM clocking uninitialized.
[ ... ]
> + ret = wcd9378_sdca_scp_init(slave);
> + if (ret) {
> + priv->scp_init_state = WCD9378_SCP_FAILED_RETRYABLE;
> + return ret;
> + }
[Severity: Medium]
Will wcd9378_sdca_scp_init() ever be retried if it fails here?
Both sdw_handle_slave_status() and sdw_bus_probe() only log a negative
return from update_status(), still complete slave->initialization_complete,
and let class_boot_work() register the SDCA function and DAIs. While the
slave stays attached, neither the SoundWire core nor
qcom_swrm_irq_handler() emits another SDW_SLAVE_ATTACHED notification, so
TX PDM clocking remains broken until an unrelated unattach/reattach cycle.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ak-gt-wcd9378-defer-scp-init-v1-1-33d834e8d307@oss.qualcomm.com?part=1
prev parent reply other threads:[~2026-12-03 14:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:25 [PATCH] ASoC: codecs: wcd9378: defer SoundWire SCP init until attachment Ajay Kumar Nandam
2026-12-03 14:45 ` 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-248004@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ajay.nandam@oss.qualcomm.com \
--cc=linux-sound@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.