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

ALSA: cmipci: 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-18-tiwai@suse.de

+69 -96
+69 -96
sound/pci/cmipci.c
··· 712 712 } 713 713 714 714 if (cm->can_multi_ch) { 715 - spin_lock_irq(&cm->reg_lock); 715 + guard(spinlock_irq)(&cm->reg_lock); 716 716 if (channels > 2) { 717 717 snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_NXCHG); 718 718 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC); ··· 735 735 snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_CHB3D); 736 736 else 737 737 snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_CHB3D); 738 - spin_unlock_irq(&cm->reg_lock); 739 738 } 740 739 return 0; 741 740 } ··· 775 776 period_size = (period_size * runtime->channels) / 2; 776 777 } 777 778 778 - spin_lock_irq(&cm->reg_lock); 779 + guard(spinlock_irq)(&cm->reg_lock); 779 780 780 781 /* set buffer address */ 781 782 reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1; ··· 841 842 } 842 843 843 844 rec->running = 0; 844 - spin_unlock_irq(&cm->reg_lock); 845 845 846 846 return 0; 847 847 } ··· 852 854 int cmd) 853 855 { 854 856 unsigned int inthld, chen, reset, pause; 855 - int result = 0; 856 857 857 858 inthld = CM_CH0_INT_EN << rec->ch; 858 859 chen = CM_CHEN0 << rec->ch; 859 860 reset = CM_RST_CH0 << rec->ch; 860 861 pause = CM_PAUSE0 << rec->ch; 861 862 862 - spin_lock(&cm->reg_lock); 863 + guard(spinlock)(&cm->reg_lock); 863 864 switch (cmd) { 864 865 case SNDRV_PCM_TRIGGER_START: 865 866 rec->running = 1; ··· 890 893 snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); 891 894 break; 892 895 default: 893 - result = -EINVAL; 894 - break; 896 + return -EINVAL; 895 897 } 896 - spin_unlock(&cm->reg_lock); 897 - return result; 898 + return 0; 898 899 } 899 900 900 901 /* ··· 982 987 struct cmipci *chip = snd_kcontrol_chip(kcontrol); 983 988 int i; 984 989 985 - spin_lock_irq(&chip->reg_lock); 990 + guard(spinlock_irq)(&chip->reg_lock); 986 991 for (i = 0; i < 4; i++) 987 992 ucontrol->value.iec958.status[i] = (chip->dig_status >> (i * 8)) & 0xff; 988 - spin_unlock_irq(&chip->reg_lock); 989 993 return 0; 990 994 } 991 995 ··· 996 1002 unsigned int val; 997 1003 998 1004 val = 0; 999 - spin_lock_irq(&chip->reg_lock); 1005 + guard(spinlock_irq)(&chip->reg_lock); 1000 1006 for (i = 0; i < 4; i++) 1001 1007 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); 1002 1008 change = val != chip->dig_status; 1003 1009 chip->dig_status = val; 1004 - spin_unlock_irq(&chip->reg_lock); 1005 1010 return change; 1006 1011 } 1007 1012 ··· 1054 1061 struct cmipci *chip = snd_kcontrol_chip(kcontrol); 1055 1062 int i; 1056 1063 1057 - spin_lock_irq(&chip->reg_lock); 1064 + guard(spinlock_irq)(&chip->reg_lock); 1058 1065 for (i = 0; i < 4; i++) 1059 1066 ucontrol->value.iec958.status[i] = (chip->dig_pcm_status >> (i * 8)) & 0xff; 1060 - spin_unlock_irq(&chip->reg_lock); 1061 1067 return 0; 1062 1068 } 1063 1069 ··· 1068 1076 unsigned int val; 1069 1077 1070 1078 val = 0; 1071 - spin_lock_irq(&chip->reg_lock); 1079 + guard(spinlock_irq)(&chip->reg_lock); 1072 1080 for (i = 0; i < 4; i++) 1073 1081 val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8); 1074 1082 change = val != chip->dig_pcm_status; 1075 1083 chip->dig_pcm_status = val; 1076 - spin_unlock_irq(&chip->reg_lock); 1077 1084 return change; 1078 1085 } 1079 1086 ··· 1216 1225 return err; 1217 1226 } 1218 1227 1219 - spin_lock_irq(&cm->reg_lock); 1228 + guard(spinlock_irq)(&cm->reg_lock); 1220 1229 cm->spdif_playback_avail = up; 1221 1230 if (up) { 1222 1231 /* they are controlled via "IEC958 Output Switch" */ ··· 1242 1251 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_PLAYBACK_SPDF); 1243 1252 setup_ac3(cm, subs, 0, 0); 1244 1253 } 1245 - spin_unlock_irq(&cm->reg_lock); 1246 1254 return 0; 1247 1255 } 1248 1256 ··· 1307 1317 /* configure for 16 bits, 2 channels, 8 kHz */ 1308 1318 if (runtime->channels > 2) 1309 1319 set_dac_channels(cm, rec, 2); 1310 - spin_lock_irq(&cm->reg_lock); 1311 - val = snd_cmipci_read(cm, CM_REG_FUNCTRL1); 1312 - val &= ~(CM_ASFC_MASK << (rec->ch * 3)); 1313 - val |= (4 << CM_ASFC_SHIFT) << (rec->ch * 3); 1314 - snd_cmipci_write(cm, CM_REG_FUNCTRL1, val); 1315 - val = snd_cmipci_read(cm, CM_REG_CHFORMAT); 1316 - val &= ~(CM_CH0FMT_MASK << (rec->ch * 2)); 1317 - val |= (3 << CM_CH0FMT_SHIFT) << (rec->ch * 2); 1318 - if (cm->can_96k) 1319 - val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); 1320 - snd_cmipci_write(cm, CM_REG_CHFORMAT, val); 1320 + scoped_guard(spinlock_irq, &cm->reg_lock) { 1321 + val = snd_cmipci_read(cm, CM_REG_FUNCTRL1); 1322 + val &= ~(CM_ASFC_MASK << (rec->ch * 3)); 1323 + val |= (4 << CM_ASFC_SHIFT) << (rec->ch * 3); 1324 + snd_cmipci_write(cm, CM_REG_FUNCTRL1, val); 1325 + val = snd_cmipci_read(cm, CM_REG_CHFORMAT); 1326 + val &= ~(CM_CH0FMT_MASK << (rec->ch * 2)); 1327 + val |= (3 << CM_CH0FMT_SHIFT) << (rec->ch * 2); 1328 + if (cm->can_96k) 1329 + val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2)); 1330 + snd_cmipci_write(cm, CM_REG_CHFORMAT, val); 1321 1331 1322 - /* start stream (we don't need interrupts) */ 1323 - cm->ctrl |= CM_CHEN0 << rec->ch; 1324 - snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); 1325 - spin_unlock_irq(&cm->reg_lock); 1332 + /* start stream (we don't need interrupts) */ 1333 + cm->ctrl |= CM_CHEN0 << rec->ch; 1334 + snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl); 1335 + } 1326 1336 1327 1337 msleep(1); 1328 1338 1329 1339 /* stop and reset stream */ 1330 - spin_lock_irq(&cm->reg_lock); 1331 - cm->ctrl &= ~(CM_CHEN0 << rec->ch); 1332 - val = CM_RST_CH0 << rec->ch; 1333 - snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | val); 1334 - snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~val); 1335 - spin_unlock_irq(&cm->reg_lock); 1340 + scoped_guard(spinlock_irq, &cm->reg_lock) { 1341 + cm->ctrl &= ~(CM_CHEN0 << rec->ch); 1342 + val = CM_RST_CH0 << rec->ch; 1343 + snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | val); 1344 + snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~val); 1345 + } 1336 1346 1337 1347 rec->needs_silencing = 0; 1338 1348 } ··· 1366 1376 { 1367 1377 struct cmipci *cm = snd_pcm_substream_chip(substream); 1368 1378 1369 - spin_lock_irq(&cm->reg_lock); 1370 - snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF); 1371 - if (cm->can_96k) { 1372 - if (substream->runtime->rate > 48000) 1373 - snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); 1379 + scoped_guard(spinlock_irq, &cm->reg_lock) { 1380 + snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF); 1381 + if (cm->can_96k) { 1382 + if (substream->runtime->rate > 48000) 1383 + snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); 1384 + else 1385 + snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); 1386 + } 1387 + if (snd_pcm_format_width(substream->runtime->format) > 16) 1388 + snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); 1374 1389 else 1375 - snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS); 1390 + snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); 1376 1391 } 1377 - if (snd_pcm_format_width(substream->runtime->format) > 16) 1378 - snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); 1379 - else 1380 - snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); 1381 - 1382 - spin_unlock_irq(&cm->reg_lock); 1383 1392 1384 1393 return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream); 1385 1394 } ··· 1387 1398 { 1388 1399 struct cmipci *cm = snd_pcm_substream_chip(subs); 1389 1400 1390 - spin_lock_irq(&cm->reg_lock); 1401 + guard(spinlock_irq)(&cm->reg_lock); 1391 1402 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF); 1392 1403 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL); 1393 - spin_unlock_irq(&cm->reg_lock); 1394 1404 1395 1405 return 0; 1396 1406 } ··· 1409 1421 return IRQ_NONE; 1410 1422 1411 1423 /* acknowledge interrupt */ 1412 - spin_lock(&cm->reg_lock); 1413 - if (status & CM_CHINT0) 1414 - mask |= CM_CH0_INT_EN; 1415 - if (status & CM_CHINT1) 1416 - mask |= CM_CH1_INT_EN; 1417 - snd_cmipci_clear_bit(cm, CM_REG_INT_HLDCLR, mask); 1418 - snd_cmipci_set_bit(cm, CM_REG_INT_HLDCLR, mask); 1419 - spin_unlock(&cm->reg_lock); 1424 + scoped_guard(spinlock, &cm->reg_lock) { 1425 + if (status & CM_CHINT0) 1426 + mask |= CM_CH0_INT_EN; 1427 + if (status & CM_CHINT1) 1428 + mask |= CM_CH1_INT_EN; 1429 + snd_cmipci_clear_bit(cm, CM_REG_INT_HLDCLR, mask); 1430 + snd_cmipci_set_bit(cm, CM_REG_INT_HLDCLR, mask); 1431 + } 1420 1432 1421 1433 if (cm->rmidi && (status & CM_UARTINT)) 1422 1434 snd_mpu401_uart_interrupt(irq, cm->rmidi->private_data); ··· 1575 1587 if (! (mode & CM_OPEN_DAC)) { 1576 1588 /* disable dual DAC mode */ 1577 1589 cm->channel[ch].is_dac = 0; 1578 - spin_lock_irq(&cm->reg_lock); 1590 + guard(spinlock_irq)(&cm->reg_lock); 1579 1591 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_ENDBDAC); 1580 - spin_unlock_irq(&cm->reg_lock); 1581 1592 } 1582 1593 return 0; 1583 1594 } ··· 1596 1609 if (! cm->channel[ch].is_dac) { 1597 1610 /* enable dual DAC mode again */ 1598 1611 cm->channel[ch].is_dac = 1; 1599 - spin_lock_irq(&cm->reg_lock); 1612 + guard(spinlock_irq)(&cm->reg_lock); 1600 1613 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_ENDBDAC); 1601 - spin_unlock_irq(&cm->reg_lock); 1602 1614 } 1603 1615 } 1604 1616 } ··· 1988 2002 int val; 1989 2003 1990 2004 cmipci_sb_reg_decode(&reg, kcontrol->private_value); 1991 - spin_lock_irq(&cm->reg_lock); 2005 + guard(spinlock_irq)(&cm->reg_lock); 1992 2006 val = (snd_cmipci_mixer_read(cm, reg.left_reg) >> reg.left_shift) & reg.mask; 1993 2007 if (reg.invert) 1994 2008 val = reg.mask - val; ··· 1999 2013 val = reg.mask - val; 2000 2014 ucontrol->value.integer.value[1] = val; 2001 2015 } 2002 - spin_unlock_irq(&cm->reg_lock); 2003 2016 return 0; 2004 2017 } 2005 2018 ··· 2022 2037 right <<= reg.right_shift; 2023 2038 } else 2024 2039 right = 0; 2025 - spin_lock_irq(&cm->reg_lock); 2040 + guard(spinlock_irq)(&cm->reg_lock); 2026 2041 oleft = snd_cmipci_mixer_read(cm, reg.left_reg); 2027 2042 left |= oleft & ~(reg.mask << reg.left_shift); 2028 2043 change = left != oleft; ··· 2037 2052 snd_cmipci_mixer_write(cm, reg.right_reg, right); 2038 2053 } else 2039 2054 snd_cmipci_mixer_write(cm, reg.left_reg, left); 2040 - spin_unlock_irq(&cm->reg_lock); 2041 2055 return change; 2042 2056 } 2043 2057 ··· 2068 2084 int val1, val2; 2069 2085 2070 2086 cmipci_sb_reg_decode(&reg, kcontrol->private_value); 2071 - spin_lock_irq(&cm->reg_lock); 2087 + guard(spinlock_irq)(&cm->reg_lock); 2072 2088 val1 = snd_cmipci_mixer_read(cm, reg.left_reg); 2073 2089 val2 = snd_cmipci_mixer_read(cm, reg.right_reg); 2074 - spin_unlock_irq(&cm->reg_lock); 2075 2090 ucontrol->value.integer.value[0] = (val1 >> reg.left_shift) & 1; 2076 2091 ucontrol->value.integer.value[1] = (val2 >> reg.left_shift) & 1; 2077 2092 ucontrol->value.integer.value[2] = (val1 >> reg.right_shift) & 1; ··· 2087 2104 int val1, val2, oval1, oval2; 2088 2105 2089 2106 cmipci_sb_reg_decode(&reg, kcontrol->private_value); 2090 - spin_lock_irq(&cm->reg_lock); 2107 + guard(spinlock_irq)(&cm->reg_lock); 2091 2108 oval1 = snd_cmipci_mixer_read(cm, reg.left_reg); 2092 2109 oval2 = snd_cmipci_mixer_read(cm, reg.right_reg); 2093 2110 val1 = oval1 & ~((1 << reg.left_shift) | (1 << reg.right_shift)); ··· 2099 2116 change = val1 != oval1 || val2 != oval2; 2100 2117 snd_cmipci_mixer_write(cm, reg.left_reg, val1); 2101 2118 snd_cmipci_mixer_write(cm, reg.right_reg, val2); 2102 - spin_unlock_irq(&cm->reg_lock); 2103 2119 return change; 2104 2120 } 2105 2121 ··· 2156 2174 unsigned char oreg, val; 2157 2175 2158 2176 cmipci_sb_reg_decode(&reg, kcontrol->private_value); 2159 - spin_lock_irq(&cm->reg_lock); 2177 + guard(spinlock_irq)(&cm->reg_lock); 2160 2178 oreg = inb(cm->iobase + reg.left_reg); 2161 2179 val = (oreg >> reg.left_shift) & reg.mask; 2162 2180 if (reg.invert) ··· 2168 2186 val = reg.mask - val; 2169 2187 ucontrol->value.integer.value[1] = val; 2170 2188 } 2171 - spin_unlock_irq(&cm->reg_lock); 2172 2189 return 0; 2173 2190 } 2174 2191 ··· 2179 2198 unsigned char oreg, nreg, val; 2180 2199 2181 2200 cmipci_sb_reg_decode(&reg, kcontrol->private_value); 2182 - spin_lock_irq(&cm->reg_lock); 2201 + guard(spinlock_irq)(&cm->reg_lock); 2183 2202 oreg = inb(cm->iobase + reg.left_reg); 2184 2203 val = ucontrol->value.integer.value[0] & reg.mask; 2185 2204 if (reg.invert) ··· 2194 2213 nreg |= (val << reg.right_shift); 2195 2214 } 2196 2215 outb(nreg, cm->iobase + reg.left_reg); 2197 - spin_unlock_irq(&cm->reg_lock); 2198 2216 return (nreg != oreg); 2199 2217 } 2200 2218 ··· 2280 2300 unsigned int val; 2281 2301 struct cmipci *cm = snd_kcontrol_chip(kcontrol); 2282 2302 2283 - spin_lock_irq(&cm->reg_lock); 2303 + guard(spinlock_irq)(&cm->reg_lock); 2284 2304 if (args->ac3_sensitive && cm->mixer_insensitive) { 2285 2305 ucontrol->value.integer.value[0] = 0; 2286 - spin_unlock_irq(&cm->reg_lock); 2287 2306 return 0; 2288 2307 } 2289 2308 if (args->is_byte) ··· 2290 2311 else 2291 2312 val = snd_cmipci_read(cm, args->reg); 2292 2313 ucontrol->value.integer.value[0] = ((val & args->mask) == args->mask_on) ? 1 : 0; 2293 - spin_unlock_irq(&cm->reg_lock); 2294 2314 return 0; 2295 2315 } 2296 2316 ··· 2311 2333 int change; 2312 2334 struct cmipci *cm = snd_kcontrol_chip(kcontrol); 2313 2335 2314 - spin_lock_irq(&cm->reg_lock); 2336 + guard(spinlock_irq)(&cm->reg_lock); 2315 2337 if (args->ac3_sensitive && cm->mixer_insensitive) { 2316 2338 /* ignored */ 2317 - spin_unlock_irq(&cm->reg_lock); 2318 2339 return 0; 2319 2340 } 2320 2341 if (args->is_byte) ··· 2333 2356 else 2334 2357 snd_cmipci_write(cm, args->reg, val); 2335 2358 } 2336 - spin_unlock_irq(&cm->reg_lock); 2337 2359 return change; 2338 2360 } 2339 2361 ··· 2465 2489 { 2466 2490 struct cmipci *cm = snd_kcontrol_chip(kcontrol); 2467 2491 2468 - spin_lock_irq(&cm->reg_lock); 2492 + guard(spinlock_irq)(&cm->reg_lock); 2469 2493 ucontrol->value.enumerated.item[0] = get_line_in_mode(cm); 2470 - spin_unlock_irq(&cm->reg_lock); 2471 2494 return 0; 2472 2495 } 2473 2496 ··· 2476 2501 struct cmipci *cm = snd_kcontrol_chip(kcontrol); 2477 2502 int change; 2478 2503 2479 - spin_lock_irq(&cm->reg_lock); 2504 + guard(spinlock_irq)(&cm->reg_lock); 2480 2505 if (ucontrol->value.enumerated.item[0] == 2) 2481 2506 change = snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_CENTR2LIN | CM_BASE2LIN); 2482 2507 else ··· 2485 2510 change |= snd_cmipci_set_bit_b(cm, CM_REG_MIXER1, CM_REAR2LIN); 2486 2511 else 2487 2512 change |= snd_cmipci_clear_bit_b(cm, CM_REG_MIXER1, CM_REAR2LIN); 2488 - spin_unlock_irq(&cm->reg_lock); 2489 2513 return change; 2490 2514 } 2491 2515 ··· 2500 2526 struct snd_ctl_elem_value *ucontrol) 2501 2527 { 2502 2528 struct cmipci *cm = snd_kcontrol_chip(kcontrol); 2529 + 2503 2530 /* same bit as spdi_phase */ 2504 - spin_lock_irq(&cm->reg_lock); 2531 + guard(spinlock_irq)(&cm->reg_lock); 2505 2532 ucontrol->value.enumerated.item[0] = 2506 2533 (snd_cmipci_read_b(cm, CM_REG_MISC) & CM_SPDIF_INVERSE) ? 1 : 0; 2507 - spin_unlock_irq(&cm->reg_lock); 2508 2534 return 0; 2509 2535 } 2510 2536 ··· 2514 2540 struct cmipci *cm = snd_kcontrol_chip(kcontrol); 2515 2541 int change; 2516 2542 2517 - spin_lock_irq(&cm->reg_lock); 2543 + guard(spinlock_irq)(&cm->reg_lock); 2518 2544 if (ucontrol->value.enumerated.item[0]) 2519 2545 change = snd_cmipci_set_bit_b(cm, CM_REG_MISC, CM_SPDIF_INVERSE); 2520 2546 else 2521 2547 change = snd_cmipci_clear_bit_b(cm, CM_REG_MISC, CM_SPDIF_INVERSE); 2522 - spin_unlock_irq(&cm->reg_lock); 2523 2548 return change; 2524 2549 } 2525 2550 ··· 2600 2627 2601 2628 strscpy(card->mixername, "CMedia PCI"); 2602 2629 2603 - spin_lock_irq(&cm->reg_lock); 2604 - snd_cmipci_mixer_write(cm, 0x00, 0x00); /* mixer reset */ 2605 - spin_unlock_irq(&cm->reg_lock); 2630 + scoped_guard(spinlock_irq, &cm->reg_lock) { 2631 + snd_cmipci_mixer_write(cm, 0x00, 0x00); /* mixer reset */ 2632 + } 2606 2633 2607 2634 for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_mixers); idx++) { 2608 2635 if (cm->chip_version == 68) { // 8768 has no PCM volume