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

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

+20 -39
+20 -39
sound/drivers/mtpav.c
··· 304 304 { 305 305 struct mtpav *mtp_card = substream->rmidi->private_data; 306 306 struct mtpav_port *portp = &mtp_card->ports[substream->number]; 307 - unsigned long flags; 308 307 309 - spin_lock_irqsave(&mtp_card->spinlock, flags); 308 + guard(spinlock_irqsave)(&mtp_card->spinlock); 310 309 snd_mtpav_output_port_write(mtp_card, portp, substream); 311 - spin_unlock_irqrestore(&mtp_card->spinlock, flags); 312 310 } 313 311 314 312 ··· 332 334 { 333 335 struct mtpav *mtp_card = substream->rmidi->private_data; 334 336 struct mtpav_port *portp = &mtp_card->ports[substream->number]; 335 - unsigned long flags; 336 337 337 - spin_lock_irqsave(&mtp_card->spinlock, flags); 338 + guard(spinlock_irqsave)(&mtp_card->spinlock); 338 339 portp->mode |= MTPAV_MODE_INPUT_OPENED; 339 340 portp->input = substream; 340 341 if (mtp_card->share_irq++ == 0) 341 342 snd_mtpav_mputreg(mtp_card, CREG, (SIGC_INTEN | SIGC_WRITE)); // enable pport interrupts 342 - spin_unlock_irqrestore(&mtp_card->spinlock, flags); 343 343 return 0; 344 344 } 345 345 ··· 348 352 { 349 353 struct mtpav *mtp_card = substream->rmidi->private_data; 350 354 struct mtpav_port *portp = &mtp_card->ports[substream->number]; 351 - unsigned long flags; 352 355 353 - spin_lock_irqsave(&mtp_card->spinlock, flags); 356 + guard(spinlock_irqsave)(&mtp_card->spinlock); 354 357 portp->mode &= ~MTPAV_MODE_INPUT_OPENED; 355 358 portp->input = NULL; 356 359 if (--mtp_card->share_irq == 0) 357 360 snd_mtpav_mputreg(mtp_card, CREG, 0); // disable pport interrupts 358 - spin_unlock_irqrestore(&mtp_card->spinlock, flags); 359 361 return 0; 360 362 } 361 363 ··· 364 370 { 365 371 struct mtpav *mtp_card = substream->rmidi->private_data; 366 372 struct mtpav_port *portp = &mtp_card->ports[substream->number]; 367 - unsigned long flags; 368 373 369 - spin_lock_irqsave(&mtp_card->spinlock, flags); 374 + guard(spinlock_irqsave)(&mtp_card->spinlock); 370 375 if (up) 371 376 portp->mode |= MTPAV_MODE_INPUT_TRIGGERED; 372 377 else 373 378 portp->mode &= ~MTPAV_MODE_INPUT_TRIGGERED; 374 - spin_unlock_irqrestore(&mtp_card->spinlock, flags); 375 - 376 379 } 377 380 378 381 ··· 379 388 380 389 static void snd_mtpav_output_timer(struct timer_list *t) 381 390 { 382 - unsigned long flags; 383 391 struct mtpav *chip = timer_container_of(chip, t, timer); 384 392 int p; 385 393 386 - spin_lock_irqsave(&chip->spinlock, flags); 394 + guard(spinlock_irqsave)(&chip->spinlock); 387 395 /* reprogram timer */ 388 396 mod_timer(&chip->timer, 1 + jiffies); 389 397 /* process each port */ ··· 391 401 if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output) 392 402 snd_mtpav_output_port_write(chip, portp, portp->output); 393 403 } 394 - spin_unlock_irqrestore(&chip->spinlock, flags); 395 404 } 396 405 397 406 /* spinlock held! */ ··· 412 423 { 413 424 struct mtpav *mtp_card = substream->rmidi->private_data; 414 425 struct mtpav_port *portp = &mtp_card->ports[substream->number]; 415 - unsigned long flags; 416 426 417 - spin_lock_irqsave(&mtp_card->spinlock, flags); 427 + guard(spinlock_irqsave)(&mtp_card->spinlock); 418 428 portp->mode |= MTPAV_MODE_OUTPUT_OPENED; 419 429 portp->output = substream; 420 - spin_unlock_irqrestore(&mtp_card->spinlock, flags); 421 430 return 0; 422 431 }; 423 432 ··· 426 439 { 427 440 struct mtpav *mtp_card = substream->rmidi->private_data; 428 441 struct mtpav_port *portp = &mtp_card->ports[substream->number]; 429 - unsigned long flags; 430 442 431 - spin_lock_irqsave(&mtp_card->spinlock, flags); 443 + guard(spinlock_irqsave)(&mtp_card->spinlock); 432 444 portp->mode &= ~MTPAV_MODE_OUTPUT_OPENED; 433 445 portp->output = NULL; 434 - spin_unlock_irqrestore(&mtp_card->spinlock, flags); 435 446 return 0; 436 447 }; 437 448 ··· 440 455 { 441 456 struct mtpav *mtp_card = substream->rmidi->private_data; 442 457 struct mtpav_port *portp = &mtp_card->ports[substream->number]; 443 - unsigned long flags; 444 458 445 - spin_lock_irqsave(&mtp_card->spinlock, flags); 446 - if (up) { 447 - if (! (portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED)) { 448 - if (mtp_card->istimer++ == 0) 449 - snd_mtpav_add_output_timer(mtp_card); 450 - portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED; 459 + scoped_guard(spinlock_irqsave, &mtp_card->spinlock) { 460 + if (up) { 461 + if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED)) { 462 + if (mtp_card->istimer++ == 0) 463 + snd_mtpav_add_output_timer(mtp_card); 464 + portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED; 465 + } 466 + } else { 467 + portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED; 468 + if (--mtp_card->istimer == 0) 469 + snd_mtpav_remove_output_timer(mtp_card); 451 470 } 452 - } else { 453 - portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED; 454 - if (--mtp_card->istimer == 0) 455 - snd_mtpav_remove_output_timer(mtp_card); 456 471 } 457 - spin_unlock_irqrestore(&mtp_card->spinlock, flags); 458 472 459 473 if (up) 460 474 snd_mtpav_output_write(substream); ··· 534 550 { 535 551 struct mtpav *mcard = dev_id; 536 552 537 - spin_lock(&mcard->spinlock); 553 + guard(spinlock)(&mcard->spinlock); 538 554 snd_mtpav_read_bytes(mcard); 539 - spin_unlock(&mcard->spinlock); 540 555 return IRQ_HANDLED; 541 556 } 542 557 ··· 641 658 static void snd_mtpav_free(struct snd_card *card) 642 659 { 643 660 struct mtpav *crd = card->private_data; 644 - unsigned long flags; 645 661 646 - spin_lock_irqsave(&crd->spinlock, flags); 662 + guard(spinlock_irqsave)(&crd->spinlock); 647 663 if (crd->istimer > 0) 648 664 snd_mtpav_remove_output_timer(crd); 649 - spin_unlock_irqrestore(&crd->spinlock, flags); 650 665 } 651 666 652 667 /*