Commit 6487e363 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: seq: 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: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240227085306.9764-19-tiwai@suse.de
parent 45bab301
...@@ -115,21 +115,19 @@ static int seq_ump_process_event(struct snd_seq_event *ev, int direct, ...@@ -115,21 +115,19 @@ static int seq_ump_process_event(struct snd_seq_event *ev, int direct,
static int seq_ump_client_open(struct seq_ump_client *client, int dir) static int seq_ump_client_open(struct seq_ump_client *client, int dir)
{ {
struct snd_ump_endpoint *ump = client->ump; struct snd_ump_endpoint *ump = client->ump;
int err = 0; int err;
mutex_lock(&ump->open_mutex); guard(mutex)(&ump->open_mutex);
if (dir == STR_OUT && !client->opened[dir]) { if (dir == STR_OUT && !client->opened[dir]) {
err = snd_rawmidi_kernel_open(&ump->core, 0, err = snd_rawmidi_kernel_open(&ump->core, 0,
SNDRV_RAWMIDI_LFLG_OUTPUT | SNDRV_RAWMIDI_LFLG_OUTPUT |
SNDRV_RAWMIDI_LFLG_APPEND, SNDRV_RAWMIDI_LFLG_APPEND,
&client->out_rfile); &client->out_rfile);
if (err < 0) if (err < 0)
goto unlock; return err;
} }
client->opened[dir]++; client->opened[dir]++;
unlock: return 0;
mutex_unlock(&ump->open_mutex);
return err;
} }
/* close the rawmidi */ /* close the rawmidi */
...@@ -137,11 +135,10 @@ static int seq_ump_client_close(struct seq_ump_client *client, int dir) ...@@ -137,11 +135,10 @@ static int seq_ump_client_close(struct seq_ump_client *client, int dir)
{ {
struct snd_ump_endpoint *ump = client->ump; struct snd_ump_endpoint *ump = client->ump;
mutex_lock(&ump->open_mutex); guard(mutex)(&ump->open_mutex);
if (!--client->opened[dir]) if (!--client->opened[dir])
if (dir == STR_OUT) if (dir == STR_OUT)
snd_rawmidi_kernel_release(&client->out_rfile); snd_rawmidi_kernel_release(&client->out_rfile);
mutex_unlock(&ump->open_mutex);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment