Re: [PATCH 04/20] ASoC: Intel: avs: probes: Use guard() for spin locks
From: Cezary Rojewski
Date: Thu Jun 11 2026 - 15:34:38 EST
On 6/11/2026 1:58 PM, phucduc.bui@xxxxxxxxx wrote:
From: bui duc phuc <phucduc.bui@xxxxxxxxx>
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Signed-off-by: bui duc phuc <phucduc.bui@xxxxxxxxx>
---
sound/soc/intel/avs/probes.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/sound/soc/intel/avs/probes.c b/sound/soc/intel/avs/probes.c
index 099119ad28b3..13d933ab77cd 100644
--- a/sound/soc/intel/avs/probes.c
+++ b/sound/soc/intel/avs/probes.c
@@ -186,7 +186,6 @@ static int avs_probe_compr_trigger(struct snd_compr_stream *cstream, int cmd,
struct hdac_ext_stream *host_stream = avs_compr_get_host_stream(cstream);
struct avs_dev *adev = to_avs_dev(dai->dev);
struct hdac_bus *bus = &adev->base.core;
- unsigned long cookie;
if (!hdac_stream(host_stream)->prepared)
return -EPIPE;
@@ -195,17 +194,15 @@ static int avs_probe_compr_trigger(struct snd_compr_stream *cstream, int cmd,
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
case SNDRV_PCM_TRIGGER_RESUME:
- spin_lock_irqsave(&bus->reg_lock, cookie);
- snd_hdac_stream_start(hdac_stream(host_stream));
- spin_unlock_irqrestore(&bus->reg_lock, cookie);
+ scoped_guard(spinlock_irqsave, &bus->reg_lock)
+ snd_hdac_stream_start(hdac_stream(host_stream));
Well, maybe one patch per driver suggestion of mine was a little too much.. Let's separate guard() changes from scoped_guard() ones. guard()s carry no readability cost.
I'm not a fan of scoped_guard() update for any existing code block that looks like below:
lock()
one_liner()
unlock()
Adding tab to the picture ruins readability. The cost of tab is OK if there are more operations between the locking/unlocking though.
break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_STOP:
- spin_lock_irqsave(&bus->reg_lock, cookie);
- snd_hdac_stream_stop(hdac_stream(host_stream));
- spin_unlock_irqrestore(&bus->reg_lock, cookie);
+ scoped_guard(spinlock_irqsave, &bus->reg_lock)
+ snd_hdac_stream_stop(hdac_stream(host_stream));
break;
default: