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

ALSA: aoa: Use guard() for mutex locks

Replace the manual mutex 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/20250829151335.7342-14-tiwai@suse.de

+112 -227
+32 -72
sound/aoa/codecs/onyx.c
··· 122 122 struct onyx *onyx = snd_kcontrol_chip(kcontrol); 123 123 s8 l, r; 124 124 125 - mutex_lock(&onyx->mutex); 125 + guard(mutex)(&onyx->mutex); 126 126 onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_LEFT, &l); 127 127 onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_RIGHT, &r); 128 - mutex_unlock(&onyx->mutex); 129 128 130 129 ucontrol->value.integer.value[0] = l + VOLUME_RANGE_SHIFT; 131 130 ucontrol->value.integer.value[1] = r + VOLUME_RANGE_SHIFT; ··· 145 146 ucontrol->value.integer.value[1] > -1 + VOLUME_RANGE_SHIFT) 146 147 return -EINVAL; 147 148 148 - mutex_lock(&onyx->mutex); 149 + guard(mutex)(&onyx->mutex); 149 150 onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_LEFT, &l); 150 151 onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_RIGHT, &r); 151 152 152 153 if (l + VOLUME_RANGE_SHIFT == ucontrol->value.integer.value[0] && 153 - r + VOLUME_RANGE_SHIFT == ucontrol->value.integer.value[1]) { 154 - mutex_unlock(&onyx->mutex); 154 + r + VOLUME_RANGE_SHIFT == ucontrol->value.integer.value[1]) 155 155 return 0; 156 - } 157 156 158 157 onyx_write_register(onyx, ONYX_REG_DAC_ATTEN_LEFT, 159 158 ucontrol->value.integer.value[0] ··· 159 162 onyx_write_register(onyx, ONYX_REG_DAC_ATTEN_RIGHT, 160 163 ucontrol->value.integer.value[1] 161 164 - VOLUME_RANGE_SHIFT); 162 - mutex_unlock(&onyx->mutex); 163 165 164 166 return 1; 165 167 } ··· 194 198 struct onyx *onyx = snd_kcontrol_chip(kcontrol); 195 199 u8 ig; 196 200 197 - mutex_lock(&onyx->mutex); 201 + guard(mutex)(&onyx->mutex); 198 202 onyx_read_register(onyx, ONYX_REG_ADC_CONTROL, &ig); 199 - mutex_unlock(&onyx->mutex); 200 203 201 204 ucontrol->value.integer.value[0] = 202 205 (ig & ONYX_ADC_PGA_GAIN_MASK) + INPUTGAIN_RANGE_SHIFT; ··· 212 217 if (ucontrol->value.integer.value[0] < 3 + INPUTGAIN_RANGE_SHIFT || 213 218 ucontrol->value.integer.value[0] > 28 + INPUTGAIN_RANGE_SHIFT) 214 219 return -EINVAL; 215 - mutex_lock(&onyx->mutex); 220 + guard(mutex)(&onyx->mutex); 216 221 onyx_read_register(onyx, ONYX_REG_ADC_CONTROL, &v); 217 222 n = v; 218 223 n &= ~ONYX_ADC_PGA_GAIN_MASK; 219 224 n |= (ucontrol->value.integer.value[0] - INPUTGAIN_RANGE_SHIFT) 220 225 & ONYX_ADC_PGA_GAIN_MASK; 221 226 onyx_write_register(onyx, ONYX_REG_ADC_CONTROL, n); 222 - mutex_unlock(&onyx->mutex); 223 227 224 228 return n != v; 225 229 } ··· 246 252 struct onyx *onyx = snd_kcontrol_chip(kcontrol); 247 253 s8 v; 248 254 249 - mutex_lock(&onyx->mutex); 255 + guard(mutex)(&onyx->mutex); 250 256 onyx_read_register(onyx, ONYX_REG_ADC_CONTROL, &v); 251 - mutex_unlock(&onyx->mutex); 252 257 253 258 ucontrol->value.enumerated.item[0] = !!(v&ONYX_ADC_INPUT_MIC); 254 259 ··· 258 265 { 259 266 s8 v; 260 267 261 - mutex_lock(&onyx->mutex); 268 + guard(mutex)(&onyx->mutex); 262 269 onyx_read_register(onyx, ONYX_REG_ADC_CONTROL, &v); 263 270 v &= ~ONYX_ADC_INPUT_MIC; 264 271 if (mic) 265 272 v |= ONYX_ADC_INPUT_MIC; 266 273 onyx_write_register(onyx, ONYX_REG_ADC_CONTROL, v); 267 - mutex_unlock(&onyx->mutex); 268 274 } 269 275 270 276 static int onyx_snd_capture_source_put(struct snd_kcontrol *kcontrol, ··· 304 312 struct onyx *onyx = snd_kcontrol_chip(kcontrol); 305 313 u8 c; 306 314 307 - mutex_lock(&onyx->mutex); 315 + guard(mutex)(&onyx->mutex); 308 316 onyx_read_register(onyx, ONYX_REG_DAC_CONTROL, &c); 309 - mutex_unlock(&onyx->mutex); 310 317 311 318 ucontrol->value.integer.value[0] = !(c & ONYX_MUTE_LEFT); 312 319 ucontrol->value.integer.value[1] = !(c & ONYX_MUTE_RIGHT); ··· 320 329 u8 v = 0, c = 0; 321 330 int err = -EBUSY; 322 331 323 - mutex_lock(&onyx->mutex); 332 + guard(mutex)(&onyx->mutex); 324 333 if (onyx->analog_locked) 325 - goto out_unlock; 334 + return -EBUSY; 326 335 327 336 onyx_read_register(onyx, ONYX_REG_DAC_CONTROL, &v); 328 337 c = v; ··· 332 341 if (!ucontrol->value.integer.value[1]) 333 342 c |= ONYX_MUTE_RIGHT; 334 343 err = onyx_write_register(onyx, ONYX_REG_DAC_CONTROL, c); 335 - 336 - out_unlock: 337 - mutex_unlock(&onyx->mutex); 338 344 339 345 return !err ? (v != c) : err; 340 346 } ··· 361 373 u8 address = (pv >> 8) & 0xff; 362 374 u8 mask = pv & 0xff; 363 375 364 - mutex_lock(&onyx->mutex); 376 + guard(mutex)(&onyx->mutex); 365 377 onyx_read_register(onyx, address, &c); 366 - mutex_unlock(&onyx->mutex); 367 378 368 379 ucontrol->value.integer.value[0] = !!(c & mask) ^ polarity; 369 380 ··· 381 394 u8 address = (pv >> 8) & 0xff; 382 395 u8 mask = pv & 0xff; 383 396 384 - mutex_lock(&onyx->mutex); 397 + guard(mutex)(&onyx->mutex); 385 398 if (spdiflock && onyx->spdif_locked) { 386 399 /* even if alsamixer doesn't care.. */ 387 - err = -EBUSY; 388 - goto out_unlock; 400 + return -EBUSY; 389 401 } 390 402 onyx_read_register(onyx, address, &v); 391 403 c = v; ··· 392 406 if (!!ucontrol->value.integer.value[0] ^ polarity) 393 407 c |= mask; 394 408 err = onyx_write_register(onyx, address, c); 395 - 396 - out_unlock: 397 - mutex_unlock(&onyx->mutex); 398 409 399 410 return !err ? (v != c) : err; 400 411 } ··· 473 490 struct onyx *onyx = snd_kcontrol_chip(kcontrol); 474 491 u8 v; 475 492 476 - mutex_lock(&onyx->mutex); 493 + guard(mutex)(&onyx->mutex); 477 494 onyx_read_register(onyx, ONYX_REG_DIG_INFO1, &v); 478 495 ucontrol->value.iec958.status[0] = v & 0x3e; 479 496 ··· 485 502 486 503 onyx_read_register(onyx, ONYX_REG_DIG_INFO4, &v); 487 504 ucontrol->value.iec958.status[4] = v & 0x0f; 488 - mutex_unlock(&onyx->mutex); 489 505 490 506 return 0; 491 507 } ··· 495 513 struct onyx *onyx = snd_kcontrol_chip(kcontrol); 496 514 u8 v; 497 515 498 - mutex_lock(&onyx->mutex); 516 + guard(mutex)(&onyx->mutex); 499 517 onyx_read_register(onyx, ONYX_REG_DIG_INFO1, &v); 500 518 v = (v & ~0x3e) | (ucontrol->value.iec958.status[0] & 0x3e); 501 519 onyx_write_register(onyx, ONYX_REG_DIG_INFO1, v); ··· 510 528 onyx_read_register(onyx, ONYX_REG_DIG_INFO4, &v); 511 529 v = (v & ~0x0f) | (ucontrol->value.iec958.status[4] & 0x0f); 512 530 onyx_write_register(onyx, ONYX_REG_DIG_INFO4, v); 513 - mutex_unlock(&onyx->mutex); 514 531 515 532 return 1; 516 533 } ··· 654 673 struct onyx *onyx = cii->codec_data; 655 674 int spdif_enabled, analog_enabled; 656 675 657 - mutex_lock(&onyx->mutex); 676 + guard(mutex)(&onyx->mutex); 658 677 onyx_read_register(onyx, ONYX_REG_DIG_INFO4, &v); 659 678 spdif_enabled = !!(v & ONYX_SPDIF_ENABLE); 660 679 onyx_read_register(onyx, ONYX_REG_DAC_CONTROL, &v); 661 680 analog_enabled = 662 681 (v & (ONYX_MUTE_RIGHT|ONYX_MUTE_LEFT)) 663 682 != (ONYX_MUTE_RIGHT|ONYX_MUTE_LEFT); 664 - mutex_unlock(&onyx->mutex); 665 683 666 684 switch (ti->tag) { 667 685 case 0: return 1; ··· 676 696 { 677 697 u8 v; 678 698 struct onyx *onyx = cii->codec_data; 679 - int err = -EBUSY; 680 699 681 - mutex_lock(&onyx->mutex); 700 + guard(mutex)(&onyx->mutex); 682 701 683 702 #ifdef SNDRV_PCM_FMTBIT_COMPRESSED_16BE 684 703 if (substream->runtime->format == SNDRV_PCM_FMTBIT_COMPRESSED_16BE) { ··· 686 707 if (onyx_write_register(onyx, 687 708 ONYX_REG_DAC_CONTROL, 688 709 v | ONYX_MUTE_RIGHT | ONYX_MUTE_LEFT)) 689 - goto out_unlock; 710 + return -EBUSY; 690 711 onyx->analog_locked = 1; 691 - err = 0; 692 - goto out_unlock; 712 + return 0; 693 713 } 694 714 #endif 695 715 switch (substream->runtime->rate) { ··· 698 720 /* these rates are ok for all outputs */ 699 721 /* FIXME: program spdif channel control bits here so that 700 722 * userspace doesn't have to if it only plays pcm! */ 701 - err = 0; 702 - goto out_unlock; 723 + return 0; 703 724 default: 704 725 /* got some rate that the digital output can't do, 705 726 * so disable and lock it */ ··· 706 729 if (onyx_write_register(onyx, 707 730 ONYX_REG_DIG_INFO4, 708 731 v & ~ONYX_SPDIF_ENABLE)) 709 - goto out_unlock; 732 + return -EBUSY; 710 733 onyx->spdif_locked = 1; 711 - err = 0; 712 - goto out_unlock; 734 + return 0; 713 735 } 714 736 715 - out_unlock: 716 - mutex_unlock(&onyx->mutex); 717 - 718 - return err; 737 + return -EBUSY; 719 738 } 720 739 721 740 static int onyx_open(struct codec_info_item *cii, ··· 719 746 { 720 747 struct onyx *onyx = cii->codec_data; 721 748 722 - mutex_lock(&onyx->mutex); 749 + guard(mutex)(&onyx->mutex); 723 750 onyx->open_count++; 724 - mutex_unlock(&onyx->mutex); 725 751 726 752 return 0; 727 753 } ··· 730 758 { 731 759 struct onyx *onyx = cii->codec_data; 732 760 733 - mutex_lock(&onyx->mutex); 761 + guard(mutex)(&onyx->mutex); 734 762 onyx->open_count--; 735 763 if (!onyx->open_count) 736 764 onyx->spdif_locked = onyx->analog_locked = 0; 737 - mutex_unlock(&onyx->mutex); 738 765 739 766 return 0; 740 767 } ··· 743 772 { 744 773 struct onyx *onyx = cii->codec_data; 745 774 746 - mutex_lock(&onyx->mutex); 775 + guard(mutex)(&onyx->mutex); 747 776 /* this *MUST* be more elaborate later... */ 748 777 switch (what) { 749 778 case CLOCK_SWITCH_PREPARE_SLAVE: ··· 755 784 default: /* silence warning */ 756 785 break; 757 786 } 758 - mutex_unlock(&onyx->mutex); 759 787 760 788 return 0; 761 789 } ··· 765 795 { 766 796 struct onyx *onyx = cii->codec_data; 767 797 u8 v; 768 - int err = -ENXIO; 769 798 770 - mutex_lock(&onyx->mutex); 799 + guard(mutex)(&onyx->mutex); 771 800 if (onyx_read_register(onyx, ONYX_REG_CONTROL, &v)) 772 - goto out_unlock; 801 + return -ENXIO; 773 802 onyx_write_register(onyx, ONYX_REG_CONTROL, v | ONYX_ADPSV | ONYX_DAPSV); 774 803 /* Apple does a sleep here but the datasheet says to do it on resume */ 775 - err = 0; 776 - out_unlock: 777 - mutex_unlock(&onyx->mutex); 778 - 779 - return err; 804 + return 0; 780 805 } 781 806 782 807 static int onyx_resume(struct codec_info_item *cii) 783 808 { 784 809 struct onyx *onyx = cii->codec_data; 785 810 u8 v; 786 - int err = -ENXIO; 787 811 788 - mutex_lock(&onyx->mutex); 812 + guard(mutex)(&onyx->mutex); 789 813 790 814 /* reset codec */ 791 815 onyx->codec.gpio->methods->set_hw_reset(onyx->codec.gpio, 0); ··· 791 827 792 828 /* take codec out of suspend (if it still is after reset) */ 793 829 if (onyx_read_register(onyx, ONYX_REG_CONTROL, &v)) 794 - goto out_unlock; 830 + return -ENXIO; 795 831 onyx_write_register(onyx, ONYX_REG_CONTROL, v & ~(ONYX_ADPSV | ONYX_DAPSV)); 796 832 /* FIXME: should divide by sample rate, but 8k is the lowest we go */ 797 833 msleep(2205000/8000); 798 834 /* reset all values */ 799 835 onyx_register_init(onyx); 800 - err = 0; 801 - out_unlock: 802 - mutex_unlock(&onyx->mutex); 803 - 804 - return err; 836 + return 0; 805 837 } 806 838 807 839 #endif /* CONFIG_PM */
+39 -74
sound/aoa/codecs/tas.c
··· 235 235 { 236 236 struct tas *tas = snd_kcontrol_chip(kcontrol); 237 237 238 - mutex_lock(&tas->mtx); 238 + guard(mutex)(&tas->mtx); 239 239 ucontrol->value.integer.value[0] = tas->cached_volume_l; 240 240 ucontrol->value.integer.value[1] = tas->cached_volume_r; 241 - mutex_unlock(&tas->mtx); 242 241 return 0; 243 242 } 244 243 ··· 253 254 ucontrol->value.integer.value[1] > 177) 254 255 return -EINVAL; 255 256 256 - mutex_lock(&tas->mtx); 257 + guard(mutex)(&tas->mtx); 257 258 if (tas->cached_volume_l == ucontrol->value.integer.value[0] 258 - && tas->cached_volume_r == ucontrol->value.integer.value[1]) { 259 - mutex_unlock(&tas->mtx); 259 + && tas->cached_volume_r == ucontrol->value.integer.value[1]) 260 260 return 0; 261 - } 262 261 263 262 tas->cached_volume_l = ucontrol->value.integer.value[0]; 264 263 tas->cached_volume_r = ucontrol->value.integer.value[1]; 265 264 if (tas->hw_enabled) 266 265 tas_set_volume(tas); 267 - mutex_unlock(&tas->mtx); 268 266 return 1; 269 267 } 270 268 ··· 281 285 { 282 286 struct tas *tas = snd_kcontrol_chip(kcontrol); 283 287 284 - mutex_lock(&tas->mtx); 288 + guard(mutex)(&tas->mtx); 285 289 ucontrol->value.integer.value[0] = !tas->mute_l; 286 290 ucontrol->value.integer.value[1] = !tas->mute_r; 287 - mutex_unlock(&tas->mtx); 288 291 return 0; 289 292 } 290 293 ··· 292 297 { 293 298 struct tas *tas = snd_kcontrol_chip(kcontrol); 294 299 295 - mutex_lock(&tas->mtx); 300 + guard(mutex)(&tas->mtx); 296 301 if (tas->mute_l == !ucontrol->value.integer.value[0] 297 - && tas->mute_r == !ucontrol->value.integer.value[1]) { 298 - mutex_unlock(&tas->mtx); 302 + && tas->mute_r == !ucontrol->value.integer.value[1]) 299 303 return 0; 300 - } 301 304 302 305 tas->mute_l = !ucontrol->value.integer.value[0]; 303 306 tas->mute_r = !ucontrol->value.integer.value[1]; 304 307 if (tas->hw_enabled) 305 308 tas_set_volume(tas); 306 - mutex_unlock(&tas->mtx); 307 309 return 1; 308 310 } 309 311 ··· 329 337 struct tas *tas = snd_kcontrol_chip(kcontrol); 330 338 int idx = kcontrol->private_value; 331 339 332 - mutex_lock(&tas->mtx); 340 + guard(mutex)(&tas->mtx); 333 341 ucontrol->value.integer.value[0] = tas->mixer_l[idx]; 334 342 ucontrol->value.integer.value[1] = tas->mixer_r[idx]; 335 - mutex_unlock(&tas->mtx); 336 343 337 344 return 0; 338 345 } ··· 342 351 struct tas *tas = snd_kcontrol_chip(kcontrol); 343 352 int idx = kcontrol->private_value; 344 353 345 - mutex_lock(&tas->mtx); 354 + guard(mutex)(&tas->mtx); 346 355 if (tas->mixer_l[idx] == ucontrol->value.integer.value[0] 347 - && tas->mixer_r[idx] == ucontrol->value.integer.value[1]) { 348 - mutex_unlock(&tas->mtx); 356 + && tas->mixer_r[idx] == ucontrol->value.integer.value[1]) 349 357 return 0; 350 - } 351 358 352 359 tas->mixer_l[idx] = ucontrol->value.integer.value[0]; 353 360 tas->mixer_r[idx] = ucontrol->value.integer.value[1]; 354 361 355 362 if (tas->hw_enabled) 356 363 tas_set_mixer(tas); 357 - mutex_unlock(&tas->mtx); 358 364 return 1; 359 365 } 360 366 ··· 384 396 { 385 397 struct tas *tas = snd_kcontrol_chip(kcontrol); 386 398 387 - mutex_lock(&tas->mtx); 399 + guard(mutex)(&tas->mtx); 388 400 ucontrol->value.integer.value[0] = tas->drc_range; 389 - mutex_unlock(&tas->mtx); 390 401 return 0; 391 402 } 392 403 ··· 398 411 ucontrol->value.integer.value[0] > TAS3004_DRC_MAX) 399 412 return -EINVAL; 400 413 401 - mutex_lock(&tas->mtx); 402 - if (tas->drc_range == ucontrol->value.integer.value[0]) { 403 - mutex_unlock(&tas->mtx); 414 + guard(mutex)(&tas->mtx); 415 + if (tas->drc_range == ucontrol->value.integer.value[0]) 404 416 return 0; 405 - } 406 417 407 418 tas->drc_range = ucontrol->value.integer.value[0]; 408 419 if (tas->hw_enabled) 409 420 tas3004_set_drc(tas); 410 - mutex_unlock(&tas->mtx); 411 421 return 1; 412 422 } 413 423 ··· 424 440 { 425 441 struct tas *tas = snd_kcontrol_chip(kcontrol); 426 442 427 - mutex_lock(&tas->mtx); 443 + guard(mutex)(&tas->mtx); 428 444 ucontrol->value.integer.value[0] = tas->drc_enabled; 429 - mutex_unlock(&tas->mtx); 430 445 return 0; 431 446 } 432 447 ··· 434 451 { 435 452 struct tas *tas = snd_kcontrol_chip(kcontrol); 436 453 437 - mutex_lock(&tas->mtx); 438 - if (tas->drc_enabled == ucontrol->value.integer.value[0]) { 439 - mutex_unlock(&tas->mtx); 454 + guard(mutex)(&tas->mtx); 455 + if (tas->drc_enabled == ucontrol->value.integer.value[0]) 440 456 return 0; 441 - } 442 457 443 458 tas->drc_enabled = !!ucontrol->value.integer.value[0]; 444 459 if (tas->hw_enabled) 445 460 tas3004_set_drc(tas); 446 - mutex_unlock(&tas->mtx); 447 461 return 1; 448 462 } 449 463 ··· 466 486 { 467 487 struct tas *tas = snd_kcontrol_chip(kcontrol); 468 488 469 - mutex_lock(&tas->mtx); 489 + guard(mutex)(&tas->mtx); 470 490 ucontrol->value.enumerated.item[0] = !!(tas->acr & TAS_ACR_INPUT_B); 471 - mutex_unlock(&tas->mtx); 472 491 return 0; 473 492 } 474 493 ··· 479 500 480 501 if (ucontrol->value.enumerated.item[0] > 1) 481 502 return -EINVAL; 482 - mutex_lock(&tas->mtx); 503 + guard(mutex)(&tas->mtx); 483 504 oldacr = tas->acr; 484 505 485 506 /* ··· 491 512 if (ucontrol->value.enumerated.item[0]) 492 513 tas->acr |= TAS_ACR_INPUT_B | TAS_ACR_B_MONAUREAL | 493 514 TAS_ACR_B_MON_SEL_RIGHT; 494 - if (oldacr == tas->acr) { 495 - mutex_unlock(&tas->mtx); 515 + if (oldacr == tas->acr) 496 516 return 0; 497 - } 498 517 if (tas->hw_enabled) 499 518 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); 500 - mutex_unlock(&tas->mtx); 501 519 return 1; 502 520 } 503 521 ··· 533 557 { 534 558 struct tas *tas = snd_kcontrol_chip(kcontrol); 535 559 536 - mutex_lock(&tas->mtx); 560 + guard(mutex)(&tas->mtx); 537 561 ucontrol->value.integer.value[0] = tas->treble; 538 - mutex_unlock(&tas->mtx); 539 562 return 0; 540 563 } 541 564 ··· 546 571 if (ucontrol->value.integer.value[0] < TAS3004_TREBLE_MIN || 547 572 ucontrol->value.integer.value[0] > TAS3004_TREBLE_MAX) 548 573 return -EINVAL; 549 - mutex_lock(&tas->mtx); 550 - if (tas->treble == ucontrol->value.integer.value[0]) { 551 - mutex_unlock(&tas->mtx); 574 + guard(mutex)(&tas->mtx); 575 + if (tas->treble == ucontrol->value.integer.value[0]) 552 576 return 0; 553 - } 554 577 555 578 tas->treble = ucontrol->value.integer.value[0]; 556 579 if (tas->hw_enabled) 557 580 tas_set_treble(tas); 558 - mutex_unlock(&tas->mtx); 559 581 return 1; 560 582 } 561 583 ··· 580 608 { 581 609 struct tas *tas = snd_kcontrol_chip(kcontrol); 582 610 583 - mutex_lock(&tas->mtx); 611 + guard(mutex)(&tas->mtx); 584 612 ucontrol->value.integer.value[0] = tas->bass; 585 - mutex_unlock(&tas->mtx); 586 613 return 0; 587 614 } 588 615 ··· 593 622 if (ucontrol->value.integer.value[0] < TAS3004_BASS_MIN || 594 623 ucontrol->value.integer.value[0] > TAS3004_BASS_MAX) 595 624 return -EINVAL; 596 - mutex_lock(&tas->mtx); 597 - if (tas->bass == ucontrol->value.integer.value[0]) { 598 - mutex_unlock(&tas->mtx); 625 + guard(mutex)(&tas->mtx); 626 + if (tas->bass == ucontrol->value.integer.value[0]) 599 627 return 0; 600 - } 601 628 602 629 tas->bass = ucontrol->value.integer.value[0]; 603 630 if (tas->hw_enabled) 604 631 tas_set_bass(tas); 605 - mutex_unlock(&tas->mtx); 606 632 return 1; 607 633 } 608 634 ··· 690 722 break; 691 723 case CLOCK_SWITCH_SLAVE: 692 724 /* Clocks are back, re-init the codec */ 693 - mutex_lock(&tas->mtx); 694 - tas_reset_init(tas); 695 - tas_set_volume(tas); 696 - tas_set_mixer(tas); 697 - tas->hw_enabled = 1; 698 - tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); 699 - mutex_unlock(&tas->mtx); 725 + scoped_guard(mutex, &tas->mtx) { 726 + tas_reset_init(tas); 727 + tas_set_volume(tas); 728 + tas_set_mixer(tas); 729 + tas->hw_enabled = 1; 730 + tas->codec.gpio->methods->all_amps_restore(tas->codec.gpio); 731 + } 700 732 break; 701 733 default: 702 734 /* doesn't happen as of now */ ··· 711 743 * our i2c device is suspended, and then take note of that! */ 712 744 static int tas_suspend(struct tas *tas) 713 745 { 714 - mutex_lock(&tas->mtx); 746 + guard(mutex)(&tas->mtx); 715 747 tas->hw_enabled = 0; 716 748 tas->acr |= TAS_ACR_ANALOG_PDOWN; 717 749 tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr); 718 - mutex_unlock(&tas->mtx); 719 750 return 0; 720 751 } 721 752 722 753 static int tas_resume(struct tas *tas) 723 754 { 724 755 /* reset codec */ 725 - mutex_lock(&tas->mtx); 756 + guard(mutex)(&tas->mtx); 726 757 tas_reset_init(tas); 727 758 tas_set_volume(tas); 728 759 tas_set_mixer(tas); 729 760 tas->hw_enabled = 1; 730 - mutex_unlock(&tas->mtx); 731 761 return 0; 732 762 } 733 763 ··· 768 802 return -EINVAL; 769 803 } 770 804 771 - mutex_lock(&tas->mtx); 772 - if (tas_reset_init(tas)) { 773 - printk(KERN_ERR PFX "tas failed to initialise\n"); 774 - mutex_unlock(&tas->mtx); 775 - return -ENXIO; 805 + scoped_guard(mutex, &tas->mtx) { 806 + if (tas_reset_init(tas)) { 807 + printk(KERN_ERR PFX "tas failed to initialise\n"); 808 + return -ENXIO; 809 + } 810 + tas->hw_enabled = 1; 776 811 } 777 - tas->hw_enabled = 1; 778 - mutex_unlock(&tas->mtx); 779 812 780 813 if (tas->codec.soundbus_dev->attach_codec(tas->codec.soundbus_dev, 781 814 aoa_get_card(),
+7 -13
sound/aoa/core/gpio-feature.c
··· 212 212 struct gpio_notification *notif = 213 213 container_of(work, struct gpio_notification, work.work); 214 214 215 - mutex_lock(&notif->mutex); 215 + guard(mutex)(&notif->mutex); 216 216 if (notif->notify) 217 217 notif->notify(notif->data); 218 - mutex_unlock(&notif->mutex); 219 218 } 220 219 221 220 static void gpio_enable_dual_edge(int gpio) ··· 340 341 if (!irq) 341 342 return -ENODEV; 342 343 343 - mutex_lock(&notif->mutex); 344 + guard(mutex)(&notif->mutex); 344 345 345 346 old = notif->notify; 346 347 347 - if (!old && !notify) { 348 - err = 0; 349 - goto out_unlock; 350 - } 348 + if (!old && !notify) 349 + return 0; 351 350 352 351 if (old && notify) { 353 352 if (old == notify && notif->data == data) 354 353 err = 0; 355 - goto out_unlock; 354 + return err; 356 355 } 357 356 358 357 if (old && !notify) ··· 359 362 if (!old && notify) { 360 363 err = request_irq(irq, ftr_handle_notify_irq, 0, name, notif); 361 364 if (err) 362 - goto out_unlock; 365 + return err; 363 366 } 364 367 365 368 notif->notify = notify; 366 369 notif->data = data; 367 370 368 - err = 0; 369 - out_unlock: 370 - mutex_unlock(&notif->mutex); 371 - return err; 371 + return 0; 372 372 } 373 373 374 374 static int ftr_get_detect(struct gpio_runtime *rt,
+9 -17
sound/aoa/core/gpio-pmf.c
··· 74 74 struct gpio_notification *notif = 75 75 container_of(work, struct gpio_notification, work.work); 76 76 77 - mutex_lock(&notif->mutex); 77 + guard(mutex)(&notif->mutex); 78 78 if (notif->notify) 79 79 notif->notify(notif->data); 80 - mutex_unlock(&notif->mutex); 81 80 } 82 81 83 82 static void pmf_gpio_init(struct gpio_runtime *rt) ··· 153 154 return -EINVAL; 154 155 } 155 156 156 - mutex_lock(&notif->mutex); 157 + guard(mutex)(&notif->mutex); 157 158 158 159 old = notif->notify; 159 160 160 - if (!old && !notify) { 161 - err = 0; 162 - goto out_unlock; 163 - } 161 + if (!old && !notify) 162 + return 0; 164 163 165 164 if (old && notify) { 166 165 if (old == notify && notif->data == data) 167 166 err = 0; 168 - goto out_unlock; 167 + return err; 169 168 } 170 169 171 170 if (old && !notify) { ··· 175 178 if (!old && notify) { 176 179 irq_client = kzalloc(sizeof(struct pmf_irq_client), 177 180 GFP_KERNEL); 178 - if (!irq_client) { 179 - err = -ENOMEM; 180 - goto out_unlock; 181 - } 181 + if (!irq_client) 182 + return -ENOMEM; 182 183 irq_client->data = notif; 183 184 irq_client->handler = pmf_handle_notify_irq; 184 185 irq_client->owner = THIS_MODULE; ··· 187 192 printk(KERN_ERR "snd-aoa: gpio layer failed to" 188 193 " register %s irq (%d)\n", name, err); 189 194 kfree(irq_client); 190 - goto out_unlock; 195 + return err; 191 196 } 192 197 notif->gpio_private = irq_client; 193 198 } 194 199 notif->notify = notify; 195 200 notif->data = data; 196 201 197 - err = 0; 198 - out_unlock: 199 - mutex_unlock(&notif->mutex); 200 - return err; 202 + return 0; 201 203 } 202 204 203 205 static int pmf_get_detect(struct gpio_runtime *rt,
+25 -51
sound/aoa/soundbus/i2sbus/pcm.c
··· 79 79 u64 formats = 0; 80 80 unsigned int rates = 0; 81 81 struct transfer_info v; 82 - int result = 0; 83 82 int bus_factor = 0, sysclock_factor = 0; 84 83 int found_this; 85 84 86 - mutex_lock(&i2sdev->lock); 85 + guard(mutex)(&i2sdev->lock); 87 86 88 87 get_pcm_info(i2sdev, in, &pi, &other); 89 88 ··· 91 92 92 93 if (pi->active) { 93 94 /* alsa messed up */ 94 - result = -EBUSY; 95 - goto out_unlock; 95 + return -EBUSY; 96 96 } 97 97 98 98 /* we now need to assign the hw */ ··· 115 117 ti++; 116 118 } 117 119 } 118 - if (!masks_inited || !bus_factor || !sysclock_factor) { 119 - result = -ENODEV; 120 - goto out_unlock; 121 - } 120 + if (!masks_inited || !bus_factor || !sysclock_factor) 121 + return -ENODEV; 122 122 /* bus dependent stuff */ 123 123 hw->info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | 124 124 SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_RESUME | ··· 190 194 hw->periods_max = MAX_DBDMA_COMMANDS; 191 195 err = snd_pcm_hw_constraint_integer(pi->substream->runtime, 192 196 SNDRV_PCM_HW_PARAM_PERIODS); 193 - if (err < 0) { 194 - result = err; 195 - goto out_unlock; 196 - } 197 + if (err < 0) 198 + return err; 197 199 list_for_each_entry(cii, &sdev->codec_list, list) { 198 200 if (cii->codec->open) { 199 201 err = cii->codec->open(cii, pi->substream); 200 202 if (err) { 201 - result = err; 202 203 /* unwind */ 203 204 found_this = 0; 204 205 list_for_each_entry_reverse(rev, ··· 207 214 if (rev == cii) 208 215 found_this = 1; 209 216 } 210 - goto out_unlock; 217 + return err; 211 218 } 212 219 } 213 220 } 214 221 215 - out_unlock: 216 - mutex_unlock(&i2sdev->lock); 217 - return result; 222 + return 0; 218 223 } 219 224 220 225 #undef CHECK_RATE ··· 223 232 struct pcm_info *pi; 224 233 int err = 0, tmp; 225 234 226 - mutex_lock(&i2sdev->lock); 235 + guard(mutex)(&i2sdev->lock); 227 236 228 237 get_pcm_info(i2sdev, in, &pi, NULL); 229 238 ··· 237 246 238 247 pi->substream = NULL; 239 248 pi->active = 0; 240 - mutex_unlock(&i2sdev->lock); 241 249 return err; 242 250 } 243 251 ··· 320 330 int input_16bit; 321 331 struct pcm_info *pi, *other; 322 332 int cnt; 323 - int result = 0; 324 333 unsigned int cmd, stopaddr; 325 334 326 - mutex_lock(&i2sdev->lock); 335 + guard(mutex)(&i2sdev->lock); 327 336 328 337 get_pcm_info(i2sdev, in, &pi, &other); 329 338 330 - if (pi->dbdma_ring.running) { 331 - result = -EBUSY; 332 - goto out_unlock; 333 - } 339 + if (pi->dbdma_ring.running) 340 + return -EBUSY; 334 341 if (pi->dbdma_ring.stopping) 335 342 i2sbus_wait_for_stop(i2sdev, pi); 336 343 337 - if (!pi->substream || !pi->substream->runtime) { 338 - result = -EINVAL; 339 - goto out_unlock; 340 - } 344 + if (!pi->substream || !pi->substream->runtime) 345 + return -EINVAL; 341 346 342 347 runtime = pi->substream->runtime; 343 348 pi->active = 1; 344 349 if (other->active && 345 350 ((i2sdev->format != runtime->format) 346 - || (i2sdev->rate != runtime->rate))) { 347 - result = -EINVAL; 348 - goto out_unlock; 349 - } 351 + || (i2sdev->rate != runtime->rate))) 352 + return -EINVAL; 350 353 351 354 i2sdev->format = runtime->format; 352 355 i2sdev->rate = runtime->rate; ··· 395 412 bi.bus_factor = cii->codec->bus_factor; 396 413 break; 397 414 } 398 - if (!bi.bus_factor) { 399 - result = -ENODEV; 400 - goto out_unlock; 401 - } 415 + if (!bi.bus_factor) 416 + return -ENODEV; 402 417 input_16bit = 1; 403 418 break; 404 419 case SNDRV_PCM_FORMAT_S32_BE: ··· 407 426 input_16bit = 0; 408 427 break; 409 428 default: 410 - result = -EINVAL; 411 - goto out_unlock; 429 + return -EINVAL; 412 430 } 413 431 /* we assume all sysclocks are the same! */ 414 432 list_for_each_entry(cii, &i2sdev->sound.codec_list, list) { ··· 418 438 if (clock_and_divisors(bi.sysclock_factor, 419 439 bi.bus_factor, 420 440 runtime->rate, 421 - &sfr) < 0) { 422 - result = -EINVAL; 423 - goto out_unlock; 424 - } 441 + &sfr) < 0) 442 + return -EINVAL; 425 443 switch (bi.bus_factor) { 426 444 case 32: 427 445 sfr |= I2S_SF_SERIAL_FORMAT_I2S_32X; ··· 435 457 int err = 0; 436 458 if (cii->codec->prepare) 437 459 err = cii->codec->prepare(cii, &bi, pi->substream); 438 - if (err) { 439 - result = err; 440 - goto out_unlock; 441 - } 460 + if (err) 461 + return err; 442 462 } 443 463 /* codecs are fine with it, so set our clocks */ 444 464 if (input_16bit) ··· 452 476 /* not locking these is fine since we touch them only in this function */ 453 477 if (in_le32(&i2sdev->intfregs->serial_format) == sfr 454 478 && in_le32(&i2sdev->intfregs->data_word_sizes) == dws) 455 - goto out_unlock; 479 + return 0; 456 480 457 481 /* let's notify the codecs about clocks going away. 458 482 * For now we only do mastering on the i2s cell... */ ··· 490 514 if (cii->codec->switch_clock) 491 515 cii->codec->switch_clock(cii, CLOCK_SWITCH_SLAVE); 492 516 493 - out_unlock: 494 - mutex_unlock(&i2sdev->lock); 495 - return result; 517 + return 0; 496 518 } 497 519 498 520 #ifdef CONFIG_PM