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

ALSA: hda/common: Use guard() for spinlocks

Replace the manual spin lock/unlock pairs with guard() for code
simplification.

Only code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250827072916.31933-25-tiwai@suse.de

+26 -37
+3 -7
sound/hda/common/codec.c
··· 1748 1748 struct snd_card *card = bus->card; 1749 1749 struct hda_codec *codec; 1750 1750 1751 - spin_lock(&card->files_lock); 1751 + guard(spinlock)(&card->files_lock); 1752 1752 if (card->shutdown) 1753 - goto err_unlock; 1753 + return -EINVAL; 1754 1754 card->shutdown = 1; 1755 1755 if (!list_empty(&card->ctl_files)) 1756 1756 goto err_clear; ··· 1765 1765 goto err_clear; 1766 1766 } 1767 1767 } 1768 - spin_unlock(&card->files_lock); 1769 1768 return 0; 1770 1769 1771 1770 err_clear: 1772 1771 card->shutdown = 0; 1773 - err_unlock: 1774 - spin_unlock(&card->files_lock); 1775 1772 return -EINVAL; 1776 1773 } 1777 1774 EXPORT_SYMBOL_GPL(snd_hda_lock_devices); ··· 1781 1784 { 1782 1785 struct snd_card *card = bus->card; 1783 1786 1784 - spin_lock(&card->files_lock); 1787 + guard(spinlock)(&card->files_lock); 1785 1788 card->shutdown = 0; 1786 - spin_unlock(&card->files_lock); 1787 1789 } 1788 1790 EXPORT_SYMBOL_GPL(snd_hda_unlock_devices); 1789 1791
+23 -30
sound/hda/common/controller.c
··· 245 245 snd_pcm_trigger_done(s, substream); 246 246 } 247 247 248 - spin_lock(&bus->reg_lock); 248 + scoped_guard(spinlock, &bus->reg_lock) { 249 + /* first, set SYNC bits of corresponding streams */ 250 + snd_hdac_stream_sync_trigger(hstr, true, sbits, sync_reg); 249 251 250 - /* first, set SYNC bits of corresponding streams */ 251 - snd_hdac_stream_sync_trigger(hstr, true, sbits, sync_reg); 252 - 253 - snd_pcm_group_for_each_entry(s, substream) { 254 - if (s->pcm->card != substream->pcm->card) 255 - continue; 256 - azx_dev = get_azx_dev(s); 257 - if (start) { 258 - azx_dev->insufficient = 1; 259 - snd_hdac_stream_start(azx_stream(azx_dev)); 260 - } else { 261 - snd_hdac_stream_stop(azx_stream(azx_dev)); 252 + snd_pcm_group_for_each_entry(s, substream) { 253 + if (s->pcm->card != substream->pcm->card) 254 + continue; 255 + azx_dev = get_azx_dev(s); 256 + if (start) { 257 + azx_dev->insufficient = 1; 258 + snd_hdac_stream_start(azx_stream(azx_dev)); 259 + } else { 260 + snd_hdac_stream_stop(azx_stream(azx_dev)); 261 + } 262 262 } 263 263 } 264 - spin_unlock(&bus->reg_lock); 265 264 266 265 snd_hdac_stream_sync(hstr, start, sbits); 267 266 268 - spin_lock(&bus->reg_lock); 267 + guard(spinlock)(&bus->reg_lock); 269 268 /* reset SYNC bits */ 270 269 snd_hdac_stream_sync_trigger(hstr, false, sbits, sync_reg); 271 270 snd_hdac_stream_timecounter_init(hstr, sbits, start); 272 - spin_unlock(&bus->reg_lock); 273 271 return 0; 274 272 } 275 273 ··· 962 964 963 965 azx_dev = azx_get_dsp_loader_dev(chip); 964 966 hstr = azx_stream(azx_dev); 965 - spin_lock_irq(&bus->reg_lock); 966 - if (hstr->opened) { 967 - chip->saved_azx_dev = *azx_dev; 968 - saved = true; 967 + scoped_guard(spinlock_irq, &bus->reg_lock) { 968 + if (hstr->opened) { 969 + chip->saved_azx_dev = *azx_dev; 970 + saved = true; 971 + } 969 972 } 970 - spin_unlock_irq(&bus->reg_lock); 971 973 972 974 err = snd_hdac_dsp_prepare(hstr, format, byte_size, bufp); 973 975 if (err < 0) { 974 - spin_lock_irq(&bus->reg_lock); 976 + guard(spinlock_irq)(&bus->reg_lock); 975 977 if (saved) 976 978 *azx_dev = chip->saved_azx_dev; 977 - spin_unlock_irq(&bus->reg_lock); 978 979 return err; 979 980 } 980 981 ··· 1004 1007 return; 1005 1008 1006 1009 snd_hdac_dsp_cleanup(hstr, dmab); 1007 - spin_lock_irq(&bus->reg_lock); 1010 + guard(spinlock_irq)(&bus->reg_lock); 1008 1011 if (hstr->opened) 1009 1012 *azx_dev = chip->saved_azx_dev; 1010 1013 hstr->locked = false; 1011 - spin_unlock_irq(&bus->reg_lock); 1012 1014 } 1013 1015 EXPORT_SYMBOL_GPL(snd_hda_codec_load_dsp_cleanup); 1014 1016 #endif /* CONFIG_SND_HDA_DSP_LOADER */ ··· 1068 1072 if (!pm_runtime_active(chip->card->dev)) 1069 1073 return IRQ_NONE; 1070 1074 1071 - spin_lock(&bus->reg_lock); 1075 + guard(spinlock)(&bus->reg_lock); 1072 1076 1073 1077 if (chip->disabled) 1074 - goto unlock; 1078 + return IRQ_NONE; 1075 1079 1076 1080 do { 1077 1081 status = azx_readl(chip, INTSTS); ··· 1102 1106 } 1103 1107 } 1104 1108 } while (active && ++repeat < 10); 1105 - 1106 - unlock: 1107 - spin_unlock(&bus->reg_lock); 1108 1109 1109 1110 return IRQ_RETVAL(handled); 1110 1111 }