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

ALSA: ali5451: 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-4-tiwai@suse.de

+38 -54
+38 -54
sound/pci/ali5451/ali5451.c
··· 911 911 912 912 dev_dbg(codec->card->dev, "alloc_voice: type=%d rec=%d\n", type, rec); 913 913 914 - spin_lock_irq(&codec->voice_alloc); 914 + guard(spinlock_irq)(&codec->voice_alloc); 915 915 if (type == SNDRV_ALI_VOICE_TYPE_PCM) { 916 916 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : 917 917 snd_ali_find_free_channel(codec,rec); 918 918 if (idx < 0) { 919 919 dev_err(codec->card->dev, "ali_alloc_voice: err.\n"); 920 - spin_unlock_irq(&codec->voice_alloc); 921 920 return NULL; 922 921 } 923 922 pvoice = &(codec->synth.voices[idx]); ··· 924 925 pvoice->use = 1; 925 926 pvoice->pcm = 1; 926 927 pvoice->mode = rec; 927 - spin_unlock_irq(&codec->voice_alloc); 928 928 return pvoice; 929 929 } 930 - spin_unlock_irq(&codec->voice_alloc); 931 930 return NULL; 932 931 } 933 932 ··· 940 943 if (!pvoice->use) 941 944 return; 942 945 snd_ali_clear_voices(codec, pvoice->number, pvoice->number); 943 - spin_lock_irq(&codec->voice_alloc); 944 - private_free = pvoice->private_free; 945 - private_data = pvoice->private_data; 946 - pvoice->private_free = NULL; 947 - pvoice->private_data = NULL; 948 - if (pvoice->pcm) 949 - snd_ali_free_channel_pcm(codec, pvoice->number); 950 - pvoice->use = pvoice->pcm = pvoice->synth = 0; 951 - pvoice->substream = NULL; 952 - spin_unlock_irq(&codec->voice_alloc); 946 + scoped_guard(spinlock_irq, &codec->voice_alloc) { 947 + private_free = pvoice->private_free; 948 + private_data = pvoice->private_data; 949 + pvoice->private_free = NULL; 950 + pvoice->private_data = NULL; 951 + if (pvoice->pcm) 952 + snd_ali_free_channel_pcm(codec, pvoice->number); 953 + pvoice->use = pvoice->pcm = pvoice->synth = 0; 954 + pvoice->substream = NULL; 955 + } 953 956 if (private_free) 954 957 private_free(private_data); 955 958 } ··· 1106 1109 snd_pcm_trigger_done(s, substream); 1107 1110 } 1108 1111 } 1109 - spin_lock(&codec->reg_lock); 1112 + guard(spinlock)(&codec->reg_lock); 1110 1113 if (!do_start) 1111 1114 outl(what, ALI_REG(codec, ALI_STOP)); 1112 1115 val = inl(ALI_REG(codec, ALI_AINTEN)); ··· 1118 1121 if (do_start) 1119 1122 outl(what, ALI_REG(codec, ALI_START)); 1120 1123 dev_dbg(codec->card->dev, "trigger: what=%xh whati=%xh\n", what, whati); 1121 - spin_unlock(&codec->reg_lock); 1122 1124 1123 1125 return 0; 1124 1126 } ··· 1185 1189 1186 1190 dev_dbg(codec->card->dev, "playback_prepare ...\n"); 1187 1191 1188 - spin_lock_irq(&codec->reg_lock); 1189 - 1192 + guard(spinlock_irq)(&codec->reg_lock); 1193 + 1190 1194 /* set Delta (rate) value */ 1191 1195 Delta = snd_ali_convert_rate(runtime->rate, 0); 1192 1196 ··· 1255 1259 CTRL, 1256 1260 EC); 1257 1261 } 1258 - spin_unlock_irq(&codec->reg_lock); 1259 1262 return 0; 1260 1263 } 1261 1264 ··· 1355 1360 struct snd_ali_voice *pvoice = runtime->private_data; 1356 1361 unsigned int cso; 1357 1362 1358 - spin_lock(&codec->reg_lock); 1359 - if (!pvoice->running) { 1360 - spin_unlock(&codec->reg_lock); 1363 + guard(spinlock)(&codec->reg_lock); 1364 + if (!pvoice->running) 1361 1365 return 0; 1362 - } 1363 1366 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); 1364 1367 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); 1365 - spin_unlock(&codec->reg_lock); 1366 1368 dev_dbg(codec->card->dev, "playback pointer returned cso=%xh.\n", cso); 1367 1369 1368 1370 cso %= runtime->buffer_size; ··· 1374 1382 struct snd_ali_voice *pvoice = runtime->private_data; 1375 1383 unsigned int cso; 1376 1384 1377 - spin_lock(&codec->reg_lock); 1378 - if (!pvoice->running) { 1379 - spin_unlock(&codec->reg_lock); 1385 + guard(spinlock)(&codec->reg_lock); 1386 + if (!pvoice->running) 1380 1387 return 0; 1381 - } 1382 1388 outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); 1383 1389 cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); 1384 - spin_unlock(&codec->reg_lock); 1385 1390 1386 1391 cso %= runtime->buffer_size; 1387 1392 return cso; ··· 1682 1693 1683 1694 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0; 1684 1695 1685 - spin_lock_irq(&codec->reg_lock); 1696 + guard(spinlock_irq)(&codec->reg_lock); 1686 1697 switch (kcontrol->private_value) { 1687 1698 case 0: 1688 1699 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0; ··· 1698 1709 break; 1699 1710 } 1700 1711 ucontrol->value.integer.value[0] = spdif_enable; 1701 - spin_unlock_irq(&codec->reg_lock); 1702 1712 return 0; 1703 1713 } 1704 1714 ··· 1709 1721 1710 1722 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0; 1711 1723 1712 - spin_lock_irq(&codec->reg_lock); 1724 + guard(spinlock_irq)(&codec->reg_lock); 1713 1725 switch (kcontrol->private_value) { 1714 1726 case 0: 1715 1727 change = (codec->spdif_mask & 0x02) ? 1 : 0; ··· 1754 1766 default: 1755 1767 break; 1756 1768 } 1757 - spin_unlock_irq(&codec->reg_lock); 1758 1769 1759 1770 return change; 1760 1771 } ··· 1820 1833 for (i = 0; i < chip->num_of_codecs; i++) 1821 1834 snd_ac97_suspend(chip->ac97[i]); 1822 1835 1823 - spin_lock_irq(&chip->reg_lock); 1836 + guard(spinlock_irq)(&chip->reg_lock); 1824 1837 1825 1838 im->regs[ALI_MISCINT >> 2] = inl(ALI_REG(chip, ALI_MISCINT)); 1826 1839 /* im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START)); */ ··· 1844 1857 /* stop all HW channel */ 1845 1858 outl(0xffffffff, ALI_REG(chip, ALI_STOP)); 1846 1859 1847 - spin_unlock_irq(&chip->reg_lock); 1848 1860 return 0; 1849 1861 } 1850 1862 ··· 1854 1868 struct snd_ali_image *im = &chip->image; 1855 1869 int i, j; 1856 1870 1857 - spin_lock_irq(&chip->reg_lock); 1871 + scoped_guard(spinlock_irq, &chip->reg_lock) { 1872 + for (i = 0; i < ALI_CHANNELS; i++) { 1873 + outb(i, ALI_REG(chip, ALI_GC_CIR)); 1874 + for (j = 0; j < ALI_CHANNEL_REGS; j++) 1875 + outl(im->channel_regs[i][j], ALI_REG(chip, j*4 + 0xe0)); 1876 + } 1858 1877 1859 - for (i = 0; i < ALI_CHANNELS; i++) { 1860 - outb(i, ALI_REG(chip, ALI_GC_CIR)); 1861 - for (j = 0; j < ALI_CHANNEL_REGS; j++) 1862 - outl(im->channel_regs[i][j], ALI_REG(chip, j*4 + 0xe0)); 1878 + for (i = 0; i < ALI_GLOBAL_REGS; i++) { 1879 + if ((i*4 == ALI_MISCINT) || (i*4 == ALI_STOP) || 1880 + (i*4 == ALI_START)) 1881 + continue; 1882 + outl(im->regs[i], ALI_REG(chip, i*4)); 1883 + } 1884 + 1885 + /* start HW channel */ 1886 + outl(im->regs[ALI_START >> 2], ALI_REG(chip, ALI_START)); 1887 + /* restore IRQ enable bits */ 1888 + outl(im->regs[ALI_MISCINT >> 2], ALI_REG(chip, ALI_MISCINT)); 1863 1889 } 1864 - 1865 - for (i = 0; i < ALI_GLOBAL_REGS; i++) { 1866 - if ((i*4 == ALI_MISCINT) || (i*4 == ALI_STOP) || 1867 - (i*4 == ALI_START)) 1868 - continue; 1869 - outl(im->regs[i], ALI_REG(chip, i*4)); 1870 - } 1871 - 1872 - /* start HW channel */ 1873 - outl(im->regs[ALI_START >> 2], ALI_REG(chip, ALI_START)); 1874 - /* restore IRQ enable bits */ 1875 - outl(im->regs[ALI_MISCINT >> 2], ALI_REG(chip, ALI_MISCINT)); 1876 - 1877 - spin_unlock_irq(&chip->reg_lock); 1878 1890 1879 1891 for (i = 0 ; i < chip->num_of_codecs; i++) 1880 1892 snd_ac97_resume(chip->ac97[i]);