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

ALSA: ac97: 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/20250829144342.4290-3-tiwai@suse.de

+22 -25
+22 -25
sound/pci/ac97/ac97_pcm.c
··· 570 570 return err; 571 571 } 572 572 } 573 - spin_lock_irq(&pcm->bus->bus_lock); 574 - for (i = 3; i < 12; i++) { 575 - if (!(slots & (1 << i))) 576 - continue; 577 - ok_flag = 0; 578 - for (cidx = 0; cidx < 4; cidx++) { 579 - if (bus->used_slots[pcm->stream][cidx] & (1 << i)) { 580 - spin_unlock_irq(&pcm->bus->bus_lock); 581 - err = -EBUSY; 573 + scoped_guard(spinlock_irq, &pcm->bus->bus_lock) { 574 + for (i = 3; i < 12; i++) { 575 + if (!(slots & (1 << i))) 576 + continue; 577 + ok_flag = 0; 578 + for (cidx = 0; cidx < 4; cidx++) { 579 + if (bus->used_slots[pcm->stream][cidx] & (1 << i)) { 580 + err = -EBUSY; 581 + goto error; 582 + } 583 + if (pcm->r[r].rslots[cidx] & (1 << i)) { 584 + bus->used_slots[pcm->stream][cidx] |= (1 << i); 585 + ok_flag++; 586 + } 587 + } 588 + if (!ok_flag) { 589 + dev_err(bus->card->dev, 590 + "cannot find configuration for AC97 slot %i\n", 591 + i); 592 + err = -EAGAIN; 582 593 goto error; 583 594 } 584 - if (pcm->r[r].rslots[cidx] & (1 << i)) { 585 - bus->used_slots[pcm->stream][cidx] |= (1 << i); 586 - ok_flag++; 587 - } 588 595 } 589 - if (!ok_flag) { 590 - spin_unlock_irq(&pcm->bus->bus_lock); 591 - dev_err(bus->card->dev, 592 - "cannot find configuration for AC97 slot %i\n", 593 - i); 594 - err = -EAGAIN; 595 - goto error; 596 - } 596 + pcm->cur_dbl = r; 597 597 } 598 - pcm->cur_dbl = r; 599 - spin_unlock_irq(&pcm->bus->bus_lock); 600 598 for (i = 3; i < 12; i++) { 601 599 if (!(slots & (1 << i))) 602 600 continue; ··· 662 664 #endif 663 665 664 666 bus = pcm->bus; 665 - spin_lock_irq(&pcm->bus->bus_lock); 667 + guard(spinlock_irq)(&pcm->bus->bus_lock); 666 668 for (i = 3; i < 12; i++) { 667 669 if (!(slots & (1 << i))) 668 670 continue; ··· 671 673 } 672 674 pcm->aslots = 0; 673 675 pcm->cur_dbl = 0; 674 - spin_unlock_irq(&pcm->bus->bus_lock); 675 676 return 0; 676 677 } 677 678