Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks
@ 2026-06-03 11:49 phucduc.bui
  2026-06-03 11:49 ` [PATCH 1/9] ASoC: qcom: audioreach: Use guard() for mutex locks phucduc.bui
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

From: bui duc phuc <phucduc.bui@gmail.com>

Hi all,

This series converts spinlock and mutex handling in the QCOM sound 
drivers to use guard() helpers.
The changes are code cleanup only and should have no functional impact.
Compile tested only.

Best regards,
Phuc

bui duc phuc (9):
  ASoC: qcom: audioreach: Use guard() for mutex locks
  ASoc: qcom: q6adm: Use guard() for mutex & spin locks
  ASoc: qcom: q6afe: Use guard() for mutex locks
  ASoC: qcom: q6apm: Use guard() for mutex locks
  ASoC: qcom: q6asm: Use guard() for mutex & spin locks
  ASoC: qdsp6: q6core: Use guard() for mutex locks
  ASoC: qdsp6: q6routing: Use guard() for mutex locks
  ASoC: qdsp6: q6usb: Use guard() for mutex locks
  ASoC: qcom: topology: Use guard() for mutex locks

 sound/soc/qcom/qdsp6/audioreach.c |   9 +-
 sound/soc/qcom/qdsp6/q6adm.c      |  52 ++++------
 sound/soc/qcom/qdsp6/q6afe.c      |   8 +-
 sound/soc/qcom/qdsp6/q6apm.c      | 107 +++++++++----------
 sound/soc/qcom/qdsp6/q6asm.c      | 164 +++++++++++++-----------------
 sound/soc/qcom/qdsp6/q6core.c     |   7 +-
 sound/soc/qcom/qdsp6/q6routing.c  |  10 +-
 sound/soc/qcom/qdsp6/q6usb.c      |  28 ++---
 sound/soc/qcom/qdsp6/topology.c   |  71 ++++++-------
 9 files changed, 190 insertions(+), 266 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/9] ASoC: qcom: audioreach: Use guard() for mutex locks
  2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
@ 2026-06-03 11:49 ` phucduc.bui
  2026-06-03 11:49 ` [PATCH 2/9] ASoc: qcom: q6adm: Use guard() for mutex & spin locks phucduc.bui
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

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/audioreach.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c
index a13f753eff98..8b3d1410c788 100644
--- a/sound/soc/qcom/qdsp6/audioreach.c
+++ b/sound/soc/qcom/qdsp6/audioreach.c
@@ -585,7 +585,7 @@ int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev,
 	const struct gpr_hdr *hdr = &pkt->hdr;
 	int rc;
 
-	mutex_lock(cmd_lock);
+	guard(mutex)(cmd_lock);
 	result->opcode = 0;
 	result->status = 0;
 
@@ -597,7 +597,7 @@ int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev,
 		rc = -EINVAL;
 
 	if (rc < 0)
-		goto err;
+		return rc;
 
 	if (rsp_opcode)
 		rc = wait_event_timeout(*cmd_wait, (result->opcode == hdr->opcode) ||
@@ -616,8 +616,6 @@ int audioreach_send_cmd_sync(struct device *dev, gpr_device_t *gdev,
 		rc = 0;
 	}
 
-err:
-	mutex_unlock(cmd_lock);
 	return rc;
 }
 EXPORT_SYMBOL_GPL(audioreach_send_cmd_sync);
@@ -1387,7 +1385,7 @@ void audioreach_graph_free_buf(struct q6apm_graph *graph)
 {
 	struct audioreach_graph_data *port;
 
-	mutex_lock(&graph->lock);
+	guard(mutex)(&graph->lock);
 	port = &graph->rx_data;
 	port->num_periods = 0;
 	kfree(port->buf);
@@ -1397,7 +1395,6 @@ void audioreach_graph_free_buf(struct q6apm_graph *graph)
 	port->num_periods = 0;
 	kfree(port->buf);
 	port->buf = NULL;
-	mutex_unlock(&graph->lock);
 }
 EXPORT_SYMBOL_GPL(audioreach_graph_free_buf);
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/9] ASoc: qcom: q6adm: Use guard() for mutex & spin locks
  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 ` phucduc.bui
  2026-06-03 11:49 ` [PATCH 3/9] ASoc: qcom: q6afe: Use guard() for mutex locks phucduc.bui
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

From: bui duc phuc <phucduc.bui@gmail.com>

Clean up the code using guard() for mutex & spin 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/q6adm.c | 52 +++++++++++++-----------------------
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6adm.c b/sound/soc/qcom/qdsp6/q6adm.c
index db0ae71f2983..44c268c3e529 100644
--- a/sound/soc/qcom/qdsp6/q6adm.c
+++ b/sound/soc/qcom/qdsp6/q6adm.c
@@ -92,9 +92,8 @@ static struct q6copp *q6adm_find_copp(struct q6adm *adm, int port_idx,
 {
 	struct q6copp *c;
 	struct q6copp *ret = NULL;
-	unsigned long flags;
 
-	spin_lock_irqsave(&adm->copps_list_lock, flags);
+	guard(spinlock_irqsave)(&adm->copps_list_lock);
 	list_for_each_entry(c, &adm->copps_list, node) {
 		if ((port_idx == c->afe_port) && (copp_idx == c->copp_idx)) {
 			ret = c;
@@ -103,8 +102,6 @@ static struct q6copp *q6adm_find_copp(struct q6adm *adm, int port_idx,
 		}
 	}
 
-	spin_unlock_irqrestore(&adm->copps_list_lock, flags);
-
 	return ret;
 
 }
@@ -116,14 +113,13 @@ static int q6adm_apr_send_copp_pkt(struct q6adm *adm, struct q6copp *copp,
 	uint32_t opcode = pkt->hdr.opcode;
 	int ret;
 
-	mutex_lock(&adm->lock);
+	guard(mutex)(&adm->lock);
 	copp->result.opcode = 0;
 	copp->result.status = 0;
 	ret = apr_send_pkt(adm->apr, pkt);
 	if (ret < 0) {
 		dev_err(dev, "Failed to send APR packet\n");
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
 	/* Wait for the callback with copp id */
@@ -146,8 +142,6 @@ static int q6adm_apr_send_copp_pkt(struct q6adm *adm, struct q6copp *copp,
 		ret = -EINVAL;
 	}
 
-err:
-	mutex_unlock(&adm->lock);
 	return ret;
 }
 
@@ -172,17 +166,16 @@ static void q6adm_free_copp(struct kref *ref)
 {
 	struct q6copp *c = container_of(ref, struct q6copp, refcount);
 	struct q6adm *adm = c->adm;
-	unsigned long flags;
 	int ret;
 
 	ret = q6adm_device_close(adm, c, c->afe_port, c->copp_idx);
 	if (ret < 0)
 		dev_err(adm->dev, "Failed to close copp %d\n", ret);
 
-	spin_lock_irqsave(&adm->copps_list_lock, flags);
-	clear_bit(c->copp_idx, &adm->copp_bitmap[c->afe_port]);
-	list_del(&c->node);
-	spin_unlock_irqrestore(&adm->copps_list_lock, flags);
+	scoped_guard(spinlock_irqsave, &adm->copps_list_lock) {
+		clear_bit(c->copp_idx, &adm->copp_bitmap[c->afe_port]);
+		list_del(&c->node);
+	}
 	kfree(c);
 }
 
@@ -306,9 +299,8 @@ static struct q6copp *q6adm_find_matching_copp(struct q6adm *adm,
 {
 	struct q6copp *c;
 	struct q6copp *ret = NULL;
-	unsigned long flags;
 
-	spin_lock_irqsave(&adm->copps_list_lock, flags);
+	guard(spinlock_irqsave)(&adm->copps_list_lock);
 
 	list_for_each_entry(c, &adm->copps_list, node) {
 		if ((port_id == c->afe_port) && (topology == c->topology) &&
@@ -318,7 +310,6 @@ static struct q6copp *q6adm_find_matching_copp(struct q6adm *adm,
 			kref_get(&c->refcount);
 		}
 	}
-	spin_unlock_irqrestore(&adm->copps_list_lock, flags);
 
 	return ret;
 }
@@ -384,7 +375,6 @@ struct q6copp *q6adm_open(struct device *dev, int port_id, int path, int rate,
 {
 	struct q6adm *adm = dev_get_drvdata(dev->parent);
 	struct q6copp *copp;
-	unsigned long flags;
 	int ret = 0;
 
 	if (port_id < 0) {
@@ -399,15 +389,13 @@ struct q6copp *q6adm_open(struct device *dev, int port_id, int path, int rate,
 		return copp;
 	}
 
-	spin_lock_irqsave(&adm->copps_list_lock, flags);
-	copp = q6adm_alloc_copp(adm, port_id);
-	if (IS_ERR(copp)) {
-		spin_unlock_irqrestore(&adm->copps_list_lock, flags);
-		return ERR_CAST(copp);
-	}
+	scoped_guard(spinlock_irqsave, &adm->copps_list_lock) {
+		copp = q6adm_alloc_copp(adm, port_id);
+		if (IS_ERR(copp))
+			return ERR_CAST(copp);
 
-	list_add_tail(&copp->node, &adm->copps_list);
-	spin_unlock_irqrestore(&adm->copps_list_lock, flags);
+		list_add_tail(&copp->node, &adm->copps_list);
+	}
 
 	kref_init(&copp->refcount);
 	copp->topology = topology;
@@ -518,7 +506,7 @@ int q6adm_matrix_map(struct device *dev, int path,
 		kref_put(&copp->refcount, q6adm_free_copp);
 	}
 
-	mutex_lock(&adm->lock);
+	guard(mutex)(&adm->lock);
 	adm->result.status = 0;
 	adm->result.opcode = 0;
 
@@ -526,7 +514,7 @@ int q6adm_matrix_map(struct device *dev, int path,
 	if (ret < 0) {
 		dev_err(dev, "routing for stream %d failed ret %d\n",
 		       payload_map.session_id, ret);
-		goto fail_cmd;
+		return ret;
 	}
 	ret = wait_event_timeout(adm->matrix_map_wait,
 				 adm->result.opcode == pkt->hdr.opcode,
@@ -534,17 +522,13 @@ int q6adm_matrix_map(struct device *dev, int path,
 	if (!ret) {
 		dev_err(dev, "routing for stream %d failed\n",
 		       payload_map.session_id);
-		ret = -ETIMEDOUT;
-		goto fail_cmd;
+		return -ETIMEDOUT;
 	} else if (adm->result.status > 0) {
 		dev_err(dev, "DSP returned error[%d]\n",
 			adm->result.status);
-		ret = -EINVAL;
-		goto fail_cmd;
+		return -EINVAL;
 	}
 
-fail_cmd:
-	mutex_unlock(&adm->lock);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(q6adm_matrix_map);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/9] ASoc: qcom: q6afe: Use guard() for mutex locks
  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 ` phucduc.bui
  2026-06-03 11:49 ` [PATCH 4/9] ASoC: qcom: q6apm: " phucduc.bui
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

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/q6afe.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c
index 40237267fda0..81a93b6f7e4c 100644
--- a/sound/soc/qcom/qdsp6/q6afe.c
+++ b/sound/soc/qcom/qdsp6/q6afe.c
@@ -1035,7 +1035,7 @@ static int afe_apr_send_pkt(struct q6afe *afe, struct apr_pkt *pkt,
 	struct aprv2_ibasic_rsp_result_t *result;
 	int ret;
 
-	mutex_lock(&afe->lock);
+	guard(mutex)(&afe->lock);
 	if (port) {
 		wait = &port->wait;
 		result = &port->result;
@@ -1050,8 +1050,7 @@ static int afe_apr_send_pkt(struct q6afe *afe, struct apr_pkt *pkt,
 	ret = apr_send_pkt(afe->apr, pkt);
 	if (ret < 0) {
 		dev_err(afe->dev, "packet not transmitted (%d)\n", ret);
-		ret = -EINVAL;
-		goto err;
+		return -EINVAL;
 	}
 
 	ret = wait_event_timeout(*wait, (result->opcode == rsp_opcode),
@@ -1066,9 +1065,6 @@ static int afe_apr_send_pkt(struct q6afe *afe, struct apr_pkt *pkt,
 		ret = 0;
 	}
 
-err:
-	mutex_unlock(&afe->lock);
-
 	return ret;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/9] ASoC: qcom: q6apm: Use guard() for mutex locks
  2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
                   ` (2 preceding siblings ...)
  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
  2026-06-03 11:49 ` [PATCH 5/9] ASoC: qcom: q6asm: Use guard() for mutex & spin locks phucduc.bui
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/9] ASoC: qcom: q6asm: Use guard() for mutex & spin locks
  2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
                   ` (3 preceding siblings ...)
  2026-06-03 11:49 ` [PATCH 4/9] ASoC: qcom: q6apm: " phucduc.bui
@ 2026-06-03 11:49 ` phucduc.bui
  2026-06-03 11:49 ` [PATCH 6/9] ASoC: qdsp6: q6core: Use guard() for mutex locks phucduc.bui
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

From: bui duc phuc <phucduc.bui@gmail.com>

Clean up the code using guard() for mutex & spin 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/q6asm.c | 164 +++++++++++++++--------------------
 1 file changed, 71 insertions(+), 93 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index de0bd8fd08ee..d058468c4afa 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -297,12 +297,12 @@ static int q6asm_apr_send_session_pkt(struct q6asm *a, struct audio_client *ac,
 	struct apr_hdr *hdr = &pkt->hdr;
 	int rc;
 
-	mutex_lock(&ac->cmd_lock);
+	guard(mutex)(&ac->cmd_lock);
 	ac->result.opcode = 0;
 	ac->result.status = 0;
 	rc = apr_send_pkt(a->adev, pkt);
 	if (rc < 0)
-		goto err;
+		return rc;
 
 	if (rsp_opcode)
 		rc = wait_event_timeout(a->mem_wait,
@@ -323,8 +323,6 @@ static int q6asm_apr_send_session_pkt(struct q6asm *a, struct audio_client *ac,
 		rc = -EINVAL;
 	}
 
-err:
-	mutex_unlock(&ac->cmd_lock);
 	return rc;
 }
 
@@ -371,11 +369,8 @@ static int __q6asm_memory_unmap(struct audio_client *ac,
 static void q6asm_audio_client_free_buf(struct audio_client *ac,
 					struct audio_port_data *port)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&ac->lock, flags);
-	port->num_periods = 0;
-	spin_unlock_irqrestore(&ac->lock, flags);
+	scoped_guard(spinlock_irqsave, &ac->lock)
+		port->num_periods = 0;
 	kfree(port->buf);
 	port->buf = NULL;
 }
@@ -427,7 +422,6 @@ static int __q6asm_memory_map_regions(struct audio_client *ac, int dir,
 	struct audio_port_data *port = NULL;
 	struct audio_buffer *ab = NULL;
 	struct apr_pkt *pkt;
-	unsigned long flags;
 	uint32_t num_regions, buf_sz;
 	int i, pkt_size;
 
@@ -464,17 +458,17 @@ static int __q6asm_memory_map_regions(struct audio_client *ac, int dir,
 	cmd->num_regions = num_regions;
 	cmd->property_flag = 0x00;
 
-	spin_lock_irqsave(&ac->lock, flags);
-	port = &ac->port[dir];
+	scoped_guard(spinlock_irqsave, &ac->lock) {
+		port = &ac->port[dir];
 
-	for (i = 0; i < num_regions; i++) {
-		ab = &port->buf[i];
-		mregions->shm_addr_lsw = lower_32_bits(ab->phys);
-		mregions->shm_addr_msw = upper_32_bits(ab->phys);
-		mregions->mem_size_bytes = buf_sz;
-		++mregions;
+		for (i = 0; i < num_regions; i++) {
+			ab = &port->buf[i];
+			mregions->shm_addr_lsw = lower_32_bits(ab->phys);
+			mregions->shm_addr_msw = upper_32_bits(ab->phys);
+			mregions->mem_size_bytes = buf_sz;
+			++mregions;
+		}
 	}
-	spin_unlock_irqrestore(&ac->lock, flags);
 
 	return q6asm_apr_send_session_pkt(a, ac, pkt, ASM_CMDRSP_SHARED_MEM_MAP_REGIONS);
 }
@@ -495,38 +489,32 @@ int q6asm_map_memory_regions(unsigned int dir, struct audio_client *ac,
 			     size_t period_sz, unsigned int periods)
 {
 	struct audio_buffer *buf;
-	unsigned long flags;
 	int cnt;
 	int rc;
 
-	spin_lock_irqsave(&ac->lock, flags);
-	if (ac->port[dir].buf) {
-		dev_err(ac->dev, "Buffer already allocated\n");
-		spin_unlock_irqrestore(&ac->lock, flags);
-		return 0;
-	}
-
-	buf = kzalloc_objs(*buf, periods, GFP_ATOMIC);
-	if (!buf) {
-		spin_unlock_irqrestore(&ac->lock, flags);
-		return -ENOMEM;
-	}
+	scoped_guard(spinlock_irqsave, &ac->lock) {
+		if (ac->port[dir].buf) {
+			dev_err(ac->dev, "Buffer already allocated\n");
+			return 0;
+		}
 
+		buf = kzalloc_objs(*buf, periods, GFP_ATOMIC);
+		if (!buf)
+			return -ENOMEM;
 
-	ac->port[dir].buf = buf;
+		ac->port[dir].buf = buf;
 
-	buf[0].phys = phys;
-	buf[0].size = period_sz;
+		buf[0].phys = phys;
+		buf[0].size = period_sz;
 
-	for (cnt = 1; cnt < periods; cnt++) {
-		if (period_sz > 0) {
-			buf[cnt].phys = buf[0].phys + (cnt * period_sz);
-			buf[cnt].size = period_sz;
+		for (cnt = 1; cnt < periods; cnt++) {
+			if (period_sz > 0) {
+				buf[cnt].phys = buf[0].phys + (cnt * period_sz);
+				buf[cnt].size = period_sz;
+			}
 		}
+		ac->port[dir].num_periods = periods;
 	}
-	ac->port[dir].num_periods = periods;
-
-	spin_unlock_irqrestore(&ac->lock, flags);
 
 	rc = __q6asm_memory_map_regions(ac, dir, period_sz, periods, 1);
 	if (rc < 0) {
@@ -542,14 +530,12 @@ static void q6asm_audio_client_release(struct kref *ref)
 {
 	struct audio_client *ac;
 	struct q6asm *a;
-	unsigned long flags;
 
 	ac = container_of(ref, struct audio_client, refcount);
 	a = ac->q6asm;
 
-	spin_lock_irqsave(&a->slock, flags);
-	a->session[ac->session] = NULL;
-	spin_unlock_irqrestore(&a->slock, flags);
+	scoped_guard(spinlock_irqsave, &a->slock)
+		a->session[ac->session] = NULL;
 
 	kfree(ac);
 }
@@ -842,7 +828,6 @@ struct audio_client *q6asm_audio_client_alloc(struct device *dev, q6asm_cb cb,
 {
 	struct q6asm *a = dev_get_drvdata(dev->parent);
 	struct audio_client *ac;
-	unsigned long flags;
 
 	ac = q6asm_get_audio_client(a, session_id + 1);
 	if (ac) {
@@ -854,9 +839,8 @@ struct audio_client *q6asm_audio_client_alloc(struct device *dev, q6asm_cb cb,
 	if (!ac)
 		return ERR_PTR(-ENOMEM);
 
-	spin_lock_irqsave(&a->slock, flags);
-	a->session[session_id + 1] = ac;
-	spin_unlock_irqrestore(&a->slock, flags);
+	scoped_guard(spinlock_irqsave, &a->slock)
+		a->session[session_id + 1] = ac;
 	ac->session = session_id + 1;
 	ac->cb = cb;
 	ac->dev = dev;
@@ -880,20 +864,19 @@ static int q6asm_ac_send_cmd_sync(struct audio_client *ac, struct apr_pkt *pkt)
 	struct apr_hdr *hdr = &pkt->hdr;
 	int rc;
 
-	mutex_lock(&ac->cmd_lock);
+	guard(mutex)(&ac->cmd_lock);
 	ac->result.opcode = 0;
 	ac->result.status = 0;
 
 	rc = apr_send_pkt(ac->adev, pkt);
 	if (rc < 0)
-		goto err;
+		return rc;
 
 	rc = wait_event_timeout(ac->cmd_wait,
 				(ac->result.opcode == hdr->opcode), 5 * HZ);
 	if (!rc) {
 		dev_err(ac->dev, "CMD %x timeout\n", hdr->opcode);
-		rc =  -ETIMEDOUT;
-		goto err;
+		return -ETIMEDOUT;
 	}
 
 	if (ac->result.status > 0) {
@@ -904,9 +887,6 @@ static int q6asm_ac_send_cmd_sync(struct audio_client *ac, struct apr_pkt *pkt)
 		rc = 0;
 	}
 
-
-err:
-	mutex_unlock(&ac->cmd_lock);
 	return rc;
 }
 
@@ -1402,7 +1382,6 @@ int q6asm_read(struct audio_client *ac, uint32_t stream_id)
 	struct audio_port_data *port;
 	struct audio_buffer *ab;
 	struct apr_pkt *pkt;
-	unsigned long flags;
 	int pkt_size = APR_HDR_SIZE + sizeof(*read);
 	int rc = 0;
 
@@ -1413,25 +1392,25 @@ int q6asm_read(struct audio_client *ac, uint32_t stream_id)
 	pkt = p;
 	read = p + APR_HDR_SIZE;
 
-	spin_lock_irqsave(&ac->lock, flags);
-	port = &ac->port[SNDRV_PCM_STREAM_CAPTURE];
-	q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
-	ab = &port->buf[port->dsp_buf];
-	pkt->hdr.opcode = ASM_DATA_CMD_READ_V2;
-	read->buf_addr_lsw = lower_32_bits(ab->phys);
-	read->buf_addr_msw = upper_32_bits(ab->phys);
-	read->mem_map_handle = port->mem_map_handle;
+	scoped_guard(spinlock_irqsave, &ac->lock) {
+		port = &ac->port[SNDRV_PCM_STREAM_CAPTURE];
+		q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
+		ab = &port->buf[port->dsp_buf];
+		pkt->hdr.opcode = ASM_DATA_CMD_READ_V2;
+		read->buf_addr_lsw = lower_32_bits(ab->phys);
+		read->buf_addr_msw = upper_32_bits(ab->phys);
+		read->mem_map_handle = port->mem_map_handle;
 
-	read->buf_size = ab->size;
-	read->seq_id = port->dsp_buf;
-	pkt->hdr.token = port->dsp_buf;
+		read->buf_size = ab->size;
+		read->seq_id = port->dsp_buf;
+		pkt->hdr.token = port->dsp_buf;
 
-	port->dsp_buf++;
+		port->dsp_buf++;
 
-	if (port->dsp_buf >= port->num_periods)
-		port->dsp_buf = 0;
+		if (port->dsp_buf >= port->num_periods)
+			port->dsp_buf = 0;
+	}
 
-	spin_unlock_irqrestore(&ac->lock, flags);
 	rc = apr_send_pkt(ac->adev, pkt);
 	if (rc == pkt_size)
 		rc = 0;
@@ -1515,7 +1494,6 @@ int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
 	struct asm_data_cmd_write_v2 *write;
 	struct audio_port_data *port;
 	struct audio_buffer *ab;
-	unsigned long flags;
 	struct apr_pkt *pkt;
 	int pkt_size = APR_HDR_SIZE + sizeof(*write);
 	int rc = 0;
@@ -1527,30 +1505,30 @@ int q6asm_write_async(struct audio_client *ac, uint32_t stream_id, uint32_t len,
 	pkt = p;
 	write = p + APR_HDR_SIZE;
 
-	spin_lock_irqsave(&ac->lock, flags);
-	port = &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
-	q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
+	scoped_guard(spinlock_irqsave, &ac->lock) {
+		port = &ac->port[SNDRV_PCM_STREAM_PLAYBACK];
+		q6asm_add_hdr(ac, &pkt->hdr, pkt_size, false, stream_id);
 
-	ab = &port->buf[port->dsp_buf];
-	pkt->hdr.token = port->dsp_buf | (len << ASM_WRITE_TOKEN_LEN_SHIFT);
-	pkt->hdr.opcode = ASM_DATA_CMD_WRITE_V2;
-	write->buf_addr_lsw = lower_32_bits(ab->phys);
-	write->buf_addr_msw = upper_32_bits(ab->phys);
-	write->buf_size = len;
-	write->seq_id = port->dsp_buf;
-	write->timestamp_lsw = lsw_ts;
-	write->timestamp_msw = msw_ts;
-	write->mem_map_handle =
-	    ac->port[SNDRV_PCM_STREAM_PLAYBACK].mem_map_handle;
+		ab = &port->buf[port->dsp_buf];
+		pkt->hdr.token = port->dsp_buf | (len << ASM_WRITE_TOKEN_LEN_SHIFT);
+		pkt->hdr.opcode = ASM_DATA_CMD_WRITE_V2;
+		write->buf_addr_lsw = lower_32_bits(ab->phys);
+		write->buf_addr_msw = upper_32_bits(ab->phys);
+		write->buf_size = len;
+		write->seq_id = port->dsp_buf;
+		write->timestamp_lsw = lsw_ts;
+		write->timestamp_msw = msw_ts;
+		write->mem_map_handle =
+		    ac->port[SNDRV_PCM_STREAM_PLAYBACK].mem_map_handle;
 
-	write->flags = wflags;
+		write->flags = wflags;
 
-	port->dsp_buf++;
+		port->dsp_buf++;
 
-	if (port->dsp_buf >= port->num_periods)
-		port->dsp_buf = 0;
+		if (port->dsp_buf >= port->num_periods)
+			port->dsp_buf = 0;
+	}
 
-	spin_unlock_irqrestore(&ac->lock, flags);
 	rc = apr_send_pkt(ac->adev, pkt);
 	if (rc == pkt_size)
 		rc = 0;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/9] ASoC: qdsp6: q6core: Use guard() for mutex locks
  2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
                   ` (4 preceding siblings ...)
  2026-06-03 11:49 ` [PATCH 5/9] ASoC: qcom: q6asm: Use guard() for mutex & spin locks phucduc.bui
@ 2026-06-03 11:49 ` phucduc.bui
  2026-06-03 11:49 ` [PATCH 7/9] ASoC: qdsp6: q6routing: " phucduc.bui
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

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/q6core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c
index 48825756a7ab..99cd4ea821a5 100644
--- a/sound/soc/qcom/qdsp6/q6core.c
+++ b/sound/soc/qcom/qdsp6/q6core.c
@@ -252,7 +252,7 @@ int q6core_get_svc_api_info(int svc_id, struct q6core_svc_api_info *ainfo)
 	if (!g_core || !ainfo)
 		return 0;
 
-	mutex_lock(&g_core->lock);
+	guard(mutex)(&g_core->lock);
 	if (!g_core->is_version_requested) {
 		if (q6core_get_fwk_versions(g_core) == -ENOTSUPP)
 			q6core_get_svc_versions(g_core);
@@ -287,8 +287,6 @@ int q6core_get_svc_api_info(int svc_id, struct q6core_svc_api_info *ainfo)
 		}
 	}
 
-	mutex_unlock(&g_core->lock);
-
 	return ret;
 }
 EXPORT_SYMBOL_GPL(q6core_get_svc_api_info);
@@ -306,7 +304,7 @@ bool q6core_is_adsp_ready(void)
 	if (!g_core)
 		return false;
 
-	mutex_lock(&g_core->lock);
+	guard(mutex)(&g_core->lock);
 	timeout = jiffies + msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
 	for (;;) {
 		if (__q6core_is_adsp_ready(g_core)) {
@@ -320,7 +318,6 @@ bool q6core_is_adsp_ready(void)
 		}
 	}
 
-	mutex_unlock(&g_core->lock);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(q6core_is_adsp_ready);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/9] ASoC: qdsp6: q6routing: Use guard() for mutex locks
  2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
                   ` (5 preceding siblings ...)
  2026-06-03 11:49 ` [PATCH 6/9] ASoC: qdsp6: q6core: Use guard() for mutex locks phucduc.bui
@ 2026-06-03 11:49 ` 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
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

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/q6routing.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6routing.c b/sound/soc/qcom/qdsp6/q6routing.c
index 7386226046fa..fff103b9dca1 100644
--- a/sound/soc/qcom/qdsp6/q6routing.c
+++ b/sound/soc/qcom/qdsp6/q6routing.c
@@ -381,7 +381,7 @@ int q6routing_stream_open(int fedai_id, int perf_mode,
 
 	pdata = &routing_data->port_data[session->port_id];
 
-	mutex_lock(&routing_data->lock);
+	guard(mutex)(&routing_data->lock);
 	session->fedai_id = fedai_id;
 
 	session->path_type = pdata->path_type;
@@ -396,10 +396,8 @@ int q6routing_stream_open(int fedai_id, int perf_mode,
 			      session->channels, topology, perf_mode,
 			      session->bits_per_sample, 0, 0);
 
-	if (IS_ERR_OR_NULL(copp)) {
-		mutex_unlock(&routing_data->lock);
+	if (IS_ERR_OR_NULL(copp))
 		return -EINVAL;
-	}
 
 	copp_idx = q6adm_get_copp_id(copp);
 	set_bit(copp_idx, &session->copp_map);
@@ -417,7 +415,6 @@ int q6routing_stream_open(int fedai_id, int perf_mode,
 		q6adm_matrix_map(routing_data->dev, session->path_type,
 				 payload, perf_mode);
 	}
-	mutex_unlock(&routing_data->lock);
 
 	return 0;
 }
@@ -1070,7 +1067,7 @@ static int routing_hw_params(struct snd_soc_component *component,
 
 	session = &data->port_data[be_id];
 
-	mutex_lock(&data->lock);
+	guard(mutex)(&data->lock);
 
 	session->path_type = path_type;
 	session->sample_rate = params_rate(params);
@@ -1087,7 +1084,6 @@ static int routing_hw_params(struct snd_soc_component *component,
 		break;
 	}
 
-	mutex_unlock(&data->lock);
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 8/9] ASoC: qdsp6: q6usb: Use guard() for mutex locks
  2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
                   ` (6 preceding siblings ...)
  2026-06-03 11:49 ` [PATCH 7/9] ASoC: qdsp6: q6routing: " phucduc.bui
@ 2026-06-03 11:49 ` phucduc.bui
  2026-06-03 11:49 ` [PATCH 9/9] ASoC: qcom: topology: " phucduc.bui
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

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/q6usb.c | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c
index 6381b289c55c..ee6de9635342 100644
--- a/sound/soc/qcom/qdsp6/q6usb.c
+++ b/sound/soc/qcom/qdsp6/q6usb.c
@@ -61,31 +61,28 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream,
 	struct snd_soc_usb_device *sdev;
 	int ret = -EINVAL;
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 
 	/* No active chip index */
 	if (list_empty(&data->devices))
-		goto out;
+		return ret;
 
 	sdev = list_last_entry(&data->devices, struct snd_soc_usb_device, list);
 
 	ret = snd_soc_usb_find_supported_format(sdev->chip_idx, params, direction);
 	if (ret < 0)
-		goto out;
+		return ret;
 
 	q6usb_afe = q6afe_port_get_from_id(cpu_dai->dev, USB_RX);
 	if (IS_ERR(q6usb_afe)) {
 		ret = PTR_ERR(q6usb_afe);
-		goto out;
+		return ret;
 	}
 
 	/* Notify audio DSP about the devices being offloaded */
 	ret = afe_port_send_usb_dev_param(q6usb_afe, sdev->card_idx,
 					  sdev->ppcm_idx[sdev->num_playback - 1]);
 
-out:
-	mutex_unlock(&data->mutex);
-
 	return ret;
 }
 
@@ -203,15 +200,14 @@ static int q6usb_update_offload_route(struct snd_soc_component *component, int c
 {
 	struct q6usb_port_data *data = dev_get_drvdata(component->dev);
 	struct snd_soc_usb_device *sdev;
-	int ret = 0;
 	int idx = -1;
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 
 	if (list_empty(&data->devices) ||
 	    direction == SNDRV_PCM_STREAM_CAPTURE) {
-		ret = -ENODEV;
-		goto out;
+		route[0] = idx;
+		return -ENODEV;
 	}
 
 	sdev = list_last_entry(&data->devices, struct snd_soc_usb_device, list);
@@ -227,11 +223,9 @@ static int q6usb_update_offload_route(struct snd_soc_component *component, int c
 				q6usb_get_pcm_id(component);
 	}
 
-out:
 	route[0] = idx;
-	mutex_unlock(&data->mutex);
 
-	return ret;
+	return 0;
 }
 
 static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb,
@@ -244,7 +238,7 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb,
 
 	data = dev_get_drvdata(usb->component->dev);
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 	if (connected) {
 		if (data->hs_jack)
 			snd_jack_report(data->hs_jack->jack, SND_JACK_USB);
@@ -257,7 +251,6 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb,
 		if (data->hs_jack)
 			snd_jack_report(data->hs_jack->jack, 0);
 	}
-	mutex_unlock(&data->mutex);
 
 	return 0;
 }
@@ -284,12 +277,11 @@ static int q6usb_component_set_jack(struct snd_soc_component *component,
 {
 	struct q6usb_port_data *data = dev_get_drvdata(component->dev);
 
-	mutex_lock(&data->mutex);
+	guard(mutex)(&data->mutex);
 	if (jack)
 		q6usb_component_enable_jack(data, jack);
 	else
 		q6usb_component_disable_jack(data);
-	mutex_unlock(&data->mutex);
 
 	return 0;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 9/9] ASoC: qcom: topology: Use guard() for mutex locks
  2026-06-03 11:49 [PATCH 0/9] ASoC: qcom: Use guard() for mutex & spin locks phucduc.bui
                   ` (7 preceding siblings ...)
  2026-06-03 11:49 ` [PATCH 8/9] ASoC: qdsp6: q6usb: " phucduc.bui
@ 2026-06-03 11:49 ` phucduc.bui
  8 siblings, 0 replies; 10+ messages in thread
From: phucduc.bui @ 2026-06-03 11:49 UTC (permalink / raw)
  To: Srinivas Kandagatla, Mark Brown
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Krzysztof Kozlowski,
	linux-sound, linux-arm-msm, linux-kernel, bui duc phuc

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/topology.c | 71 +++++++++++++++------------------
 1 file changed, 33 insertions(+), 38 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c
index 1f69fba6de26..efbbebb8c6d3 100644
--- a/sound/soc/qcom/qdsp6/topology.c
+++ b/sound/soc/qcom/qdsp6/topology.c
@@ -32,9 +32,8 @@ static struct audioreach_graph_info *audioreach_tplg_alloc_graph_info(struct q6a
 	struct audioreach_graph_info *info;
 	int ret;
 
-	mutex_lock(&apm->lock);
-	info = idr_find(&apm->graph_info_idr, graph_id);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		info = idr_find(&apm->graph_info_idr, graph_id);
 
 	if (info) {
 		*found = true;
@@ -48,9 +47,8 @@ static struct audioreach_graph_info *audioreach_tplg_alloc_graph_info(struct q6a
 
 	INIT_LIST_HEAD(&info->sg_list);
 
-	mutex_lock(&apm->lock);
-	ret = idr_alloc_u32(&apm->graph_info_idr, info, &graph_id, graph_id, GFP_KERNEL);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		ret = idr_alloc_u32(&apm->graph_info_idr, info, &graph_id, graph_id, GFP_KERNEL);
 
 	if (ret < 0) {
 		dev_err(apm->dev, "Failed to allocate Graph ID (%x)\n", graph_id);
@@ -82,9 +80,8 @@ static struct audioreach_sub_graph *audioreach_tplg_alloc_sub_graph(struct q6apm
 		return ERR_PTR(-EINVAL);
 
 	/* Find if there is already a matching sub-graph */
-	mutex_lock(&apm->lock);
-	sg = idr_find(&apm->sub_graphs_idr, sub_graph_id);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		sg = idr_find(&apm->sub_graphs_idr, sub_graph_id);
 
 	if (sg) {
 		*found = true;
@@ -98,9 +95,10 @@ static struct audioreach_sub_graph *audioreach_tplg_alloc_sub_graph(struct q6apm
 
 	INIT_LIST_HEAD(&sg->container_list);
 
-	mutex_lock(&apm->lock);
-	ret = idr_alloc_u32(&apm->sub_graphs_idr, sg, &sub_graph_id, sub_graph_id, GFP_KERNEL);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		ret = idr_alloc_u32(&apm->sub_graphs_idr, sg,
+				&sub_graph_id, sub_graph_id,
+				GFP_KERNEL);
 
 	if (ret < 0) {
 		dev_err(apm->dev, "Failed to allocate Sub-Graph Instance ID (%x)\n", sub_graph_id);
@@ -124,9 +122,8 @@ static struct audioreach_container *audioreach_tplg_alloc_container(struct q6apm
 	if (!container_id)
 		return ERR_PTR(-EINVAL);
 
-	mutex_lock(&apm->lock);
-	cont = idr_find(&apm->containers_idr, container_id);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		cont = idr_find(&apm->containers_idr, container_id);
 
 	if (cont) {
 		*found = true;
@@ -140,9 +137,10 @@ static struct audioreach_container *audioreach_tplg_alloc_container(struct q6apm
 
 	INIT_LIST_HEAD(&cont->modules_list);
 
-	mutex_lock(&apm->lock);
-	ret = idr_alloc_u32(&apm->containers_idr, cont, &container_id, container_id, GFP_KERNEL);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		ret = idr_alloc_u32(&apm->containers_idr, cont,
+				&container_id, container_id,
+				GFP_KERNEL);
 
 	if (ret < 0) {
 		dev_err(apm->dev, "Failed to allocate Container Instance ID (%x)\n", container_id);
@@ -167,9 +165,8 @@ static struct audioreach_module *audioreach_tplg_alloc_module(struct q6apm *apm,
 	struct audioreach_module *mod;
 	int ret;
 
-	mutex_lock(&apm->lock);
-	mod = idr_find(&apm->modules_idr, module_id);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		mod = idr_find(&apm->modules_idr, module_id);
 
 	if (mod) {
 		*found = true;
@@ -180,15 +177,17 @@ static struct audioreach_module *audioreach_tplg_alloc_module(struct q6apm *apm,
 	if (!mod)
 		return ERR_PTR(-ENOMEM);
 
-	mutex_lock(&apm->lock);
-	if (!module_id) { /* alloc module id dynamically */
-		ret = idr_alloc_cyclic(&apm->modules_idr, mod,
-				       AR_MODULE_DYNAMIC_INSTANCE_ID_START,
-				       AR_MODULE_DYNAMIC_INSTANCE_ID_END, GFP_KERNEL);
-	} else {
-		ret = idr_alloc_u32(&apm->modules_idr, mod, &module_id, module_id, GFP_KERNEL);
+	scoped_guard(mutex, &apm->lock) {
+		if (!module_id) { /* alloc module id dynamically */
+			ret = idr_alloc_cyclic(&apm->modules_idr, mod,
+					       AR_MODULE_DYNAMIC_INSTANCE_ID_START,
+					       AR_MODULE_DYNAMIC_INSTANCE_ID_END, GFP_KERNEL);
+		} else {
+			ret = idr_alloc_u32(&apm->modules_idr, mod,
+					&module_id, module_id,
+					GFP_KERNEL);
+		}
 	}
-	mutex_unlock(&apm->lock);
 
 	if (ret < 0) {
 		dev_err(apm->dev, "Failed to allocate Module Instance ID (%x)\n", module_id);
@@ -966,7 +965,7 @@ static int audioreach_widget_unload(struct snd_soc_component *scomp,
 
 	cont = mod->container;
 
-	mutex_lock(&apm->lock);
+	guard(mutex)(&apm->lock);
 	idr_remove(&apm->modules_idr, mod->instance_id);
 	cont->num_modules--;
 
@@ -997,8 +996,6 @@ static int audioreach_widget_unload(struct snd_soc_component *scomp,
 		}
 	}
 
-	mutex_unlock(&apm->lock);
-
 	return 0;
 }
 
@@ -1106,9 +1103,8 @@ static void audioreach_connect_sub_graphs(struct q6apm *apm,
 {
 	struct audioreach_graph_info *info;
 
-	mutex_lock(&apm->lock);
-	info = idr_find(&apm->graph_info_idr, m2->graph_id);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		info = idr_find(&apm->graph_info_idr, m2->graph_id);
 
 	if (connect) {
 		info->src_mod_inst_id = m1->module_instance_id;
@@ -1130,9 +1126,8 @@ static bool audioreach_is_vmixer_connected(struct q6apm *apm,
 {
 	const struct audioreach_graph_info *info;
 
-	mutex_lock(&apm->lock);
-	info = idr_find(&apm->graph_info_idr, m2->graph_id);
-	mutex_unlock(&apm->lock);
+	scoped_guard(mutex, &apm->lock)
+		info = idr_find(&apm->graph_info_idr, m2->graph_id);
 
 	if (info->dst_mod_inst_id == m2->module_instance_id &&
 	    info->src_mod_inst_id == m1->module_instance_id)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-06-03 11:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 4/9] ASoC: qcom: q6apm: " phucduc.bui
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox