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=1796309109; b=As5LPmahHDUWVYmEW5kbJYpCVEvIMszqFYkTTSvCHoD7jEoI1LFkcmVTE3RTN5pDD5wV +3dxKc1cyTThmasUq946t4/0vsEdTfvfe4i7sfv5/tWXl8EyFuXTzypglPuIQwXw52BiZ X6F02iaH5WUWNDgIkOzaYhc7V5bMoOEPhpcbXe3EvPZ25gM/MEDV2NU5mEVZiRAo/38vG tDqU2aLqwXMQCuuR9AZvmlyPw+9JdrUYBwmzhLGfhDeZ4HoBNQxy211duPxCBiNB7kAtV J2dtA/qPRCixTwYQCctO/z9/cdbAyOErfmTUoA9koe+Cecmu7N1yF/2lp5rbSBvBKvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309109; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=lBx52rMU+3COuR6h7QePnI3+l02q4utfiftfbit2BNo=; b=5hI9KMjWpdQRok1EpafX+ZfeYE4OVBcAnfOeL8mrwvRnZF/KEKcbwis31JSu19A9Du47 YagASlBN0USbPmid8CvbBA0EXMDcZ66C0jwnKlSrIb18YaQILGrok+S/PbU08mfypMr/r i4GZLa2sWUA225xl5V3ftTOonUKvLlvOxH73I2H/5DVhpy9dTzvzklFgNHHdXGql+i/1T 3oIU4Vsv/bmcAjh2Pd9Ow1tHpyF0sg2DMte0wajONEaHNB4fG1k1kN9ZUWtmoTZ2nz7Qh iW+D/uUjeYmIgsklE5bnHjHFjM2APSOS+e9n+0iQZ5DNPYf9qkn7t09Cv6jGD1YNkqw== 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=Oj3HFmZ7; 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 E7FE8606A330 for ; Thu, 3 Dec 2026 14:45:08 +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=Oj3HFmZ7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FCE51F000C1; Thu, 3 Dec 2026 14:45:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796309108; bh=lBx52rMU+3COuR6h7QePnI3+l02q4utfiftfbit2BNo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Oj3HFmZ7ffBbHzyzL0DhPbKTdHRtqN9PvRd28zcs8Np9NecSUHIiws7bxVfkYU5Pt A8vvVJ5Vp62QbktyNJJjKU50MaLuhHC1TWRCx7ipRt/M/GNGW00Z+CsJ0SFkUPx0ta Z4ywOx4qtPGKUha/kKwPiWO5PQRCMMu3YKBmeQ3oPzrjRK9uQyfV/aXhter3I2gujn yfxpUQBov3VsA6ZN1Gg0PbO2wQlOWaaea8Say/BWL7Q9bww6PIJ8KNqWqr92/VGGzb 0GgM7Cj+Rrd521IrAbF+vSqYQJ4bFaXLKo5KfAueeOWhdBh9xVShFhHVZTtX/XfH4W oVbclWJ/new/g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ASoC: codecs: wcd9378: defer SoundWire SCP init until attachment Reply-To: sashiko-reviews@lists.linux.dev To: "Ajay Kumar Nandam" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261203-ak-gt-wcd9378-defer-scp-init-v1-1-33d834e8d307@oss.qualcomm.com> References: <20261203-ak-gt-wcd9378-defer-scp-init-v1-1-33d834e8d307@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 14:45:08 +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 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 > 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 [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 c= odec") > diff --git a/sound/soc/codecs/wcd9378-sdca.c b/sound/soc/codecs/wcd9378-s= dca.c > index efbbeb3dc721a..b00acae866541 100644 > --- a/sound/soc/codecs/wcd9378-sdca.c > +++ b/sound/soc/codecs/wcd9378-sdca.c > @@ -27,8 +27,24 @@ > #include > #include "wcd9378-sdca.h" > =20 > +/* > + * 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 =3D 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); > } > =20 > - /* SCP writes below need the slave attached. */ > - ret =3D 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 =3D 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 =3D 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 =3D dev_get_drvdata(&slave->dev); > + int ret; > + > + if (status =3D=3D SDW_SLAVE_UNATTACHED) { > + guard(mutex)(&priv->scp_init_lock); > + priv->scp_init_state =3D WCD9378_SCP_NOT_INITIALIZED; > + return 0; > + } > + > + if (status !=3D 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 =3D=3D 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 =3D wcd9378_sdca_scp_init(slave); > + if (ret) { > + priv->scp_init_state =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-ak-gt-wcd9= 378-defer-scp-init-v1-1-33d834e8d307@oss.qualcomm.com?part=3D1