From: "Baek Kyu, Kim" <pocj8ur4in@gmail.com>
To: Vinod Koul <vkoul@kernel.org>,
Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>,
Srinivas Kandagatla <srini@kernel.org>,
linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] soundwire: qcom: restore port reservations on registration failure
Date: Tue, 20 Oct 2026 02:02:03 +0900 [thread overview]
Message-ID: <20261019170203.2533974-3-pocj8ur4in@gmail.com> (raw)
In-Reply-To: <20261019170203.2533974-1-pocj8ur4in@gmail.com>
qcom_swrm_stream_alloc_ports() ignores sdw_stream_add_master() errors and
returns success after master registration fails. Reservations made before
registration, or before discovering that all ports are busy, also remain
set in the controller bitmap.
For example, failing the second of two master port allocations returns
-ENOMEM from the core, but hw_params reports success and retains the new
port reservations. The stream is marked as configured despite incomplete
master registration.
Save the bitmap under port_lock and restore it on either failure, then
return the original error. This preserves earlier reservations and allows
a failed stream to retry. Remove the hw_params error cleanup that walks
master runtime ports: that list does not reliably describe reservations
made by the failed attempt. The allocation helper now restores its own
reservations before returning.
This patch depends on patch 1/2, which rolls back partial master port
allocation and failed stream configuration in the SoundWire core.
Fixes: 02efb49aa805 ("soundwire: qcom: add support for SoundWire controller")
Fixes: 5c68b66d4d7e ("soundwire: qcom: drop unneeded qcom_swrm_stream_alloc_ports() cleanup")
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
---
Tested with ARM64 QEMU KUnit using synthetic devices. Failing the second
master port allocation made hw_params return success and retain
reservations before the fix. With both patches, it returns -ENOMEM,
restores the original bitmap, and allows a successful retry. No physical
Qualcomm audio hardware was tested.
drivers/soundwire/qcom.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index 55678a30cd4a..586bdd17171a 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -1241,7 +1241,8 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
struct sdw_port_runtime *p_rt;
struct sdw_slave *slave;
unsigned long *port_mask;
- int maxport, pn, nports = 0;
+ int maxport, pn, nports = 0, ret;
+ unsigned long saved_port_mask;
unsigned int m_port;
struct sdw_port_config *pconfig __free(kfree) = kzalloc_objs(*pconfig,
ctrl->nports);
@@ -1260,6 +1261,7 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
sconfig.bps = 1;
guard(mutex)(&ctrl->port_lock);
+ saved_port_mask = ctrl->port_mask;
list_for_each_entry(m_rt, &stream->master_list, stream_node) {
/*
@@ -1286,7 +1288,8 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
if (pn >= maxport) {
dev_err(ctrl->dev, "All ports busy\n");
- return -EBUSY;
+ ret = -EBUSY;
+ goto restore_mask;
}
set_bit(pn, port_mask);
pconfig[nports].num = pn;
@@ -1296,10 +1299,14 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
}
}
- sdw_stream_add_master(&ctrl->bus, &sconfig, pconfig,
- nports, stream);
+ ret = sdw_stream_add_master(&ctrl->bus, &sconfig, pconfig,
+ nports, stream);
+ if (!ret)
+ return 0;
- return 0;
+restore_mask:
+ ctrl->port_mask = saved_port_mask;
+ return ret;
}
static int qcom_swrm_hw_params(struct snd_pcm_substream *substream,
@@ -1308,14 +1315,9 @@ static int qcom_swrm_hw_params(struct snd_pcm_substream *substream,
{
struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dai->dev);
struct sdw_stream_runtime *sruntime = ctrl->sruntime[dai->id];
- int ret;
- ret = qcom_swrm_stream_alloc_ports(ctrl, sruntime, params,
- substream->stream);
- if (ret)
- qcom_swrm_stream_free_ports(ctrl, sruntime);
-
- return ret;
+ return qcom_swrm_stream_alloc_ports(ctrl, sruntime, params,
+ substream->stream);
}
static int qcom_swrm_hw_free(struct snd_pcm_substream *substream,
prev parent reply other threads:[~2026-10-19 17:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 17:02 [PATCH 0/2] soundwire: roll back failed master registration Baek Kyu, Kim
2026-10-19 17:02 ` [PATCH 1/2] soundwire: stream: " Baek Kyu, Kim
2026-10-19 17:02 ` Baek Kyu, Kim [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=20261019170203.2533974-3-pocj8ur4in@gmail.com \
--to=pocj8ur4in@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=pierre-louis.bossart@linux.dev \
--cc=srini@kernel.org \
--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
all inboxes | Powered by JetHome®