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: ump: Use guard() for locking

We can simplify the code gracefully with new guard() macro and co for
automatic cleanup of locks.

Only the code refactoring, and no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240227085306.9764-2-tiwai@suse.de

+12 -23
+12 -23
sound/core/ump.c
··· 985 985 struct snd_ump_endpoint *ump = substream->rmidi->private_data; 986 986 int dir = substream->stream; 987 987 int group = ump->legacy_mapping[substream->number]; 988 - int err = 0; 988 + int err; 989 989 990 - mutex_lock(&ump->open_mutex); 991 - if (ump->legacy_substreams[dir][group]) { 992 - err = -EBUSY; 993 - goto unlock; 994 - } 990 + guard(mutex)(&ump->open_mutex); 991 + if (ump->legacy_substreams[dir][group]) 992 + return -EBUSY; 995 993 if (dir == SNDRV_RAWMIDI_STREAM_OUTPUT) { 996 994 if (!ump->legacy_out_opens) { 997 995 err = snd_rawmidi_kernel_open(&ump->core, 0, ··· 997 999 SNDRV_RAWMIDI_LFLG_APPEND, 998 1000 &ump->legacy_out_rfile); 999 1001 if (err < 0) 1000 - goto unlock; 1002 + return err; 1001 1003 } 1002 1004 ump->legacy_out_opens++; 1003 1005 snd_ump_convert_reset(&ump->out_cvts[group]); 1004 1006 } 1005 - spin_lock_irq(&ump->legacy_locks[dir]); 1007 + guard(spinlock_irq)(&ump->legacy_locks[dir]); 1006 1008 ump->legacy_substreams[dir][group] = substream; 1007 - spin_unlock_irq(&ump->legacy_locks[dir]); 1008 - unlock: 1009 - mutex_unlock(&ump->open_mutex); 1010 - return err; 1009 + return 0; 1011 1010 } 1012 1011 1013 1012 static int snd_ump_legacy_close(struct snd_rawmidi_substream *substream) ··· 1013 1018 int dir = substream->stream; 1014 1019 int group = ump->legacy_mapping[substream->number]; 1015 1020 1016 - mutex_lock(&ump->open_mutex); 1017 - spin_lock_irq(&ump->legacy_locks[dir]); 1018 - ump->legacy_substreams[dir][group] = NULL; 1019 - spin_unlock_irq(&ump->legacy_locks[dir]); 1021 + guard(mutex)(&ump->open_mutex); 1022 + scoped_guard(spinlock_irq, &ump->legacy_locks[dir]) 1023 + ump->legacy_substreams[dir][group] = NULL; 1020 1024 if (dir == SNDRV_RAWMIDI_STREAM_OUTPUT) { 1021 1025 if (!--ump->legacy_out_opens) 1022 1026 snd_rawmidi_kernel_release(&ump->legacy_out_rfile); 1023 1027 } 1024 - mutex_unlock(&ump->open_mutex); 1025 1028 return 0; 1026 1029 } 1027 1030 ··· 1071 1078 const int dir = SNDRV_RAWMIDI_STREAM_OUTPUT; 1072 1079 unsigned char c; 1073 1080 int group, size = 0; 1074 - unsigned long flags; 1075 1081 1076 1082 if (!ump->out_cvts || !ump->legacy_out_opens) 1077 1083 return 0; 1078 1084 1079 - spin_lock_irqsave(&ump->legacy_locks[dir], flags); 1085 + guard(spinlock_irqsave)(&ump->legacy_locks[dir]); 1080 1086 for (group = 0; group < SNDRV_UMP_MAX_GROUPS; group++) { 1081 1087 substream = ump->legacy_substreams[dir][group]; 1082 1088 if (!substream) ··· 1091 1099 break; 1092 1100 } 1093 1101 } 1094 - spin_unlock_irqrestore(&ump->legacy_locks[dir], flags); 1095 1102 return size; 1096 1103 } 1097 1104 ··· 1100 1109 struct snd_rawmidi_substream *substream; 1101 1110 unsigned char buf[16]; 1102 1111 unsigned char group; 1103 - unsigned long flags; 1104 1112 const int dir = SNDRV_RAWMIDI_STREAM_INPUT; 1105 1113 int size; 1106 1114 1107 1115 size = snd_ump_convert_from_ump(src, buf, &group); 1108 1116 if (size <= 0) 1109 1117 return; 1110 - spin_lock_irqsave(&ump->legacy_locks[dir], flags); 1118 + guard(spinlock_irqsave)(&ump->legacy_locks[dir]); 1111 1119 substream = ump->legacy_substreams[dir][group]; 1112 1120 if (substream) 1113 1121 snd_rawmidi_receive(substream, buf, size); 1114 - spin_unlock_irqrestore(&ump->legacy_locks[dir], flags); 1115 1122 } 1116 1123 1117 1124 /* Fill ump->legacy_mapping[] for groups to be used for legacy rawmidi */