ALSA: x86: 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/20250829151335.7342-8-tiwai@suse.de
This commit is contained in:
Takashi Iwai 2025-08-29 17:13:21 +02:00
parent 10403f910a
commit ab770b4163
1 changed files with 39 additions and 54 deletions

View File

@ -171,13 +171,11 @@ static struct snd_pcm_substream *
had_substream_get(struct snd_intelhad *intelhaddata) had_substream_get(struct snd_intelhad *intelhaddata)
{ {
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
unsigned long flags;
spin_lock_irqsave(&intelhaddata->had_spinlock, flags); guard(spinlock_irqsave)(&intelhaddata->had_spinlock);
substream = intelhaddata->stream_info.substream; substream = intelhaddata->stream_info.substream;
if (substream) if (substream)
intelhaddata->stream_info.substream_refcount++; intelhaddata->stream_info.substream_refcount++;
spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
return substream; return substream;
} }
@ -186,11 +184,8 @@ had_substream_get(struct snd_intelhad *intelhaddata)
*/ */
static void had_substream_put(struct snd_intelhad *intelhaddata) static void had_substream_put(struct snd_intelhad *intelhaddata)
{ {
unsigned long flags; guard(spinlock_irqsave)(&intelhaddata->had_spinlock);
spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
intelhaddata->stream_info.substream_refcount--; intelhaddata->stream_info.substream_refcount--;
spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
} }
static u32 had_config_offset(int pipe) static u32 had_config_offset(int pipe)
@ -946,10 +941,9 @@ static int had_process_ringbuf(struct snd_pcm_substream *substream,
struct snd_intelhad *intelhaddata) struct snd_intelhad *intelhaddata)
{ {
int len, processed; int len, processed;
unsigned long flags;
processed = 0; processed = 0;
spin_lock_irqsave(&intelhaddata->had_spinlock, flags); guard(spinlock_irqsave)(&intelhaddata->had_spinlock);
for (;;) { for (;;) {
/* get the remaining bytes on the buffer */ /* get the remaining bytes on the buffer */
had_read_register(intelhaddata, had_read_register(intelhaddata,
@ -958,25 +952,20 @@ static int had_process_ringbuf(struct snd_pcm_substream *substream,
if (len < 0 || len > intelhaddata->period_bytes) { if (len < 0 || len > intelhaddata->period_bytes) {
dev_dbg(intelhaddata->dev, "Invalid buf length %d\n", dev_dbg(intelhaddata->dev, "Invalid buf length %d\n",
len); len);
len = -EPIPE; return -EPIPE;
goto out;
} }
if (len > 0) /* OK, this is the current buffer */ if (len > 0) /* OK, this is the current buffer */
break; break;
/* len=0 => already empty, check the next buffer */ /* len=0 => already empty, check the next buffer */
if (++processed >= intelhaddata->num_bds) { if (++processed >= intelhaddata->num_bds)
len = -EPIPE; /* all empty? - report underrun */ return -EPIPE; /* all empty? - report underrun */
goto out;
}
had_advance_ringbuf(substream, intelhaddata); had_advance_ringbuf(substream, intelhaddata);
} }
len = intelhaddata->period_bytes - len; len = intelhaddata->period_bytes - len;
len += intelhaddata->period_bytes * intelhaddata->pcmbuf_head; len += intelhaddata->period_bytes * intelhaddata->pcmbuf_head;
out:
spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
return len; return len;
} }
@ -1092,10 +1081,10 @@ static int had_pcm_open(struct snd_pcm_substream *substream)
goto error; goto error;
/* expose PCM substream */ /* expose PCM substream */
spin_lock_irq(&intelhaddata->had_spinlock); scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) {
intelhaddata->stream_info.substream = substream; intelhaddata->stream_info.substream = substream;
intelhaddata->stream_info.substream_refcount++; intelhaddata->stream_info.substream_refcount++;
spin_unlock_irq(&intelhaddata->had_spinlock); }
return retval; return retval;
error: error:
@ -1153,7 +1142,7 @@ static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
intelhaddata = snd_pcm_substream_chip(substream); intelhaddata = snd_pcm_substream_chip(substream);
spin_lock(&intelhaddata->had_spinlock); guard(spinlock)(&intelhaddata->had_spinlock);
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@ -1172,7 +1161,6 @@ static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
default: default:
retval = -EINVAL; retval = -EINVAL;
} }
spin_unlock(&intelhaddata->had_spinlock);
return retval; return retval;
} }
@ -1311,21 +1299,20 @@ static void had_process_hot_plug(struct snd_intelhad *intelhaddata)
{ {
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
spin_lock_irq(&intelhaddata->had_spinlock); scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) {
if (intelhaddata->connected) { if (intelhaddata->connected) {
dev_dbg(intelhaddata->dev, "Device already connected\n"); dev_dbg(intelhaddata->dev, "Device already connected\n");
spin_unlock_irq(&intelhaddata->had_spinlock); return;
return; }
}
/* Disable Audio */ /* Disable Audio */
had_enable_audio(intelhaddata, false); had_enable_audio(intelhaddata, false);
intelhaddata->connected = true; intelhaddata->connected = true;
dev_dbg(intelhaddata->dev, dev_dbg(intelhaddata->dev,
"%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n", "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n",
__func__, __LINE__); __func__, __LINE__);
spin_unlock_irq(&intelhaddata->had_spinlock); }
had_build_channel_allocation_map(intelhaddata); had_build_channel_allocation_map(intelhaddata);
@ -1344,22 +1331,20 @@ static void had_process_hot_unplug(struct snd_intelhad *intelhaddata)
{ {
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
spin_lock_irq(&intelhaddata->had_spinlock); scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) {
if (!intelhaddata->connected) { if (!intelhaddata->connected) {
dev_dbg(intelhaddata->dev, "Device already disconnected\n"); dev_dbg(intelhaddata->dev, "Device already disconnected\n");
spin_unlock_irq(&intelhaddata->had_spinlock); return;
return; }
} /* Disable Audio */
had_enable_audio(intelhaddata, false);
/* Disable Audio */ intelhaddata->connected = false;
had_enable_audio(intelhaddata, false); dev_dbg(intelhaddata->dev,
"%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n",
intelhaddata->connected = false;
dev_dbg(intelhaddata->dev,
"%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n",
__func__, __LINE__); __func__, __LINE__);
spin_unlock_irq(&intelhaddata->had_spinlock); }
kfree(intelhaddata->chmap->chmap); kfree(intelhaddata->chmap->chmap);
intelhaddata->chmap->chmap = NULL; intelhaddata->chmap->chmap = NULL;
@ -1636,9 +1621,9 @@ static void hdmi_lpe_audio_free(struct snd_card *card)
struct intel_hdmi_lpe_audio_pdata *pdata = card_ctx->dev->platform_data; struct intel_hdmi_lpe_audio_pdata *pdata = card_ctx->dev->platform_data;
int port; int port;
spin_lock_irq(&pdata->lpe_audio_slock); scoped_guard(spinlock_irq, &pdata->lpe_audio_slock) {
pdata->notify_audio_lpe = NULL; pdata->notify_audio_lpe = NULL;
spin_unlock_irq(&pdata->lpe_audio_slock); }
for_each_port(card_ctx, port) { for_each_port(card_ctx, port) {
struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port]; struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
@ -1799,9 +1784,9 @@ static int __hdmi_lpe_audio_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
spin_lock_irq(&pdata->lpe_audio_slock); scoped_guard(spinlock_irq, &pdata->lpe_audio_slock) {
pdata->notify_audio_lpe = notify_audio_lpe; pdata->notify_audio_lpe = notify_audio_lpe;
spin_unlock_irq(&pdata->lpe_audio_slock); }
pm_runtime_set_autosuspend_delay(&pdev->dev, INTEL_HDMI_AUDIO_SUSPEND_DELAY_MS); pm_runtime_set_autosuspend_delay(&pdev->dev, INTEL_HDMI_AUDIO_SUSPEND_DELAY_MS);
pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_use_autosuspend(&pdev->dev);