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

ALSA: x86: 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/20250829151335.7342-8-tiwai@suse.de

+39 -54
+39 -54
sound/x86/intel_hdmi_audio.c
··· 171 171 had_substream_get(struct snd_intelhad *intelhaddata) 172 172 { 173 173 struct snd_pcm_substream *substream; 174 - unsigned long flags; 175 174 176 - spin_lock_irqsave(&intelhaddata->had_spinlock, flags); 175 + guard(spinlock_irqsave)(&intelhaddata->had_spinlock); 177 176 substream = intelhaddata->stream_info.substream; 178 177 if (substream) 179 178 intelhaddata->stream_info.substream_refcount++; 180 - spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); 181 179 return substream; 182 180 } 183 181 ··· 184 186 */ 185 187 static void had_substream_put(struct snd_intelhad *intelhaddata) 186 188 { 187 - unsigned long flags; 188 - 189 - spin_lock_irqsave(&intelhaddata->had_spinlock, flags); 189 + guard(spinlock_irqsave)(&intelhaddata->had_spinlock); 190 190 intelhaddata->stream_info.substream_refcount--; 191 - spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); 192 191 } 193 192 194 193 static u32 had_config_offset(int pipe) ··· 941 946 struct snd_intelhad *intelhaddata) 942 947 { 943 948 int len, processed; 944 - unsigned long flags; 945 949 946 950 processed = 0; 947 - spin_lock_irqsave(&intelhaddata->had_spinlock, flags); 951 + guard(spinlock_irqsave)(&intelhaddata->had_spinlock); 948 952 for (;;) { 949 953 /* get the remaining bytes on the buffer */ 950 954 had_read_register(intelhaddata, ··· 952 958 if (len < 0 || len > intelhaddata->period_bytes) { 953 959 dev_dbg(intelhaddata->dev, "Invalid buf length %d\n", 954 960 len); 955 - len = -EPIPE; 956 - goto out; 961 + return -EPIPE; 957 962 } 958 963 959 964 if (len > 0) /* OK, this is the current buffer */ 960 965 break; 961 966 962 967 /* len=0 => already empty, check the next buffer */ 963 - if (++processed >= intelhaddata->num_bds) { 964 - len = -EPIPE; /* all empty? - report underrun */ 965 - goto out; 966 - } 968 + if (++processed >= intelhaddata->num_bds) 969 + return -EPIPE; /* all empty? - report underrun */ 967 970 had_advance_ringbuf(substream, intelhaddata); 968 971 } 969 972 970 973 len = intelhaddata->period_bytes - len; 971 974 len += intelhaddata->period_bytes * intelhaddata->pcmbuf_head; 972 - out: 973 - spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); 974 975 return len; 975 976 } 976 977 ··· 1081 1092 goto error; 1082 1093 1083 1094 /* expose PCM substream */ 1084 - spin_lock_irq(&intelhaddata->had_spinlock); 1085 - intelhaddata->stream_info.substream = substream; 1086 - intelhaddata->stream_info.substream_refcount++; 1087 - spin_unlock_irq(&intelhaddata->had_spinlock); 1095 + scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) { 1096 + intelhaddata->stream_info.substream = substream; 1097 + intelhaddata->stream_info.substream_refcount++; 1098 + } 1088 1099 1089 1100 return retval; 1090 1101 error: ··· 1142 1153 1143 1154 intelhaddata = snd_pcm_substream_chip(substream); 1144 1155 1145 - spin_lock(&intelhaddata->had_spinlock); 1156 + guard(spinlock)(&intelhaddata->had_spinlock); 1146 1157 switch (cmd) { 1147 1158 case SNDRV_PCM_TRIGGER_START: 1148 1159 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: ··· 1161 1172 default: 1162 1173 retval = -EINVAL; 1163 1174 } 1164 - spin_unlock(&intelhaddata->had_spinlock); 1165 1175 return retval; 1166 1176 } 1167 1177 ··· 1299 1311 { 1300 1312 struct snd_pcm_substream *substream; 1301 1313 1302 - spin_lock_irq(&intelhaddata->had_spinlock); 1303 - if (intelhaddata->connected) { 1304 - dev_dbg(intelhaddata->dev, "Device already connected\n"); 1305 - spin_unlock_irq(&intelhaddata->had_spinlock); 1306 - return; 1307 - } 1314 + scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) { 1315 + if (intelhaddata->connected) { 1316 + dev_dbg(intelhaddata->dev, "Device already connected\n"); 1317 + return; 1318 + } 1308 1319 1309 - /* Disable Audio */ 1310 - had_enable_audio(intelhaddata, false); 1320 + /* Disable Audio */ 1321 + had_enable_audio(intelhaddata, false); 1311 1322 1312 - intelhaddata->connected = true; 1313 - dev_dbg(intelhaddata->dev, 1314 - "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n", 1323 + intelhaddata->connected = true; 1324 + dev_dbg(intelhaddata->dev, 1325 + "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n", 1315 1326 __func__, __LINE__); 1316 - spin_unlock_irq(&intelhaddata->had_spinlock); 1327 + } 1317 1328 1318 1329 had_build_channel_allocation_map(intelhaddata); 1319 1330 ··· 1331 1344 { 1332 1345 struct snd_pcm_substream *substream; 1333 1346 1334 - spin_lock_irq(&intelhaddata->had_spinlock); 1335 - if (!intelhaddata->connected) { 1336 - dev_dbg(intelhaddata->dev, "Device already disconnected\n"); 1337 - spin_unlock_irq(&intelhaddata->had_spinlock); 1338 - return; 1347 + scoped_guard(spinlock_irq, &intelhaddata->had_spinlock) { 1348 + if (!intelhaddata->connected) { 1349 + dev_dbg(intelhaddata->dev, "Device already disconnected\n"); 1350 + return; 1351 + } 1339 1352 1340 - } 1353 + /* Disable Audio */ 1354 + had_enable_audio(intelhaddata, false); 1341 1355 1342 - /* Disable Audio */ 1343 - had_enable_audio(intelhaddata, false); 1344 - 1345 - intelhaddata->connected = false; 1346 - dev_dbg(intelhaddata->dev, 1347 - "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n", 1356 + intelhaddata->connected = false; 1357 + dev_dbg(intelhaddata->dev, 1358 + "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n", 1348 1359 __func__, __LINE__); 1349 - spin_unlock_irq(&intelhaddata->had_spinlock); 1360 + } 1350 1361 1351 1362 kfree(intelhaddata->chmap->chmap); 1352 1363 intelhaddata->chmap->chmap = NULL; ··· 1621 1636 struct intel_hdmi_lpe_audio_pdata *pdata = card_ctx->dev->platform_data; 1622 1637 int port; 1623 1638 1624 - spin_lock_irq(&pdata->lpe_audio_slock); 1625 - pdata->notify_audio_lpe = NULL; 1626 - spin_unlock_irq(&pdata->lpe_audio_slock); 1639 + scoped_guard(spinlock_irq, &pdata->lpe_audio_slock) { 1640 + pdata->notify_audio_lpe = NULL; 1641 + } 1627 1642 1628 1643 for_each_port(card_ctx, port) { 1629 1644 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port]; ··· 1784 1799 if (ret) 1785 1800 return ret; 1786 1801 1787 - spin_lock_irq(&pdata->lpe_audio_slock); 1788 - pdata->notify_audio_lpe = notify_audio_lpe; 1789 - spin_unlock_irq(&pdata->lpe_audio_slock); 1802 + scoped_guard(spinlock_irq, &pdata->lpe_audio_slock) { 1803 + pdata->notify_audio_lpe = notify_audio_lpe; 1804 + } 1790 1805 1791 1806 pm_runtime_set_autosuspend_delay(&pdev->dev, INTEL_HDMI_AUDIO_SUSPEND_DELAY_MS); 1792 1807 pm_runtime_use_autosuspend(&pdev->dev);