ALSA: hiface: Use guard() for spin locks

Clean up the code using guard() for spin locks.

Merely code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829150724.6886-6-tiwai@suse.de
pull/476/head
Takashi Iwai 2025-08-29 17:07:13 +02:00
parent 07f55c77b9
commit ea3bfbbc9a
1 changed files with 14 additions and 21 deletions

View File

@ -305,7 +305,6 @@ static void hiface_pcm_out_urb_handler(struct urb *usb_urb)
struct pcm_runtime *rt = out_urb->chip->pcm;
struct pcm_substream *sub;
bool do_period_elapsed = false;
unsigned long flags;
int ret;
if (rt->panic || rt->stream_state == STREAM_STOPPING)
@ -325,13 +324,12 @@ static void hiface_pcm_out_urb_handler(struct urb *usb_urb)
/* now send our playback data (if a free out urb was found) */
sub = &rt->playback;
spin_lock_irqsave(&sub->lock, flags);
if (sub->active)
do_period_elapsed = hiface_pcm_playback(sub, out_urb);
else
memset(out_urb->buffer, 0, PCM_PACKET_SIZE);
spin_unlock_irqrestore(&sub->lock, flags);
scoped_guard(spinlock_irqsave, &sub->lock) {
if (sub->active)
do_period_elapsed = hiface_pcm_playback(sub, out_urb);
else
memset(out_urb->buffer, 0, PCM_PACKET_SIZE);
}
if (do_period_elapsed)
snd_pcm_period_elapsed(sub->instance);
@ -389,7 +387,6 @@ static int hiface_pcm_close(struct snd_pcm_substream *alsa_sub)
{
struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
struct pcm_substream *sub = hiface_pcm_get_substream(alsa_sub);
unsigned long flags;
if (rt->panic)
return 0;
@ -399,11 +396,9 @@ static int hiface_pcm_close(struct snd_pcm_substream *alsa_sub)
hiface_pcm_stream_stop(rt);
/* deactivate substream */
spin_lock_irqsave(&sub->lock, flags);
guard(spinlock_irqsave)(&sub->lock);
sub->instance = NULL;
sub->active = false;
spin_unlock_irqrestore(&sub->lock, flags);
}
return 0;
}
@ -452,16 +447,16 @@ static int hiface_pcm_trigger(struct snd_pcm_substream *alsa_sub, int cmd)
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
spin_lock_irq(&sub->lock);
sub->active = true;
spin_unlock_irq(&sub->lock);
scoped_guard(spinlock_irq, &sub->lock) {
sub->active = true;
}
return 0;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
spin_lock_irq(&sub->lock);
sub->active = false;
spin_unlock_irq(&sub->lock);
scoped_guard(spinlock_irq, &sub->lock) {
sub->active = false;
}
return 0;
default:
@ -473,15 +468,13 @@ static snd_pcm_uframes_t hiface_pcm_pointer(struct snd_pcm_substream *alsa_sub)
{
struct pcm_substream *sub = hiface_pcm_get_substream(alsa_sub);
struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub);
unsigned long flags;
snd_pcm_uframes_t dma_offset;
if (rt->panic || !sub)
return SNDRV_PCM_POS_XRUN;
spin_lock_irqsave(&sub->lock, flags);
guard(spinlock_irqsave)(&sub->lock);
dma_offset = sub->dma_off;
spin_unlock_irqrestore(&sub->lock, flags);
return bytes_to_frames(alsa_sub->runtime, dma_offset);
}