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

ALSA: synth: 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/20250829151335.7342-4-tiwai@suse.de

+12 -28
+2 -4
sound/synth/emux/emux_proc.c
··· 19 19 int i; 20 20 21 21 emu = entry->private_data; 22 - mutex_lock(&emu->register_mutex); 22 + guard(mutex)(&emu->register_mutex); 23 23 if (emu->name) 24 24 snd_iprintf(buf, "Device: %s\n", emu->name); 25 25 snd_iprintf(buf, "Ports: %d\n", emu->num_ports); ··· 38 38 snd_iprintf(buf, "Memory Size: 0\n"); 39 39 } 40 40 if (emu->sflist) { 41 - mutex_lock(&emu->sflist->presets_mutex); 41 + guard(mutex)(&emu->sflist->presets_mutex); 42 42 snd_iprintf(buf, "SoundFonts: %d\n", emu->sflist->fonts_size); 43 43 snd_iprintf(buf, "Instruments: %d\n", emu->sflist->zone_counter); 44 44 snd_iprintf(buf, "Samples: %d\n", emu->sflist->sample_counter); 45 45 snd_iprintf(buf, "Locked Instruments: %d\n", emu->sflist->zone_locked); 46 46 snd_iprintf(buf, "Locked Samples: %d\n", emu->sflist->sample_locked); 47 - mutex_unlock(&emu->sflist->presets_mutex); 48 47 } 49 48 #if 0 /* debug */ 50 49 if (emu->voices[0].state != SNDRV_EMUX_ST_OFF && emu->voices[0].ch >= 0) { ··· 84 85 snd_iprintf(buf, "sample_mode=%x, rate=%x\n", vp->reg.sample_mode, vp->reg.rate_offset); 85 86 } 86 87 #endif 87 - mutex_unlock(&emu->register_mutex); 88 88 } 89 89 90 90
+5 -12
sound/synth/emux/emux_seq.c
··· 272 272 273 273 int snd_emux_inc_count(struct snd_emux *emu) 274 274 { 275 - int ret; 276 - 277 - mutex_lock(&emu->register_mutex); 278 - ret = __snd_emux_inc_count(emu); 279 - mutex_unlock(&emu->register_mutex); 280 - return ret; 275 + guard(mutex)(&emu->register_mutex); 276 + return __snd_emux_inc_count(emu); 281 277 } 282 278 283 279 /* ··· 291 295 292 296 void snd_emux_dec_count(struct snd_emux *emu) 293 297 { 294 - mutex_lock(&emu->register_mutex); 298 + guard(mutex)(&emu->register_mutex); 295 299 __snd_emux_dec_count(emu); 296 - mutex_unlock(&emu->register_mutex); 297 300 } 298 301 299 302 /* ··· 311 316 if (snd_BUG_ON(!emu)) 312 317 return -EINVAL; 313 318 314 - mutex_lock(&emu->register_mutex); 319 + guard(mutex)(&emu->register_mutex); 315 320 snd_emux_init_port(p); 316 321 __snd_emux_inc_count(emu); 317 - mutex_unlock(&emu->register_mutex); 318 322 return 0; 319 323 } 320 324 ··· 333 339 if (snd_BUG_ON(!emu)) 334 340 return -EINVAL; 335 341 336 - mutex_lock(&emu->register_mutex); 342 + guard(mutex)(&emu->register_mutex); 337 343 snd_emux_sounds_off_all(p); 338 344 __snd_emux_dec_count(emu); 339 - mutex_unlock(&emu->register_mutex); 340 345 return 0; 341 346 } 342 347
+5 -12
sound/synth/util_mem.c
··· 124 124 struct snd_util_memblk * 125 125 snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size) 126 126 { 127 - struct snd_util_memblk *blk; 128 - mutex_lock(&hdr->block_mutex); 129 - blk = __snd_util_mem_alloc(hdr, size); 130 - mutex_unlock(&hdr->block_mutex); 131 - return blk; 127 + guard(mutex)(&hdr->block_mutex); 128 + return __snd_util_mem_alloc(hdr, size); 132 129 } 133 130 134 131 ··· 150 153 if (snd_BUG_ON(!hdr || !blk)) 151 154 return -EINVAL; 152 155 153 - mutex_lock(&hdr->block_mutex); 156 + guard(mutex)(&hdr->block_mutex); 154 157 __snd_util_mem_free(hdr, blk); 155 - mutex_unlock(&hdr->block_mutex); 156 158 return 0; 157 159 } 158 160 ··· 160 164 */ 161 165 int snd_util_mem_avail(struct snd_util_memhdr *hdr) 162 166 { 163 - unsigned int size; 164 - mutex_lock(&hdr->block_mutex); 165 - size = hdr->size - hdr->used; 166 - mutex_unlock(&hdr->block_mutex); 167 - return size; 167 + guard(mutex)(&hdr->block_mutex); 168 + return hdr->size - hdr->used; 168 169 } 169 170 170 171