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

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: ppc: 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>

+57 -82
+6 -18
sound/ppc/awacs.c
··· 137 137 int reg = kcontrol->private_value & 0xff; 138 138 int lshift = (kcontrol->private_value >> 8) & 0xff; 139 139 int inverted = (kcontrol->private_value >> 16) & 1; 140 - unsigned long flags; 141 140 int vol[2]; 142 141 143 - spin_lock_irqsave(&chip->reg_lock, flags); 142 + guard(spinlock_irqsave)(&chip->reg_lock); 144 143 vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf; 145 144 vol[1] = chip->awacs_reg[reg] & 0xf; 146 - spin_unlock_irqrestore(&chip->reg_lock, flags); 147 145 if (inverted) { 148 146 vol[0] = 0x0f - vol[0]; 149 147 vol[1] = 0x0f - vol[1]; ··· 159 161 int lshift = (kcontrol->private_value >> 8) & 0xff; 160 162 int inverted = (kcontrol->private_value >> 16) & 1; 161 163 int val, oldval; 162 - unsigned long flags; 163 164 unsigned int vol[2]; 164 165 165 166 vol[0] = ucontrol->value.integer.value[0]; ··· 171 174 } 172 175 vol[0] &= 0x0f; 173 176 vol[1] &= 0x0f; 174 - spin_lock_irqsave(&chip->reg_lock, flags); 177 + guard(spinlock_irqsave)(&chip->reg_lock); 175 178 oldval = chip->awacs_reg[reg]; 176 179 val = oldval & ~(0xf | (0xf << lshift)); 177 180 val |= vol[0] << lshift; 178 181 val |= vol[1]; 179 182 if (oldval != val) 180 183 snd_pmac_awacs_write_reg(chip, reg, val); 181 - spin_unlock_irqrestore(&chip->reg_lock, flags); 182 184 return oldval != reg; 183 185 } 184 186 ··· 200 204 int shift = (kcontrol->private_value >> 8) & 0xff; 201 205 int invert = (kcontrol->private_value >> 16) & 1; 202 206 int val; 203 - unsigned long flags; 204 207 205 - spin_lock_irqsave(&chip->reg_lock, flags); 208 + guard(spinlock_irqsave)(&chip->reg_lock); 206 209 val = (chip->awacs_reg[reg] >> shift) & 1; 207 - spin_unlock_irqrestore(&chip->reg_lock, flags); 208 210 if (invert) 209 211 val = 1 - val; 210 212 ucontrol->value.integer.value[0] = val; ··· 218 224 int invert = (kcontrol->private_value >> 16) & 1; 219 225 int mask = 1 << shift; 220 226 int val, changed; 221 - unsigned long flags; 222 227 223 - spin_lock_irqsave(&chip->reg_lock, flags); 228 + guard(spinlock_irqsave)(&chip->reg_lock); 224 229 val = chip->awacs_reg[reg] & ~mask; 225 230 if (ucontrol->value.integer.value[0] != invert) 226 231 val |= mask; 227 232 changed = chip->awacs_reg[reg] != val; 228 233 if (changed) 229 234 snd_pmac_awacs_write_reg(chip, reg, val); 230 - spin_unlock_irqrestore(&chip->reg_lock, flags); 231 235 return changed; 232 236 } 233 237 ··· 533 541 { 534 542 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 535 543 int val = 0; 536 - unsigned long flags; 537 544 538 - spin_lock_irqsave(&chip->reg_lock, flags); 545 + guard(spinlock_irqsave)(&chip->reg_lock); 539 546 if (chip->awacs_reg[6] & MASK_MIC_BOOST) 540 547 val |= 2; 541 548 if (chip->awacs_reg[0] & MASK_GAINLINE) 542 549 val |= 1; 543 - spin_unlock_irqrestore(&chip->reg_lock, flags); 544 550 ucontrol->value.integer.value[0] = val; 545 551 return 0; 546 552 } ··· 549 559 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 550 560 int changed = 0; 551 561 int val0, val6; 552 - unsigned long flags; 553 562 554 - spin_lock_irqsave(&chip->reg_lock, flags); 563 + guard(spinlock_irqsave)(&chip->reg_lock); 555 564 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE; 556 565 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST; 557 566 if (ucontrol->value.integer.value[0] & 1) ··· 565 576 snd_pmac_awacs_write_reg(chip, 6, val6); 566 577 changed = 1; 567 578 } 568 - spin_unlock_irqrestore(&chip->reg_lock, flags); 569 579 return changed; 570 580 } 571 581
+6 -11
sound/ppc/beep.c
··· 88 88 { 89 89 struct snd_pmac *chip; 90 90 struct pmac_beep *beep; 91 - unsigned long flags; 92 91 int beep_speed = 0; 93 92 int srate; 94 93 int period, ncycles, nsamples; ··· 111 112 return -1; 112 113 113 114 if (! hz) { 114 - spin_lock_irqsave(&chip->reg_lock, flags); 115 + guard(spinlock_irqsave)(&chip->reg_lock); 115 116 if (beep->running) 116 117 snd_pmac_beep_stop(chip); 117 - spin_unlock_irqrestore(&chip->reg_lock, flags); 118 118 return 0; 119 119 } 120 120 ··· 123 125 if (hz <= srate / BEEP_BUFLEN || hz > srate / 2) 124 126 hz = 1000; 125 127 126 - spin_lock_irqsave(&chip->reg_lock, flags); 127 - if (chip->playback.running || chip->capture.running || beep->running) { 128 - spin_unlock_irqrestore(&chip->reg_lock, flags); 129 - return 0; 128 + scoped_guard(spinlock_irqsave, &chip->reg_lock) { 129 + if (chip->playback.running || chip->capture.running || beep->running) 130 + return 0; 131 + beep->running = 1; 130 132 } 131 - beep->running = 1; 132 - spin_unlock_irqrestore(&chip->reg_lock, flags); 133 133 134 134 if (hz == beep->hz && beep->volume == beep->volume_play) { 135 135 nsamples = beep->nsamples; ··· 147 151 beep->nsamples = nsamples; 148 152 } 149 153 150 - spin_lock_irqsave(&chip->reg_lock, flags); 154 + guard(spinlock_irqsave)(&chip->reg_lock); 151 155 snd_pmac_beep_dma_start(chip, beep->nsamples * 4, beep->addr, beep_speed); 152 - spin_unlock_irqrestore(&chip->reg_lock, flags); 153 156 return 0; 154 157 } 155 158
+2 -8
sound/ppc/burgundy.c
··· 59 59 snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr) 60 60 { 61 61 unsigned val = 0; 62 - unsigned long flags; 63 62 64 - spin_lock_irqsave(&chip->reg_lock, flags); 63 + guard(spinlock_irqsave)(&chip->reg_lock); 65 64 66 65 out_le32(&chip->awacs->codec_ctrl, addr + 0x100000); 67 66 snd_pmac_burgundy_busy_wait(chip); ··· 82 83 snd_pmac_burgundy_extend_wait(chip); 83 84 val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<24; 84 85 85 - spin_unlock_irqrestore(&chip->reg_lock, flags); 86 - 87 86 return val; 88 87 } 89 88 ··· 97 100 snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr) 98 101 { 99 102 unsigned val = 0; 100 - unsigned long flags; 101 103 102 - spin_lock_irqsave(&chip->reg_lock, flags); 104 + guard(spinlock_irqsave)(&chip->reg_lock); 103 105 104 106 out_le32(&chip->awacs->codec_ctrl, addr + 0x100000); 105 107 snd_pmac_burgundy_busy_wait(chip); 106 108 snd_pmac_burgundy_extend_wait(chip); 107 109 val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff; 108 - 109 - spin_unlock_irqrestore(&chip->reg_lock, flags); 110 110 111 111 return val; 112 112 }
+43 -45
sound/ppc/pmac.c
··· 206 206 * common to many PowerBook G3 systems and random noise otherwise 207 207 * captured on iBook2's about every third time. -ReneR 208 208 */ 209 - spin_lock_irq(&chip->reg_lock); 210 - snd_pmac_dma_stop(rec); 211 - chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP); 212 - snd_pmac_dma_set_command(rec, &chip->extra_dma); 213 - snd_pmac_dma_run(rec, RUN); 214 - spin_unlock_irq(&chip->reg_lock); 215 - mdelay(5); 216 - spin_lock_irq(&chip->reg_lock); 217 - /* continuous DMA memory type doesn't provide the physical address, 218 - * so we need to resolve the address here... 219 - */ 220 - offset = runtime->dma_addr; 221 - for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) { 222 - cp->phy_addr = cpu_to_le32(offset); 223 - cp->req_count = cpu_to_le16(rec->period_size); 224 - /*cp->res_count = cpu_to_le16(0);*/ 225 - cp->xfer_status = cpu_to_le16(0); 226 - offset += rec->period_size; 209 + scoped_guard(spinlock_irq, &chip->reg_lock) { 210 + snd_pmac_dma_stop(rec); 211 + chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP); 212 + snd_pmac_dma_set_command(rec, &chip->extra_dma); 213 + snd_pmac_dma_run(rec, RUN); 227 214 } 228 - /* make loop */ 229 - cp->command = cpu_to_le16(DBDMA_NOP | BR_ALWAYS); 230 - cp->cmd_dep = cpu_to_le32(rec->cmd.addr); 215 + mdelay(5); 216 + scoped_guard(spinlock_irq, &chip->reg_lock) { 217 + /* continuous DMA memory type doesn't provide the physical address, 218 + * so we need to resolve the address here... 219 + */ 220 + offset = runtime->dma_addr; 221 + for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) { 222 + cp->phy_addr = cpu_to_le32(offset); 223 + cp->req_count = cpu_to_le16(rec->period_size); 224 + /*cp->res_count = cpu_to_le16(0);*/ 225 + cp->xfer_status = cpu_to_le16(0); 226 + offset += rec->period_size; 227 + } 228 + /* make loop */ 229 + cp->command = cpu_to_le16(DBDMA_NOP | BR_ALWAYS); 230 + cp->cmd_dep = cpu_to_le32(rec->cmd.addr); 231 231 232 - snd_pmac_dma_stop(rec); 233 - snd_pmac_dma_set_command(rec, &rec->cmd); 234 - spin_unlock_irq(&chip->reg_lock); 232 + snd_pmac_dma_stop(rec); 233 + snd_pmac_dma_set_command(rec, &rec->cmd); 234 + } 235 235 236 236 return 0; 237 237 } ··· 253 253 return -EBUSY; 254 254 command = (subs->stream == SNDRV_PCM_STREAM_PLAYBACK ? 255 255 OUTPUT_MORE : INPUT_MORE) + INTR_ALWAYS; 256 - spin_lock(&chip->reg_lock); 257 - snd_pmac_beep_stop(chip); 258 - snd_pmac_pcm_set_format(chip); 259 - for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) 260 - out_le16(&cp->command, command); 261 - snd_pmac_dma_set_command(rec, &rec->cmd); 262 - (void)in_le32(&rec->dma->status); 263 - snd_pmac_dma_run(rec, RUN|WAKE); 264 - rec->running = 1; 265 - spin_unlock(&chip->reg_lock); 256 + scoped_guard(spinlock, &chip->reg_lock) { 257 + snd_pmac_beep_stop(chip); 258 + snd_pmac_pcm_set_format(chip); 259 + for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) 260 + out_le16(&cp->command, command); 261 + snd_pmac_dma_set_command(rec, &rec->cmd); 262 + (void)in_le32(&rec->dma->status); 263 + snd_pmac_dma_run(rec, RUN|WAKE); 264 + rec->running = 1; 265 + } 266 266 break; 267 267 268 268 case SNDRV_PCM_TRIGGER_STOP: 269 269 case SNDRV_PCM_TRIGGER_SUSPEND: 270 - spin_lock(&chip->reg_lock); 271 - rec->running = 0; 272 - snd_pmac_dma_stop(rec); 273 - for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) 274 - out_le16(&cp->command, DBDMA_STOP); 275 - spin_unlock(&chip->reg_lock); 270 + scoped_guard(spinlock, &chip->reg_lock) { 271 + rec->running = 0; 272 + snd_pmac_dma_stop(rec); 273 + for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) 274 + out_le16(&cp->command, DBDMA_STOP); 275 + } 276 276 break; 277 277 278 278 default: ··· 1321 1321 1322 1322 void snd_pmac_suspend(struct snd_pmac *chip) 1323 1323 { 1324 - unsigned long flags; 1325 - 1326 1324 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); 1327 1325 if (chip->suspend) 1328 1326 chip->suspend(chip); 1329 - spin_lock_irqsave(&chip->reg_lock, flags); 1330 - snd_pmac_beep_stop(chip); 1331 - spin_unlock_irqrestore(&chip->reg_lock, flags); 1327 + scoped_guard(spinlock_irqsave, &chip->reg_lock) { 1328 + snd_pmac_beep_stop(chip); 1329 + } 1332 1330 if (chip->irq >= 0) 1333 1331 disable_irq(chip->irq); 1334 1332 if (chip->tx_irq >= 0)