* [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
@ 2026-06-10 10:21 phucduc.bui
2026-06-10 12:54 ` Jerome Brunet
2026-06-11 19:42 ` Mark Brown
0 siblings, 2 replies; 7+ messages in thread
From: phucduc.bui @ 2026-06-10 10:21 UTC (permalink / raw)
To: Mark Brown, Jerome Brunet
Cc: Liam Girdwood, Neil Armstrong, Kevin Hilman, Martin Blumenstingl,
Jaroslav Kysela, Takashi Iwai, linux-sound, linux-arm-kernel,
linux-amlogic, 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>
---
sound/soc/meson/axg-tdm-formatter.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/sound/soc/meson/axg-tdm-formatter.c b/sound/soc/meson/axg-tdm-formatter.c
index f451e4dce442..a6ba401104d5 100644
--- a/sound/soc/meson/axg-tdm-formatter.c
+++ b/sound/soc/meson/axg-tdm-formatter.c
@@ -157,20 +157,19 @@ static int axg_tdm_formatter_attach(struct axg_tdm_formatter *formatter)
struct axg_tdm_stream *ts = formatter->stream;
int ret = 0;
- mutex_lock(&ts->lock);
+ guard(mutex)(&ts->lock);
/* Catch up if the stream is already running when we attach */
if (ts->ready) {
ret = axg_tdm_formatter_enable(formatter);
if (ret) {
pr_err("failed to enable formatter\n");
- goto out;
+ return ret;
}
}
list_add_tail(&formatter->list, &ts->formatter_list);
-out:
- mutex_unlock(&ts->lock);
+
return ret;
}
@@ -178,9 +177,8 @@ static void axg_tdm_formatter_dettach(struct axg_tdm_formatter *formatter)
{
struct axg_tdm_stream *ts = formatter->stream;
- mutex_lock(&ts->lock);
- list_del(&formatter->list);
- mutex_unlock(&ts->lock);
+ scoped_guard(mutex, &ts->lock)
+ list_del(&formatter->list);
axg_tdm_formatter_disable(formatter);
}
@@ -330,7 +328,7 @@ int axg_tdm_stream_start(struct axg_tdm_stream *ts)
struct axg_tdm_formatter *formatter;
int ret = 0;
- mutex_lock(&ts->lock);
+ guard(mutex)(&ts->lock);
ts->ready = true;
/* Start all the formatters attached to the stream */
@@ -338,12 +336,10 @@ int axg_tdm_stream_start(struct axg_tdm_stream *ts)
ret = axg_tdm_formatter_enable(formatter);
if (ret) {
pr_err("failed to start tdm stream\n");
- goto out;
+ return ret;
}
}
-out:
- mutex_unlock(&ts->lock);
return ret;
}
EXPORT_SYMBOL_GPL(axg_tdm_stream_start);
@@ -352,15 +348,13 @@ void axg_tdm_stream_stop(struct axg_tdm_stream *ts)
{
struct axg_tdm_formatter *formatter;
- mutex_lock(&ts->lock);
+ guard(mutex)(&ts->lock);
ts->ready = false;
/* Stop all the formatters attached to the stream */
list_for_each_entry(formatter, &ts->formatter_list, list) {
axg_tdm_formatter_disable(formatter);
}
-
- mutex_unlock(&ts->lock);
}
EXPORT_SYMBOL_GPL(axg_tdm_stream_stop);
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
2026-06-10 10:21 [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks phucduc.bui
@ 2026-06-10 12:54 ` Jerome Brunet
2026-06-10 15:46 ` Mark Brown
2026-06-10 16:27 ` Bui Duc Phuc
2026-06-11 19:42 ` Mark Brown
1 sibling, 2 replies; 7+ messages in thread
From: Jerome Brunet @ 2026-06-10 12:54 UTC (permalink / raw)
To: phucduc.bui
Cc: Mark Brown, Liam Girdwood, Neil Armstrong, Kevin Hilman,
Martin Blumenstingl, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-arm-kernel, linux-amlogic, linux-kernel
On mer. 10 juin 2026 at 17:21, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
>
> Clean up the code using guard() for mutex locks.
> Merely code refactoring, and no behavior change.
I suppose it is OK but it does not seem to really clean anything and
make the code easier to follow in that instance, from my perspective at
least.
If there is policy to systematically use guard() whenever
possible then OK, otherwise it seems unnecessary.
>
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
> ---
> sound/soc/meson/axg-tdm-formatter.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/sound/soc/meson/axg-tdm-formatter.c b/sound/soc/meson/axg-tdm-formatter.c
> index f451e4dce442..a6ba401104d5 100644
> --- a/sound/soc/meson/axg-tdm-formatter.c
> +++ b/sound/soc/meson/axg-tdm-formatter.c
> @@ -157,20 +157,19 @@ static int axg_tdm_formatter_attach(struct axg_tdm_formatter *formatter)
> struct axg_tdm_stream *ts = formatter->stream;
> int ret = 0;
>
> - mutex_lock(&ts->lock);
> + guard(mutex)(&ts->lock);
>
> /* Catch up if the stream is already running when we attach */
> if (ts->ready) {
> ret = axg_tdm_formatter_enable(formatter);
> if (ret) {
> pr_err("failed to enable formatter\n");
> - goto out;
> + return ret;
> }
> }
>
> list_add_tail(&formatter->list, &ts->formatter_list);
> -out:
> - mutex_unlock(&ts->lock);
> +
> return ret;
> }
>
> @@ -178,9 +177,8 @@ static void axg_tdm_formatter_dettach(struct axg_tdm_formatter *formatter)
> {
> struct axg_tdm_stream *ts = formatter->stream;
>
> - mutex_lock(&ts->lock);
> - list_del(&formatter->list);
> - mutex_unlock(&ts->lock);
> + scoped_guard(mutex, &ts->lock)
> + list_del(&formatter->list);
>
> axg_tdm_formatter_disable(formatter);
> }
> @@ -330,7 +328,7 @@ int axg_tdm_stream_start(struct axg_tdm_stream *ts)
> struct axg_tdm_formatter *formatter;
> int ret = 0;
>
> - mutex_lock(&ts->lock);
> + guard(mutex)(&ts->lock);
> ts->ready = true;
>
> /* Start all the formatters attached to the stream */
> @@ -338,12 +336,10 @@ int axg_tdm_stream_start(struct axg_tdm_stream *ts)
> ret = axg_tdm_formatter_enable(formatter);
> if (ret) {
> pr_err("failed to start tdm stream\n");
> - goto out;
> + return ret;
> }
> }
>
> -out:
> - mutex_unlock(&ts->lock);
> return ret;
> }
> EXPORT_SYMBOL_GPL(axg_tdm_stream_start);
> @@ -352,15 +348,13 @@ void axg_tdm_stream_stop(struct axg_tdm_stream *ts)
> {
> struct axg_tdm_formatter *formatter;
>
> - mutex_lock(&ts->lock);
> + guard(mutex)(&ts->lock);
> ts->ready = false;
>
> /* Stop all the formatters attached to the stream */
> list_for_each_entry(formatter, &ts->formatter_list, list) {
> axg_tdm_formatter_disable(formatter);
> }
> -
> - mutex_unlock(&ts->lock);
> }
> EXPORT_SYMBOL_GPL(axg_tdm_stream_stop);
--
Jerome
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
2026-06-10 12:54 ` Jerome Brunet
@ 2026-06-10 15:46 ` Mark Brown
2026-06-10 16:27 ` Bui Duc Phuc
1 sibling, 0 replies; 7+ messages in thread
From: Mark Brown @ 2026-06-10 15:46 UTC (permalink / raw)
To: Jerome Brunet
Cc: phucduc.bui, Liam Girdwood, Neil Armstrong, Kevin Hilman,
Martin Blumenstingl, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-arm-kernel, linux-amlogic, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 608 bytes --]
On Wed, Jun 10, 2026 at 02:54:08PM +0200, Jerome Brunet wrote:
> On mer. 10 juin 2026 at 17:21, phucduc.bui@gmail.com wrote:
> > Clean up the code using guard() for mutex locks.
> > Merely code refactoring, and no behavior change.
> I suppose it is OK but it does not seem to really clean anything and
> make the code easier to follow in that instance, from my perspective at
> least.
> If there is policy to systematically use guard() whenever
> possible then OK, otherwise it seems unnecessary.
I don't know about policy but there's definitely people who are keen on
converting things to this pattern.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
2026-06-10 12:54 ` Jerome Brunet
2026-06-10 15:46 ` Mark Brown
@ 2026-06-10 16:27 ` Bui Duc Phuc
2026-06-11 8:10 ` Jerome Brunet
1 sibling, 1 reply; 7+ messages in thread
From: Bui Duc Phuc @ 2026-06-10 16:27 UTC (permalink / raw)
To: Jerome Brunet
Cc: Mark Brown, Liam Girdwood, Neil Armstrong, Kevin Hilman,
Martin Blumenstingl, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-arm-kernel, linux-amlogic, linux-kernel
Hi Jerome,
Thank you for your feedback,
>
> I suppose it is OK but it does not seem to really clean anything and
> make the code easier to follow in that instance, from my perspective at
> least.
>
> If there is policy to systematically use guard() whenever
> possible then OK, otherwise it seems unnecessary.
>
I have noticed that guard() has been adopted in several subsystems.
Since this appears to be the only place in the Meson ASoC code currently using
mutex_lock()/mutex_unlock(), I converted it for consistency with the
newer style.
Going forward, should new Meson ASoC code use guard(), or should it continue
using the traditional mutex_lock()/mutex_unlock() pattern?
Best regards,
Phuc
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
2026-06-10 16:27 ` Bui Duc Phuc
@ 2026-06-11 8:10 ` Jerome Brunet
2026-06-12 2:36 ` Bui Duc Phuc
0 siblings, 1 reply; 7+ messages in thread
From: Jerome Brunet @ 2026-06-11 8:10 UTC (permalink / raw)
To: Bui Duc Phuc
Cc: Mark Brown, Liam Girdwood, Neil Armstrong, Kevin Hilman,
Martin Blumenstingl, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-arm-kernel, linux-amlogic, linux-kernel
On mer. 10 juin 2026 at 23:27, Bui Duc Phuc <phucduc.bui@gmail.com> wrote:
> Hi Jerome,
>
> Thank you for your feedback,
>
>>
>> I suppose it is OK but it does not seem to really clean anything and
>> make the code easier to follow in that instance, from my perspective at
>> least.
>>
>> If there is policy to systematically use guard() whenever
>> possible then OK, otherwise it seems unnecessary.
>>
>
> I have noticed that guard() has been adopted in several subsystems.
> Since this appears to be the only place in the Meson ASoC code currently using
> mutex_lock()/mutex_unlock(), I converted it for consistency with the
> newer style.
>
> Going forward, should new Meson ASoC code use guard(), or should it continue
> using the traditional mutex_lock()/mutex_unlock() pattern?
Can't say if there is such policy either. IMO it should be more a
case-by-case thing
The code is not better or worse with the change but you went through the
trouble of doing so, if Mark is fine with it, let's have it
Reviewed-by: Jerome Brunet <jbrunet@baylibre.com>
>
> Best regards,
> Phuc
--
Jerome
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
2026-06-11 8:10 ` Jerome Brunet
@ 2026-06-12 2:36 ` Bui Duc Phuc
0 siblings, 0 replies; 7+ messages in thread
From: Bui Duc Phuc @ 2026-06-12 2:36 UTC (permalink / raw)
To: Jerome Brunet
Cc: Mark Brown, Liam Girdwood, Neil Armstrong, Kevin Hilman,
Martin Blumenstingl, Jaroslav Kysela, Takashi Iwai, linux-sound,
linux-arm-kernel, linux-amlogic, linux-kernel
Hi Jerome,
Thank you for the review and for the Reviewed-by tag.
>
> The code is not better or worse with the change but you went through the
> trouble of doing so, if Mark is fine with it, let's have it
>
> Reviewed-by: Jerome Brunet <jbrunet@baylibre.com>
>
Regarding the point about whether the change makes the code better or worse,
I have sent an additional patch to address related cleanup in the same area:
https://lore.kernel.org/all/20260612020113.9557-1-phucduc.bui@gmail.com/
Would appreciate your review on that as well.
While looking into the Meson ASoC probe paths,
I noticed a few consistency issues that seem to appear across multiple drivers:
1. Mixed usage of dev_err_probe() and dev_err() in probe error paths.
2. Inconsistent error message formatting: some messages start with lowercase
("failed to init..."), while others start with uppercase ("Failed
to register...").
3. In aiu_probe(), error paths for IRQ retrieval do not provide
additional context,
making it harder to identify which resource failed:
aiu->i2s.irq = platform_get_irq_byname(pdev, "i2s");
if (aiu->i2s.irq < 0)
return aiu->i2s.irq;
aiu->spdif.irq = platform_get_irq_byname(pdev, "spdif");
if (aiu->spdif.irq < 0)
return aiu->spdif.irq;
4 ......
Do you think addressing these issues would improve readability and
maintainability of the Meson codebase over time?
Or is it generally preferred to leave these kinds of consistency
improvements untouched unless a functional bug is being fixed?
Best regards,
Phuc
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
2026-06-10 10:21 [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks phucduc.bui
2026-06-10 12:54 ` Jerome Brunet
@ 2026-06-11 19:42 ` Mark Brown
1 sibling, 0 replies; 7+ messages in thread
From: Mark Brown @ 2026-06-11 19:42 UTC (permalink / raw)
To: Jerome Brunet, phucduc.bui
Cc: Liam Girdwood, Neil Armstrong, Kevin Hilman, Martin Blumenstingl,
Jaroslav Kysela, Takashi Iwai, linux-sound, linux-arm-kernel,
linux-amlogic, linux-kernel
On Wed, 10 Jun 2026 17:21:53 +0700, phucduc.bui@gmail.com wrote:
> ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2
Thanks!
[1/1] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks
https://git.kernel.org/broonie/sound/c/a68bbd4ac1b1
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-06-12 22:19 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-10 10:21 [PATCH] ASoC: meson: axg-tdm-formatter: Use guard() for mutex locks phucduc.bui
2026-06-10 12:54 ` Jerome Brunet
2026-06-10 15:46 ` Mark Brown
2026-06-10 16:27 ` Bui Duc Phuc
2026-06-11 8:10 ` Jerome Brunet
2026-06-12 2:36 ` Bui Duc Phuc
2026-06-11 19:42 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox