Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: caiaq: 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-10-tiwai@suse.de

+13 -26
+13 -26
sound/usb/caiaq/audio.c
··· 51 51 activate_substream(struct snd_usb_caiaqdev *cdev, 52 52 struct snd_pcm_substream *sub) 53 53 { 54 - spin_lock(&cdev->spinlock); 54 + guard(spinlock)(&cdev->spinlock); 55 55 56 56 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 57 57 cdev->sub_playback[sub->number] = sub; 58 58 else 59 59 cdev->sub_capture[sub->number] = sub; 60 - 61 - spin_unlock(&cdev->spinlock); 62 60 } 63 61 64 62 static void 65 63 deactivate_substream(struct snd_usb_caiaqdev *cdev, 66 64 struct snd_pcm_substream *sub) 67 65 { 68 - unsigned long flags; 69 - spin_lock_irqsave(&cdev->spinlock, flags); 66 + guard(spinlock_irqsave)(&cdev->spinlock); 70 67 71 68 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 72 69 cdev->sub_playback[sub->number] = NULL; 73 70 else 74 71 cdev->sub_capture[sub->number] = NULL; 75 - 76 - spin_unlock_irqrestore(&cdev->spinlock, flags); 77 72 } 78 73 79 74 static int ··· 280 285 { 281 286 int index = sub->number; 282 287 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub); 283 - snd_pcm_uframes_t ptr; 284 288 285 - spin_lock(&cdev->spinlock); 289 + guard(spinlock)(&cdev->spinlock); 286 290 287 - if (cdev->input_panic || cdev->output_panic) { 288 - ptr = SNDRV_PCM_POS_XRUN; 289 - goto unlock; 290 - } 291 + if (cdev->input_panic || cdev->output_panic) 292 + return SNDRV_PCM_POS_XRUN; 291 293 292 294 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 293 - ptr = bytes_to_frames(sub->runtime, 294 - cdev->audio_out_buf_pos[index]); 295 + return bytes_to_frames(sub->runtime, 296 + cdev->audio_out_buf_pos[index]); 295 297 else 296 - ptr = bytes_to_frames(sub->runtime, 297 - cdev->audio_in_buf_pos[index]); 298 - 299 - unlock: 300 - spin_unlock(&cdev->spinlock); 301 - return ptr; 298 + return bytes_to_frames(sub->runtime, 299 + cdev->audio_in_buf_pos[index]); 302 300 } 303 301 304 302 /* operators for both playback and capture */ ··· 589 601 struct device *dev; 590 602 struct urb *out = NULL; 591 603 int i, frame, len, send_it = 0, outframe = 0; 592 - unsigned long flags; 593 604 size_t offset = 0; 594 605 595 606 if (urb->status || !info) ··· 625 638 offset += len; 626 639 627 640 if (len > 0) { 628 - spin_lock_irqsave(&cdev->spinlock, flags); 629 - fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]); 630 - read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]); 631 - spin_unlock_irqrestore(&cdev->spinlock, flags); 641 + scoped_guard(spinlock_irqsave, &cdev->spinlock) { 642 + fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]); 643 + read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]); 644 + } 632 645 check_for_elapsed_periods(cdev, cdev->sub_playback); 633 646 check_for_elapsed_periods(cdev, cdev->sub_capture); 634 647 send_it = 1;