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

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

+30 -66
+5 -14
sound/drivers/vx/vx_core.c
··· 344 344 */ 345 345 int vx_send_msg(struct vx_core *chip, struct vx_rmh *rmh) 346 346 { 347 - int err; 348 - 349 - mutex_lock(&chip->lock); 350 - err = vx_send_msg_nolock(chip, rmh); 351 - mutex_unlock(&chip->lock); 352 - return err; 347 + guard(mutex)(&chip->lock); 348 + return vx_send_msg_nolock(chip, rmh); 353 349 } 354 350 355 351 ··· 400 404 */ 401 405 int vx_send_rih(struct vx_core *chip, int cmd) 402 406 { 403 - int err; 404 - 405 - mutex_lock(&chip->lock); 406 - err = vx_send_rih_nolock(chip, cmd); 407 - mutex_unlock(&chip->lock); 408 - return err; 407 + guard(mutex)(&chip->lock); 408 + return vx_send_rih_nolock(chip, cmd); 409 409 } 410 410 411 411 #define END_OF_RESET_WAIT_TIME 500 /* us */ ··· 473 481 int err; 474 482 475 483 vx_init_rmh(&chip->irq_rmh, CMD_TEST_IT); 476 - mutex_lock(&chip->lock); 484 + guard(mutex)(&chip->lock); 477 485 err = vx_send_msg_nolock(chip, &chip->irq_rmh); 478 486 if (err < 0) 479 487 *ret = 0; 480 488 else 481 489 *ret = chip->irq_rmh.Stat[0]; 482 - mutex_unlock(&chip->lock); 483 490 return err; 484 491 } 485 492
+17 -40
sound/drivers/vx/vx_mixer.c
··· 25 25 if (chip->chip_status & VX_STAT_IS_STALE) 26 26 return; 27 27 28 - mutex_lock(&chip->lock); 28 + guard(mutex)(&chip->lock); 29 29 chip->ops->write_codec(chip, codec, data); 30 - mutex_unlock(&chip->lock); 31 30 } 32 31 33 32 /* ··· 165 166 if (chip->chip_status & VX_STAT_IS_STALE) 166 167 return; 167 168 168 - mutex_lock(&chip->lock); 169 + guard(mutex)(&chip->lock); 169 170 chip->ops->change_audio_source(chip, src); 170 - mutex_unlock(&chip->lock); 171 171 } 172 172 173 173 ··· 409 411 { 410 412 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 411 413 int codec = kcontrol->id.index; 412 - mutex_lock(&chip->mixer_mutex); 414 + 415 + guard(mutex)(&chip->mixer_mutex); 413 416 ucontrol->value.integer.value[0] = chip->output_level[codec][0]; 414 417 ucontrol->value.integer.value[1] = chip->output_level[codec][1]; 415 - mutex_unlock(&chip->mixer_mutex); 416 418 return 0; 417 419 } 418 420 ··· 427 429 val[1] = ucontrol->value.integer.value[1]; 428 430 if (val[0] > vmax || val[1] > vmax) 429 431 return -EINVAL; 430 - mutex_lock(&chip->mixer_mutex); 432 + guard(mutex)(&chip->mixer_mutex); 431 433 if (val[0] != chip->output_level[codec][0] || 432 434 val[1] != chip->output_level[codec][1]) { 433 435 vx_set_analog_output_level(chip, codec, val[0], val[1]); 434 436 chip->output_level[codec][0] = val[0]; 435 437 chip->output_level[codec][1] = val[1]; 436 - mutex_unlock(&chip->mixer_mutex); 437 438 return 1; 438 439 } 439 - mutex_unlock(&chip->mixer_mutex); 440 440 return 0; 441 441 } 442 442 ··· 486 490 if (ucontrol->value.enumerated.item[0] > 1) 487 491 return -EINVAL; 488 492 } 489 - mutex_lock(&chip->mixer_mutex); 493 + guard(mutex)(&chip->mixer_mutex); 490 494 if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) { 491 495 chip->audio_source_target = ucontrol->value.enumerated.item[0]; 492 496 vx_sync_audio_source(chip); 493 - mutex_unlock(&chip->mixer_mutex); 494 497 return 1; 495 498 } 496 - mutex_unlock(&chip->mixer_mutex); 497 499 return 0; 498 500 } 499 501 ··· 528 534 529 535 if (ucontrol->value.enumerated.item[0] > 2) 530 536 return -EINVAL; 531 - mutex_lock(&chip->mixer_mutex); 537 + guard(mutex)(&chip->mixer_mutex); 532 538 if (chip->clock_mode != ucontrol->value.enumerated.item[0]) { 533 539 chip->clock_mode = ucontrol->value.enumerated.item[0]; 534 540 vx_set_clock(chip, chip->freq); 535 - mutex_unlock(&chip->mixer_mutex); 536 541 return 1; 537 542 } 538 - mutex_unlock(&chip->mixer_mutex); 539 543 return 0; 540 544 } 541 545 ··· 563 571 int audio = kcontrol->private_value & 0xff; 564 572 int capture = (kcontrol->private_value >> 8) & 1; 565 573 566 - mutex_lock(&chip->mixer_mutex); 574 + guard(mutex)(&chip->mixer_mutex); 567 575 ucontrol->value.integer.value[0] = chip->audio_gain[capture][audio]; 568 576 ucontrol->value.integer.value[1] = chip->audio_gain[capture][audio+1]; 569 - mutex_unlock(&chip->mixer_mutex); 570 577 return 0; 571 578 } 572 579 ··· 580 589 val[1] = ucontrol->value.integer.value[1]; 581 590 if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) 582 591 return -EINVAL; 583 - mutex_lock(&chip->mixer_mutex); 592 + guard(mutex)(&chip->mixer_mutex); 584 593 if (val[0] != chip->audio_gain[capture][audio] || 585 594 val[1] != chip->audio_gain[capture][audio+1]) { 586 595 vx_set_audio_gain(chip, audio, capture, val[0]); 587 596 vx_set_audio_gain(chip, audio+1, capture, val[1]); 588 - mutex_unlock(&chip->mixer_mutex); 589 597 return 1; 590 598 } 591 - mutex_unlock(&chip->mixer_mutex); 592 599 return 0; 593 600 } 594 601 ··· 595 606 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 596 607 int audio = kcontrol->private_value & 0xff; 597 608 598 - mutex_lock(&chip->mixer_mutex); 609 + guard(mutex)(&chip->mixer_mutex); 599 610 ucontrol->value.integer.value[0] = chip->audio_monitor[audio]; 600 611 ucontrol->value.integer.value[1] = chip->audio_monitor[audio+1]; 601 - mutex_unlock(&chip->mixer_mutex); 602 612 return 0; 603 613 } 604 614 ··· 612 624 if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) 613 625 return -EINVAL; 614 626 615 - mutex_lock(&chip->mixer_mutex); 627 + guard(mutex)(&chip->mixer_mutex); 616 628 if (val[0] != chip->audio_monitor[audio] || 617 629 val[1] != chip->audio_monitor[audio+1]) { 618 630 vx_set_monitor_level(chip, audio, val[0], 619 631 chip->audio_monitor_active[audio]); 620 632 vx_set_monitor_level(chip, audio+1, val[1], 621 633 chip->audio_monitor_active[audio+1]); 622 - mutex_unlock(&chip->mixer_mutex); 623 634 return 1; 624 635 } 625 - mutex_unlock(&chip->mixer_mutex); 626 636 return 0; 627 637 } 628 638 ··· 631 645 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 632 646 int audio = kcontrol->private_value & 0xff; 633 647 634 - mutex_lock(&chip->mixer_mutex); 648 + guard(mutex)(&chip->mixer_mutex); 635 649 ucontrol->value.integer.value[0] = chip->audio_active[audio]; 636 650 ucontrol->value.integer.value[1] = chip->audio_active[audio+1]; 637 - mutex_unlock(&chip->mixer_mutex); 638 651 return 0; 639 652 } 640 653 ··· 642 657 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 643 658 int audio = kcontrol->private_value & 0xff; 644 659 645 - mutex_lock(&chip->mixer_mutex); 660 + guard(mutex)(&chip->mixer_mutex); 646 661 if (ucontrol->value.integer.value[0] != chip->audio_active[audio] || 647 662 ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) { 648 663 vx_set_audio_switch(chip, audio, 649 664 !!ucontrol->value.integer.value[0]); 650 665 vx_set_audio_switch(chip, audio+1, 651 666 !!ucontrol->value.integer.value[1]); 652 - mutex_unlock(&chip->mixer_mutex); 653 667 return 1; 654 668 } 655 - mutex_unlock(&chip->mixer_mutex); 656 669 return 0; 657 670 } 658 671 ··· 659 676 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 660 677 int audio = kcontrol->private_value & 0xff; 661 678 662 - mutex_lock(&chip->mixer_mutex); 679 + guard(mutex)(&chip->mixer_mutex); 663 680 ucontrol->value.integer.value[0] = chip->audio_monitor_active[audio]; 664 681 ucontrol->value.integer.value[1] = chip->audio_monitor_active[audio+1]; 665 - mutex_unlock(&chip->mixer_mutex); 666 682 return 0; 667 683 } 668 684 ··· 670 688 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 671 689 int audio = kcontrol->private_value & 0xff; 672 690 673 - mutex_lock(&chip->mixer_mutex); 691 + guard(mutex)(&chip->mixer_mutex); 674 692 if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] || 675 693 ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) { 676 694 vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], 677 695 !!ucontrol->value.integer.value[0]); 678 696 vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], 679 697 !!ucontrol->value.integer.value[1]); 680 - mutex_unlock(&chip->mixer_mutex); 681 698 return 1; 682 699 } 683 - mutex_unlock(&chip->mixer_mutex); 684 700 return 0; 685 701 } 686 702 ··· 734 754 { 735 755 struct vx_core *chip = snd_kcontrol_chip(kcontrol); 736 756 737 - mutex_lock(&chip->mixer_mutex); 757 + guard(mutex)(&chip->mixer_mutex); 738 758 ucontrol->value.iec958.status[0] = (chip->uer_bits >> 0) & 0xff; 739 759 ucontrol->value.iec958.status[1] = (chip->uer_bits >> 8) & 0xff; 740 760 ucontrol->value.iec958.status[2] = (chip->uer_bits >> 16) & 0xff; 741 761 ucontrol->value.iec958.status[3] = (chip->uer_bits >> 24) & 0xff; 742 - mutex_unlock(&chip->mixer_mutex); 743 762 return 0; 744 763 } 745 764 ··· 760 781 (ucontrol->value.iec958.status[1] << 8) | 761 782 (ucontrol->value.iec958.status[2] << 16) | 762 783 (ucontrol->value.iec958.status[3] << 24); 763 - mutex_lock(&chip->mixer_mutex); 784 + guard(mutex)(&chip->mixer_mutex); 764 785 if (chip->uer_bits != val) { 765 786 chip->uer_bits = val; 766 787 vx_set_iec958_status(chip, val); 767 - mutex_unlock(&chip->mixer_mutex); 768 788 return 1; 769 789 } 770 - mutex_unlock(&chip->mixer_mutex); 771 790 return 0; 772 791 } 773 792
+1 -2
sound/drivers/vx/vx_pcm.c
··· 630 630 /* we don't need irqsave here, because this function 631 631 * is called from either trigger callback or irq handler 632 632 */ 633 - mutex_lock(&chip->lock); 633 + guard(mutex)(&chip->lock); 634 634 vx_pseudo_dma_write(chip, runtime, pipe, size); 635 635 err = vx_notify_end_of_buffer(chip, pipe); 636 636 /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ 637 637 vx_send_rih_nolock(chip, IRQ_CONNECT_STREAM_NEXT); 638 - mutex_unlock(&chip->lock); 639 638 return err; 640 639 } 641 640
+7 -10
sound/drivers/vx/vx_uer.c
··· 49 49 { 50 50 int val; 51 51 52 - mutex_lock(&chip->lock); 52 + guard(mutex)(&chip->lock); 53 53 if (chip->type >= VX_TYPE_VXPOCKET) { 54 54 vx_outb(chip, CSUER, 1); /* read */ 55 55 vx_outb(chip, RUER, index & XX_UER_CBITS_OFFSET_MASK); ··· 59 59 vx_outl(chip, RUER, index & XX_UER_CBITS_OFFSET_MASK); 60 60 val = (vx_inl(chip, RUER) >> 7) & 0x01; 61 61 } 62 - mutex_unlock(&chip->lock); 63 62 return val; 64 63 } 65 64 ··· 70 71 static void vx_write_one_cbit(struct vx_core *chip, int index, int val) 71 72 { 72 73 val = !!val; /* 0 or 1 */ 73 - mutex_lock(&chip->lock); 74 + guard(mutex)(&chip->lock); 74 75 if (vx_is_pcmcia(chip)) { 75 76 vx_outb(chip, CSUER, 0); /* write */ 76 77 vx_outb(chip, RUER, (val << 7) | (index & XX_UER_CBITS_OFFSET_MASK)); ··· 78 79 vx_outl(chip, CSUER, 0); /* write */ 79 80 vx_outl(chip, RUER, (val << 7) | (index & XX_UER_CBITS_OFFSET_MASK)); 80 81 } 81 - mutex_unlock(&chip->lock); 82 82 } 83 83 84 84 /* ··· 176 178 { 177 179 /* we mute DAC to prevent clicks */ 178 180 vx_toggle_dac_mute(chip, 1); 179 - mutex_lock(&chip->lock); 180 - chip->ops->set_clock_source(chip, source); 181 - chip->clock_source = source; 182 - mutex_unlock(&chip->lock); 181 + scoped_guard(mutex, &chip->lock) { 182 + chip->ops->set_clock_source(chip, source); 183 + chip->clock_source = source; 184 + } 183 185 /* unmute */ 184 186 vx_toggle_dac_mute(chip, 0); 185 187 } ··· 196 198 clock = vx_calc_clock_from_freq(chip, freq); 197 199 dev_dbg(chip->card->dev, 198 200 "set internal clock to 0x%x from freq %d\n", clock, freq); 199 - mutex_lock(&chip->lock); 201 + guard(mutex)(&chip->lock); 200 202 if (vx_is_pcmcia(chip)) { 201 203 vx_outb(chip, HIFREQ, (clock >> 8) & 0x0f); 202 204 vx_outb(chip, LOFREQ, clock & 0xff); ··· 204 206 vx_outl(chip, HIFREQ, (clock >> 8) & 0x0f); 205 207 vx_outl(chip, LOFREQ, clock & 0xff); 206 208 } 207 - mutex_unlock(&chip->lock); 208 209 } 209 210 210 211