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

ALSA: hiface: 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/20250829150724.6886-5-tiwai@suse.de

+10 -26
+3 -8
sound/usb/hiface/chip.c
··· 101 101 102 102 /* check whether the card is already registered */ 103 103 chip = NULL; 104 - mutex_lock(&register_mutex); 104 + guard(mutex)(&register_mutex); 105 105 106 106 for (i = 0; i < SNDRV_CARDS; i++) 107 107 if (enable[i]) ··· 109 109 110 110 if (i >= SNDRV_CARDS) { 111 111 dev_err(&device->dev, "no available " CARD_NAME " audio device\n"); 112 - ret = -ENODEV; 113 - goto err; 112 + return -ENODEV; 114 113 } 115 114 116 115 ret = hiface_chip_create(intf, device, i, quirk, &chip); 117 116 if (ret < 0) 118 - goto err; 117 + return ret; 119 118 120 119 ret = hiface_pcm_init(chip, quirk ? quirk->extra_freq : 0); 121 120 if (ret < 0) ··· 126 127 goto err_chip_destroy; 127 128 } 128 129 129 - mutex_unlock(&register_mutex); 130 - 131 130 usb_set_intfdata(intf, chip); 132 131 return 0; 133 132 134 133 err_chip_destroy: 135 134 snd_card_free(chip->card); 136 - err: 137 - mutex_unlock(&register_mutex); 138 135 return ret; 139 136 } 140 137
+7 -18
sound/usb/hiface/pcm.c
··· 356 356 if (rt->panic) 357 357 return -EPIPE; 358 358 359 - mutex_lock(&rt->stream_mutex); 359 + guard(mutex)(&rt->stream_mutex); 360 360 alsa_rt->hw = pcm_hw; 361 361 362 362 if (alsa_sub->stream == SNDRV_PCM_STREAM_PLAYBACK) ··· 364 364 365 365 if (!sub) { 366 366 struct device *device = &rt->chip->dev->dev; 367 - mutex_unlock(&rt->stream_mutex); 368 367 dev_err(device, "Invalid stream type\n"); 369 368 return -EINVAL; 370 369 } ··· 376 377 ret = snd_pcm_hw_constraint_list(alsa_sub->runtime, 0, 377 378 SNDRV_PCM_HW_PARAM_RATE, 378 379 &constraints_extra_rates); 379 - if (ret < 0) { 380 - mutex_unlock(&rt->stream_mutex); 380 + if (ret < 0) 381 381 return ret; 382 - } 383 382 } 384 383 385 384 sub->instance = alsa_sub; 386 385 sub->active = false; 387 - mutex_unlock(&rt->stream_mutex); 388 386 return 0; 389 387 } 390 388 ··· 394 398 if (rt->panic) 395 399 return 0; 396 400 397 - mutex_lock(&rt->stream_mutex); 401 + guard(mutex)(&rt->stream_mutex); 398 402 if (sub) { 399 403 hiface_pcm_stream_stop(rt); 400 404 ··· 405 409 spin_unlock_irqrestore(&sub->lock, flags); 406 410 407 411 } 408 - mutex_unlock(&rt->stream_mutex); 409 412 return 0; 410 413 } 411 414 ··· 420 425 if (!sub) 421 426 return -ENODEV; 422 427 423 - mutex_lock(&rt->stream_mutex); 428 + guard(mutex)(&rt->stream_mutex); 424 429 425 430 hiface_pcm_stream_stop(rt); 426 431 ··· 430 435 if (rt->stream_state == STREAM_DISABLED) { 431 436 432 437 ret = hiface_pcm_set_rate(rt, alsa_rt->rate); 433 - if (ret) { 434 - mutex_unlock(&rt->stream_mutex); 438 + if (ret) 435 439 return ret; 436 - } 437 440 ret = hiface_pcm_stream_start(rt); 438 - if (ret) { 439 - mutex_unlock(&rt->stream_mutex); 441 + if (ret) 440 442 return ret; 441 - } 442 443 } 443 - mutex_unlock(&rt->stream_mutex); 444 444 return 0; 445 445 } 446 446 ··· 522 532 if (rt) { 523 533 rt->panic = true; 524 534 525 - mutex_lock(&rt->stream_mutex); 535 + guard(mutex)(&rt->stream_mutex); 526 536 hiface_pcm_stream_stop(rt); 527 - mutex_unlock(&rt->stream_mutex); 528 537 } 529 538 } 530 539