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

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

+14 -21
+14 -21
sound/usb/hiface/pcm.c
··· 305 305 struct pcm_runtime *rt = out_urb->chip->pcm; 306 306 struct pcm_substream *sub; 307 307 bool do_period_elapsed = false; 308 - unsigned long flags; 309 308 int ret; 310 309 311 310 if (rt->panic || rt->stream_state == STREAM_STOPPING) ··· 324 325 325 326 /* now send our playback data (if a free out urb was found) */ 326 327 sub = &rt->playback; 327 - spin_lock_irqsave(&sub->lock, flags); 328 - if (sub->active) 329 - do_period_elapsed = hiface_pcm_playback(sub, out_urb); 330 - else 331 - memset(out_urb->buffer, 0, PCM_PACKET_SIZE); 332 - 333 - spin_unlock_irqrestore(&sub->lock, flags); 328 + scoped_guard(spinlock_irqsave, &sub->lock) { 329 + if (sub->active) 330 + do_period_elapsed = hiface_pcm_playback(sub, out_urb); 331 + else 332 + memset(out_urb->buffer, 0, PCM_PACKET_SIZE); 333 + } 334 334 335 335 if (do_period_elapsed) 336 336 snd_pcm_period_elapsed(sub->instance); ··· 387 389 { 388 390 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub); 389 391 struct pcm_substream *sub = hiface_pcm_get_substream(alsa_sub); 390 - unsigned long flags; 391 392 392 393 if (rt->panic) 393 394 return 0; ··· 396 399 hiface_pcm_stream_stop(rt); 397 400 398 401 /* deactivate substream */ 399 - spin_lock_irqsave(&sub->lock, flags); 402 + guard(spinlock_irqsave)(&sub->lock); 400 403 sub->instance = NULL; 401 404 sub->active = false; 402 - spin_unlock_irqrestore(&sub->lock, flags); 403 - 404 405 } 405 406 return 0; 406 407 } ··· 447 452 switch (cmd) { 448 453 case SNDRV_PCM_TRIGGER_START: 449 454 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 450 - spin_lock_irq(&sub->lock); 451 - sub->active = true; 452 - spin_unlock_irq(&sub->lock); 455 + scoped_guard(spinlock_irq, &sub->lock) { 456 + sub->active = true; 457 + } 453 458 return 0; 454 459 455 460 case SNDRV_PCM_TRIGGER_STOP: 456 461 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 457 - spin_lock_irq(&sub->lock); 458 - sub->active = false; 459 - spin_unlock_irq(&sub->lock); 462 + scoped_guard(spinlock_irq, &sub->lock) { 463 + sub->active = false; 464 + } 460 465 return 0; 461 466 462 467 default: ··· 468 473 { 469 474 struct pcm_substream *sub = hiface_pcm_get_substream(alsa_sub); 470 475 struct pcm_runtime *rt = snd_pcm_substream_chip(alsa_sub); 471 - unsigned long flags; 472 476 snd_pcm_uframes_t dma_offset; 473 477 474 478 if (rt->panic || !sub) 475 479 return SNDRV_PCM_POS_XRUN; 476 480 477 - spin_lock_irqsave(&sub->lock, flags); 481 + guard(spinlock_irqsave)(&sub->lock); 478 482 dma_offset = sub->dma_off; 479 - spin_unlock_irqrestore(&sub->lock, flags); 480 483 return bytes_to_frames(alsa_sub->runtime, dma_offset); 481 484 } 482 485