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

ALSA: bcd2000: 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-9-tiwai@suse.de

+4 -12
+4 -12
sound/usb/bcd2000/bcd2000.c
··· 369 369 char usb_path[32]; 370 370 int err; 371 371 372 - mutex_lock(&devices_mutex); 372 + guard(mutex)(&devices_mutex); 373 373 374 374 for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) 375 375 if (!test_bit(card_index, devices_used)) 376 376 break; 377 377 378 - if (card_index >= SNDRV_CARDS) { 379 - mutex_unlock(&devices_mutex); 378 + if (card_index >= SNDRV_CARDS) 380 379 return -ENOENT; 381 - } 382 380 383 381 err = snd_card_new(&interface->dev, index[card_index], id[card_index], 384 382 THIS_MODULE, sizeof(*bcd2k), &card); 385 - if (err < 0) { 386 - mutex_unlock(&devices_mutex); 383 + if (err < 0) 387 384 return err; 388 - } 389 385 390 386 bcd2k = card->private_data; 391 387 bcd2k->dev = interface_to_usbdev(interface); ··· 409 413 usb_set_intfdata(interface, bcd2k); 410 414 set_bit(card_index, devices_used); 411 415 412 - mutex_unlock(&devices_mutex); 413 416 return 0; 414 417 415 418 probe_error: 416 419 dev_info(&bcd2k->dev->dev, PREFIX "error during probing"); 417 420 bcd2000_free_usb_related_resources(bcd2k, interface); 418 421 snd_card_free(card); 419 - mutex_unlock(&devices_mutex); 420 422 return err; 421 423 } 422 424 ··· 425 431 if (!bcd2k) 426 432 return; 427 433 428 - mutex_lock(&devices_mutex); 434 + guard(mutex)(&devices_mutex); 429 435 430 436 /* make sure that userspace cannot create new requests */ 431 437 snd_card_disconnect(bcd2k->card); ··· 435 441 clear_bit(bcd2k->card_index, devices_used); 436 442 437 443 snd_card_free_when_closed(bcd2k->card); 438 - 439 - mutex_unlock(&devices_mutex); 440 444 } 441 445 442 446 static struct usb_driver bcd2000_driver = {