From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: broonie@kernel.org
Cc: vkoul@kernel.org, yung-chuan.liao@linux.intel.com,
pierre-louis.bossart@linux.dev, peter.ujfalusi@linux.intel.com,
shumingf@realtek.com, lgirdwood@gmail.com,
linux-sound@vger.kernel.org, patches@opensource.cirrus.com
Subject: [PATCH v2 04/13] ASoC: SDCA: Correct FDL locking with scoped_guard
Date: Mon, 3 Nov 2025 15:07:59 +0000 [thread overview]
Message-ID: <20251103150808.4015208-5-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20251103150808.4015208-1-ckeepax@opensource.cirrus.com>
The current locking in sdca_fdl_process() locks over
sdca_ump_cancel_timeout() and the timeout work function takes the same
lock, this can lead to a deadlock if the work runs as part of the
cancel. To fix this use scoped_guard and move the cancel timeout to be
outside the lock.
Fixes: e92e25f77748 ("ASoC: SDCA: Add UMP timeout handling for FDL")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
New since v1.
sound/soc/sdca/sdca_fdl.c | 90 ++++++++++++++++++++-------------------
1 file changed, 46 insertions(+), 44 deletions(-)
diff --git a/sound/soc/sdca/sdca_fdl.c b/sound/soc/sdca/sdca_fdl.c
index cb79dc3131b82..fe0ef2df4d9eb 100644
--- a/sound/soc/sdca/sdca_fdl.c
+++ b/sound/soc/sdca/sdca_fdl.c
@@ -402,8 +402,6 @@ int sdca_fdl_process(struct sdca_interrupt *interrupt)
unsigned int reg, status;
int response, ret;
- guard(mutex)(&fdl_state->lock);
-
ret = sdca_ump_get_owner_host(dev, interrupt->function_regmap,
interrupt->function, interrupt->entity,
interrupt->control);
@@ -412,56 +410,60 @@ int sdca_fdl_process(struct sdca_interrupt *interrupt)
sdca_ump_cancel_timeout(&fdl_state->timeout);
- reg = SDW_SDCA_CTL(interrupt->function->desc->adr, interrupt->entity->id,
- SDCA_CTL_XU_FDL_STATUS, 0);
- ret = regmap_read(interrupt->function_regmap, reg, &status);
- if (ret < 0) {
- dev_err(dev, "failed to read FDL status: %d\n", ret);
- return ret;
- }
+ scoped_guard(mutex, &fdl_state->lock) {
+ reg = SDW_SDCA_CTL(interrupt->function->desc->adr,
+ interrupt->entity->id, SDCA_CTL_XU_FDL_STATUS, 0);
+ ret = regmap_read(interrupt->function_regmap, reg, &status);
+ if (ret < 0) {
+ dev_err(dev, "failed to read FDL status: %d\n", ret);
+ return ret;
+ }
- dev_dbg(dev, "FDL status: %#x\n", status);
+ dev_dbg(dev, "FDL status: %#x\n", status);
- ret = fdl_status_process(interrupt, status);
- if (ret < 0)
- goto reset_function;
-
- response = ret;
+ ret = fdl_status_process(interrupt, status);
+ if (ret < 0)
+ goto reset_function;
- dev_dbg(dev, "FDL response: %#x\n", response);
+ response = ret;
- ret = regmap_write(interrupt->function_regmap, reg,
- response | (status & ~SDCA_CTL_XU_FDLH_MASK));
- if (ret < 0) {
- dev_err(dev, "failed to set FDL status signal: %d\n", ret);
- return ret;
- }
+ dev_dbg(dev, "FDL response: %#x\n", response);
- ret = sdca_ump_set_owner_device(dev, interrupt->function_regmap,
- interrupt->function, interrupt->entity,
- interrupt->control);
- if (ret)
- return ret;
-
- switch (response) {
- case SDCA_CTL_XU_FDLH_RESET_ACK:
- dev_dbg(dev, "FDL request reset\n");
+ ret = regmap_write(interrupt->function_regmap, reg,
+ response | (status & ~SDCA_CTL_XU_FDLH_MASK));
+ if (ret < 0) {
+ dev_err(dev, "failed to set FDL status signal: %d\n", ret);
+ return ret;
+ }
- switch (xu->reset_mechanism) {
- default:
- dev_warn(dev, "Requested reset mechanism not implemented\n");
+ ret = sdca_ump_set_owner_device(dev, interrupt->function_regmap,
+ interrupt->function,
+ interrupt->entity,
+ interrupt->control);
+ if (ret)
+ return ret;
+
+ switch (response) {
+ case SDCA_CTL_XU_FDLH_RESET_ACK:
+ dev_dbg(dev, "FDL request reset\n");
+
+ switch (xu->reset_mechanism) {
+ default:
+ dev_warn(dev, "Requested reset mechanism not implemented\n");
+ fallthrough;
+ case SDCA_XU_RESET_FUNCTION:
+ goto reset_function;
+ }
+ case SDCA_CTL_XU_FDLH_COMPLETE:
+ if (status & SDCA_CTL_XU_FDLD_REQ_ABORT ||
+ status == SDCA_CTL_XU_FDLD_COMPLETE)
+ return 0;
fallthrough;
- case SDCA_XU_RESET_FUNCTION:
- goto reset_function;
- }
- case SDCA_CTL_XU_FDLH_COMPLETE:
- if (status & SDCA_CTL_XU_FDLD_REQ_ABORT ||
- status == SDCA_CTL_XU_FDLD_COMPLETE)
+ default:
+ sdca_ump_schedule_timeout(&fdl_state->timeout,
+ xu->max_delay);
return 0;
- fallthrough;
- default:
- sdca_ump_schedule_timeout(&fdl_state->timeout, xu->max_delay);
- return 0;
+ }
}
reset_function:
--
2.47.3
next prev parent reply other threads:[~2025-11-03 15:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 15:07 [PATCH v2 00/13] Add SDCA class driver Charles Keepax
2025-11-03 15:07 ` [PATCH v2 01/13] ASoC: SDCA: Remove duplicated module macros Charles Keepax
2025-11-03 15:07 ` [PATCH v2 02/13] ASoC: SDCA: Fix missing dash in HIDE DisCo property Charles Keepax
2025-11-03 15:07 ` [PATCH v2 03/13] ASoC: SDCA: Add missing forward declaration in header Charles Keepax
2025-11-03 15:07 ` Charles Keepax [this message]
2025-11-05 15:07 ` [PATCH v2 04/13] ASoC: SDCA: Correct FDL locking with scoped_guard Charles Keepax
2025-11-03 15:08 ` [PATCH v2 05/13] ASoC: SDCA: Add comment for function reset polling Charles Keepax
2025-11-03 15:08 ` [PATCH v2 06/13] ASoC: SDCA: Move most of the messages from info to debug Charles Keepax
2025-11-03 15:08 ` [PATCH v2 07/13] ASoC: SDCA: Use helper macros for control identification Charles Keepax
2025-11-03 15:08 ` [PATCH v2 08/13] ASoC: SDCA: Factor out helper to process Control defaults Charles Keepax
2025-11-03 15:08 ` [PATCH v2 09/13] ASoC: SDCA: Populate regmap cache for readable Controls Charles Keepax
2025-11-03 15:08 ` [PATCH v2 10/13] ASoC: SDCA: Add helper to write initialization writes Charles Keepax
2025-11-03 15:08 ` [PATCH v2 11/13] ASoC: SDCA: add function devices Charles Keepax
2025-11-03 15:08 ` [PATCH v2 12/13] ASoC: SDCA: Add basic SDCA class driver Charles Keepax
2025-11-03 15:08 ` [PATCH v2 13/13] ASoC: SDCA: Add basic SDCA function driver Charles Keepax
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=20251103150808.4015208-5-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=shumingf@realtek.com \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.com \
/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