From: phucduc.bui@gmail.com
To: Srinivas Kandagatla <srini@kernel.org>, Mark Brown <broonie@kernel.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>,
linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org,
bui duc phuc <phucduc.bui@gmail.com>
Subject: [PATCH 4/9] ASoC: qcom: q6apm: Use guard() for mutex locks
Date: Wed, 3 Jun 2026 18:49:44 +0700 [thread overview]
Message-ID: <20260603114949.149595-5-phucduc.bui@gmail.com> (raw)
In-Reply-To: <20260603114949.149595-1-phucduc.bui@gmail.com>
From: bui duc phuc <phucduc.bui@gmail.com>
Clean up the code using guard() for mutex locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
NOTE: This patch is compile-tested only.
sound/soc/qcom/qdsp6/q6apm.c | 107 ++++++++++++++++-------------------
1 file changed, 48 insertions(+), 59 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6apm.c b/sound/soc/qcom/qdsp6/q6apm.c
index 2ab378fb5032..17c44587b084 100644
--- a/sound/soc/qcom/qdsp6/q6apm.c
+++ b/sound/soc/qcom/qdsp6/q6apm.c
@@ -44,9 +44,8 @@ static struct audioreach_graph *q6apm_get_audioreach_graph(struct q6apm *apm, ui
struct audioreach_graph *graph;
int id;
- mutex_lock(&apm->lock);
- graph = idr_find(&apm->graph_idr, graph_id);
- mutex_unlock(&apm->lock);
+ scoped_guard(mutex, &apm->lock)
+ graph = idr_find(&apm->graph_idr, graph_id);
if (graph) {
kref_get(&graph->refcount);
@@ -74,16 +73,15 @@ static struct audioreach_graph *q6apm_get_audioreach_graph(struct q6apm *apm, ui
return ERR_CAST(err);
}
- mutex_lock(&apm->lock);
- id = idr_alloc(&apm->graph_idr, graph, graph_id, graph_id + 1, GFP_KERNEL);
- if (id < 0) {
- dev_err(apm->dev, "Unable to allocate graph id (%d)\n", graph_id);
- kfree(graph->graph);
- kfree(graph);
- mutex_unlock(&apm->lock);
- return ERR_PTR(id);
+ scoped_guard(mutex, &apm->lock) {
+ id = idr_alloc(&apm->graph_idr, graph, graph_id, graph_id + 1, GFP_KERNEL);
+ if (id < 0) {
+ dev_err(apm->dev, "Unable to allocate graph id (%d)\n", graph_id);
+ kfree(graph->graph);
+ kfree(graph);
+ return ERR_PTR(id);
+ }
}
- mutex_unlock(&apm->lock);
kref_init(&graph->refcount);
@@ -131,9 +129,8 @@ static void q6apm_put_audioreach_graph(struct kref *ref)
audioreach_graph_mgmt_cmd(graph, APM_CMD_GRAPH_CLOSE);
- mutex_lock(&apm->lock);
- graph = idr_remove(&apm->graph_idr, graph->id);
- mutex_unlock(&apm->lock);
+ scoped_guard(mutex, &apm->lock)
+ graph = idr_remove(&apm->graph_idr, graph->id);
kfree(graph->graph);
kfree(graph);
@@ -254,20 +251,16 @@ int q6apm_alloc_fragments(struct q6apm_graph *graph, unsigned int dir, phys_addr
else
data = &graph->tx_data;
- mutex_lock(&graph->lock);
+ guard(mutex)(&graph->lock);
data->dsp_buf = 0;
- if (data->buf) {
- mutex_unlock(&graph->lock);
+ if (data->buf)
return 0;
- }
buf = kzalloc_objs(struct audio_buffer, periods);
- if (!buf) {
- mutex_unlock(&graph->lock);
+ if (!buf)
return -ENOMEM;
- }
if (dir == SNDRV_PCM_STREAM_PLAYBACK)
data = &graph->rx_data;
@@ -287,8 +280,6 @@ int q6apm_alloc_fragments(struct q6apm_graph *graph, unsigned int dir, phys_addr
}
data->num_periods = periods;
- mutex_unlock(&graph->lock);
-
return 0;
}
EXPORT_SYMBOL_GPL(q6apm_alloc_fragments);
@@ -457,23 +448,22 @@ int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts,
write_buffer = (void *)pkt + GPR_HDR_SIZE;
- mutex_lock(&graph->lock);
- ab = &graph->rx_data.buf[graph->rx_data.dsp_buf];
-
- write_buffer->buf_addr_lsw = lower_32_bits(ab->phys);
- write_buffer->buf_addr_msw = upper_32_bits(ab->phys);
- write_buffer->buf_size = len;
- write_buffer->timestamp_lsw = lsw_ts;
- write_buffer->timestamp_msw = msw_ts;
- write_buffer->mem_map_handle = graph->info->mem_map_handle;
- write_buffer->flags = wflags;
+ scoped_guard(mutex, &graph->lock) {
+ ab = &graph->rx_data.buf[graph->rx_data.dsp_buf];
- graph->rx_data.dsp_buf++;
+ write_buffer->buf_addr_lsw = lower_32_bits(ab->phys);
+ write_buffer->buf_addr_msw = upper_32_bits(ab->phys);
+ write_buffer->buf_size = len;
+ write_buffer->timestamp_lsw = lsw_ts;
+ write_buffer->timestamp_msw = msw_ts;
+ write_buffer->mem_map_handle = graph->info->mem_map_handle;
+ write_buffer->flags = wflags;
- if (graph->rx_data.dsp_buf >= graph->rx_data.num_periods)
- graph->rx_data.dsp_buf = 0;
+ graph->rx_data.dsp_buf++;
- mutex_unlock(&graph->lock);
+ if (graph->rx_data.dsp_buf >= graph->rx_data.num_periods)
+ graph->rx_data.dsp_buf = 0;
+ }
return gpr_send_port_pkt(graph->port, pkt);
}
@@ -493,21 +483,20 @@ int q6apm_read(struct q6apm_graph *graph)
read_buffer = (void *)pkt + GPR_HDR_SIZE;
- mutex_lock(&graph->lock);
- port = &graph->tx_data;
- ab = &port->buf[port->dsp_buf];
-
- read_buffer->buf_addr_lsw = lower_32_bits(ab->phys);
- read_buffer->buf_addr_msw = upper_32_bits(ab->phys);
- read_buffer->mem_map_handle = graph->info->mem_map_handle;
- read_buffer->buf_size = ab->size;
+ scoped_guard(mutex, &graph->lock) {
+ port = &graph->tx_data;
+ ab = &port->buf[port->dsp_buf];
- port->dsp_buf++;
+ read_buffer->buf_addr_lsw = lower_32_bits(ab->phys);
+ read_buffer->buf_addr_msw = upper_32_bits(ab->phys);
+ read_buffer->mem_map_handle = graph->info->mem_map_handle;
+ read_buffer->buf_size = ab->size;
- if (port->dsp_buf >= port->num_periods)
- port->dsp_buf = 0;
+ port->dsp_buf++;
- mutex_unlock(&graph->lock);
+ if (port->dsp_buf >= port->num_periods)
+ port->dsp_buf = 0;
+ }
return gpr_send_port_pkt(graph->port, pkt);
}
@@ -545,12 +534,12 @@ static int graph_callback(const struct gpr_resp_pkt *data, void *priv, int op)
if (!graph->ar_graph)
break;
client_event = APM_CLIENT_EVENT_DATA_WRITE_DONE;
- mutex_lock(&graph->lock);
- token = hdr->token & APM_WRITE_TOKEN_MASK;
+ scoped_guard(mutex, &graph->lock) {
+ token = hdr->token & APM_WRITE_TOKEN_MASK;
- done = data->payload;
- phys = graph->rx_data.buf[token].phys;
- mutex_unlock(&graph->lock);
+ done = data->payload;
+ phys = graph->rx_data.buf[token].phys;
+ }
/* token numbering starts at 0 */
atomic_set(&graph->rx_data.hw_ptr, token + 1);
if (lower_32_bits(phys) == done->buf_addr_lsw &&
@@ -569,10 +558,10 @@ static int graph_callback(const struct gpr_resp_pkt *data, void *priv, int op)
if (!graph->ar_graph)
break;
client_event = APM_CLIENT_EVENT_DATA_READ_DONE;
- mutex_lock(&graph->lock);
- rd_done = data->payload;
- phys = graph->tx_data.buf[hdr->token].phys;
- mutex_unlock(&graph->lock);
+ scoped_guard(mutex, &graph->lock) {
+ rd_done = data->payload;
+ phys = graph->tx_data.buf[hdr->token].phys;
+ }
/* token numbering starts at 0 */
atomic_set(&graph->tx_data.hw_ptr, hdr->token + 1);
--
2.43.0
next prev parent reply other threads:[~2026-06-03 11:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
2026-06-03 11:49 ` [PATCH 1/9] ASoC: qcom: audioreach: Use guard() for mutex locks phucduc.bui
2026-06-03 11:49 ` [PATCH 2/9] ASoc: qcom: q6adm: Use guard() for mutex & spin locks phucduc.bui
2026-06-03 11:49 ` [PATCH 3/9] ASoc: qcom: q6afe: Use guard() for mutex locks phucduc.bui
2026-06-03 11:49 ` phucduc.bui [this message]
2026-06-03 11:49 ` [PATCH 5/9] ASoC: qcom: q6asm: Use guard() for mutex & spin locks phucduc.bui
2026-06-03 11:49 ` [PATCH 6/9] ASoC: qdsp6: q6core: Use guard() for mutex locks phucduc.bui
2026-06-03 11:49 ` [PATCH 7/9] ASoC: qdsp6: q6routing: " phucduc.bui
2026-06-03 11:49 ` [PATCH 8/9] ASoC: qdsp6: q6usb: " phucduc.bui
2026-06-03 11:49 ` [PATCH 9/9] ASoC: qcom: topology: " phucduc.bui
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=20260603114949.149595-5-phucduc.bui@gmail.com \
--to=phucduc.bui@gmail.com \
--cc=broonie@kernel.org \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=srini@kernel.org \
--cc=tiwai@suse.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