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

ALSA: sscape: 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/20250829145300.5460-16-tiwai@suse.de

+81 -103
+81 -103
sound/isa/sscape.c
··· 200 200 static void sscape_write(struct soundscape *s, enum GA_REG reg, 201 201 unsigned char val) 202 202 { 203 - unsigned long flags; 204 - 205 - spin_lock_irqsave(&s->lock, flags); 203 + guard(spinlock_irqsave)(&s->lock); 206 204 sscape_write_unsafe(s->io_base, reg, val); 207 - spin_unlock_irqrestore(&s->lock, flags); 208 205 } 209 206 210 207 /* ··· 364 367 unsigned long end_time = jiffies + msecs_to_jiffies(timeout); 365 368 366 369 do { 367 - unsigned long flags; 368 370 int x; 369 371 370 - spin_lock_irqsave(&s->lock, flags); 371 - x = host_read_unsafe(s->io_base); 372 - spin_unlock_irqrestore(&s->lock, flags); 372 + scoped_guard(spinlock_irqsave, &s->lock) { 373 + x = host_read_unsafe(s->io_base); 374 + } 373 375 if (x == 0xfe || x == 0xff) 374 376 return 1; 375 377 ··· 390 394 unsigned long end_time = jiffies + msecs_to_jiffies(timeout); 391 395 392 396 do { 393 - unsigned long flags; 394 397 int x; 395 398 396 - spin_lock_irqsave(&s->lock, flags); 397 - x = host_read_unsafe(s->io_base); 398 - spin_unlock_irqrestore(&s->lock, flags); 399 + scoped_guard(spinlock_irqsave, &s->lock) { 400 + x = host_read_unsafe(s->io_base); 401 + } 399 402 if (x == 0xfe) 400 403 return 1; 401 404 ··· 410 415 static int upload_dma_data(struct soundscape *s, const unsigned char *data, 411 416 size_t size) 412 417 { 413 - unsigned long flags; 414 418 struct snd_dma_buffer dma; 415 419 int ret; 416 420 unsigned char val; ··· 417 423 if (!get_dmabuf(s, &dma, PAGE_ALIGN(32 * 1024))) 418 424 return -ENOMEM; 419 425 420 - spin_lock_irqsave(&s->lock, flags); 426 + scoped_guard(spinlock_irqsave, &s->lock) { 421 427 422 - /* 423 - * Reset the board ... 424 - */ 425 - val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); 426 - sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val & 0x3f); 428 + /* 429 + * Reset the board ... 430 + */ 431 + val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); 432 + sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val & 0x3f); 427 433 428 - /* 429 - * Enable the DMA channels and configure them ... 430 - */ 431 - val = (s->chip->dma1 << 4) | DMA_8BIT; 432 - sscape_write_unsafe(s->io_base, GA_DMAA_REG, val); 433 - sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20); 434 + /* 435 + * Enable the DMA channels and configure them ... 436 + */ 437 + val = (s->chip->dma1 << 4) | DMA_8BIT; 438 + sscape_write_unsafe(s->io_base, GA_DMAA_REG, val); 439 + sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20); 434 440 435 - /* 436 - * Take the board out of reset ... 437 - */ 438 - val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); 439 - sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x80); 441 + /* 442 + * Take the board out of reset ... 443 + */ 444 + val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); 445 + sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x80); 440 446 441 - /* 442 - * Upload the firmware to the SoundScape 443 - * board through the DMA channel ... 444 - */ 445 - while (size != 0) { 446 - unsigned long len; 447 + /* 448 + * Upload the firmware to the SoundScape 449 + * board through the DMA channel ... 450 + */ 451 + while (size != 0) { 452 + unsigned long len; 447 453 448 - len = min(size, dma.bytes); 449 - memcpy(dma.area, data, len); 450 - data += len; 451 - size -= len; 454 + len = min(size, dma.bytes); 455 + memcpy(dma.area, data, len); 456 + data += len; 457 + size -= len; 452 458 453 - snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE); 454 - sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG); 455 - if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) { 456 - /* 457 - * Don't forget to release this spinlock we're holding 458 - */ 459 - spin_unlock_irqrestore(&s->lock, flags); 459 + snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE); 460 + sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG); 461 + if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) { 462 + dev_err(s->dev, "sscape: DMA upload has timed out\n"); 463 + ret = -EAGAIN; 464 + goto _release_dma; 465 + } 466 + } /* while */ 460 467 461 - dev_err(s->dev, "sscape: DMA upload has timed out\n"); 462 - ret = -EAGAIN; 463 - goto _release_dma; 464 - } 465 - } /* while */ 468 + set_host_mode_unsafe(s->io_base); 469 + outb(0x0, s->io_base); 466 470 467 - set_host_mode_unsafe(s->io_base); 468 - outb(0x0, s->io_base); 469 - 470 - /* 471 - * Boot the board ... (I think) 472 - */ 473 - val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); 474 - sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x40); 475 - spin_unlock_irqrestore(&s->lock, flags); 471 + /* 472 + * Boot the board ... (I think) 473 + */ 474 + val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG); 475 + sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x40); 476 + } 476 477 477 478 /* 478 479 * If all has gone well, then the board should acknowledge ··· 502 513 static int sscape_upload_bootblock(struct snd_card *card) 503 514 { 504 515 struct soundscape *sscape = get_card_soundscape(card); 505 - unsigned long flags; 506 516 const struct firmware *init_fw = NULL; 507 517 int data = 0; 508 518 int ret; ··· 515 527 516 528 release_firmware(init_fw); 517 529 518 - spin_lock_irqsave(&sscape->lock, flags); 530 + guard(spinlock_irqsave)(&sscape->lock); 519 531 if (ret == 0) 520 532 data = host_read_ctrl_unsafe(sscape->io_base, 100); 521 533 522 534 if (data & 0x10) 523 535 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f); 524 - 525 - spin_unlock_irqrestore(&sscape->lock, flags); 526 536 527 537 data &= 0xf; 528 538 if (ret == 0 && data > 7) { ··· 579 593 struct snd_wss *chip = snd_kcontrol_chip(kctl); 580 594 struct snd_card *card = chip->card; 581 595 register struct soundscape *s = get_card_soundscape(card); 582 - unsigned long flags; 583 596 584 - spin_lock_irqsave(&s->lock, flags); 597 + guard(spinlock_irqsave)(&s->lock); 585 598 uctl->value.integer.value[0] = s->midi_vol; 586 - spin_unlock_irqrestore(&s->lock, flags); 587 599 return 0; 588 600 } 589 601 ··· 591 607 struct snd_wss *chip = snd_kcontrol_chip(kctl); 592 608 struct snd_card *card = chip->card; 593 609 struct soundscape *s = get_card_soundscape(card); 594 - unsigned long flags; 595 610 int change; 596 611 unsigned char new_val; 597 612 598 - spin_lock_irqsave(&s->lock, flags); 613 + guard(spinlock_irqsave)(&s->lock); 599 614 600 615 new_val = uctl->value.integer.value[0] & 127; 601 616 /* ··· 625 642 */ 626 643 set_midi_mode_unsafe(s->io_base); 627 644 628 - spin_unlock_irqrestore(&s->lock, flags); 629 645 return change; 630 646 } 631 647 ··· 834 852 err = snd_wss_create(card, port, -1, irq, dma1, dma2, 835 853 codec_type, WSS_HWSHARE_DMA1, &chip); 836 854 if (!err) { 837 - unsigned long flags; 838 - 839 855 if (sscape->type != SSCAPE_VIVO) { 840 856 /* 841 857 * The input clock frequency on the SoundScape must ··· 841 861 * to get the playback to sound correct ... 842 862 */ 843 863 snd_wss_mce_up(chip); 844 - spin_lock_irqsave(&chip->reg_lock, flags); 845 - snd_wss_out(chip, AD1845_CLOCK, 0x20); 846 - spin_unlock_irqrestore(&chip->reg_lock, flags); 864 + scoped_guard(spinlock_irqsave, &chip->reg_lock) { 865 + snd_wss_out(chip, AD1845_CLOCK, 0x20); 866 + } 847 867 snd_wss_mce_down(chip); 848 868 849 869 } ··· 900 920 unsigned mpu_irq_cfg; 901 921 struct resource *io_res; 902 922 struct resource *wss_res; 903 - unsigned long flags; 904 923 int err; 905 924 int val; 906 925 const char *name; ··· 985 1006 * Tell the on-board devices where their resources are (I think - 986 1007 * I can't be sure without a datasheet ... So many magic values!) 987 1008 */ 988 - spin_lock_irqsave(&sscape->lock, flags); 1009 + scoped_guard(spinlock_irqsave, &sscape->lock) { 989 1010 990 - sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); 991 - sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00); 1011 + sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); 1012 + sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00); 992 1013 993 - /* 994 - * Enable and configure the DMA channels ... 995 - */ 996 - sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50); 997 - dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70); 998 - sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg); 999 - sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20); 1014 + /* 1015 + * Enable and configure the DMA channels ... 1016 + */ 1017 + sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50); 1018 + dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70); 1019 + sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg); 1020 + sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20); 1000 1021 1001 - mpu_irq_cfg |= mpu_irq_cfg << 2; 1002 - val = sscape_read_unsafe(sscape->io_base, GA_HMCTL_REG) & 0xF7; 1003 - if (joystick[dev]) 1004 - val |= 8; 1005 - sscape_write_unsafe(sscape->io_base, GA_HMCTL_REG, val | 0x10); 1006 - sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg); 1007 - sscape_write_unsafe(sscape->io_base, 1008 - GA_CDCFG_REG, 0x09 | DMA_8BIT 1009 - | (dma[dev] << 4) | (irq_cfg << 1)); 1010 - /* 1011 - * Enable the master IRQ ... 1012 - */ 1013 - sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x80); 1022 + mpu_irq_cfg |= mpu_irq_cfg << 2; 1023 + val = sscape_read_unsafe(sscape->io_base, GA_HMCTL_REG) & 0xF7; 1024 + if (joystick[dev]) 1025 + val |= 8; 1026 + sscape_write_unsafe(sscape->io_base, GA_HMCTL_REG, val | 0x10); 1027 + sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg); 1028 + sscape_write_unsafe(sscape->io_base, 1029 + GA_CDCFG_REG, 0x09 | DMA_8BIT 1030 + | (dma[dev] << 4) | (irq_cfg << 1)); 1031 + /* 1032 + * Enable the master IRQ ... 1033 + */ 1034 + sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x80); 1014 1035 1015 - spin_unlock_irqrestore(&sscape->lock, flags); 1036 + } 1016 1037 1017 1038 /* 1018 1039 * We have now enabled the codec chip, and so we should ··· 1052 1073 /* 1053 1074 * Initialize mixer 1054 1075 */ 1055 - spin_lock_irqsave(&sscape->lock, flags); 1076 + guard(spinlock_irqsave)(&sscape->lock); 1056 1077 sscape->midi_vol = 0; 1057 1078 host_write_ctrl_unsafe(sscape->io_base, 1058 1079 CMD_SET_MIDI_VOL, 100); ··· 1069 1090 host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100); 1070 1091 1071 1092 set_midi_mode_unsafe(sscape->io_base); 1072 - spin_unlock_irqrestore(&sscape->lock, flags); 1073 1093 } 1074 1094 } 1075 1095