mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Zhang Cen <rollkingzzc@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	zerocling0077@gmail.com, 2045gemini@gmail.com
Subject: Re: [PATCH] ALSA: seq: midi: Serialize output teardown with event_input
Date: Wed, 27 May 2026 07:34:29 +0200	[thread overview]
Message-ID: <87wlwpwh3u.wl-tiwai@suse.de> (raw)
In-Reply-To: <20260526152608.1250473-1-rollkingzzc@gmail.com>

On Tue, 26 May 2026 17:26:08 +0200,
Zhang Cen wrote:
> @@ -125,31 +128,44 @@ static int event_process_midi(struct snd_seq_event *ev, int direct,
>  	struct seq_midisynth *msynth = private_data;
>  	unsigned char msg[10];	/* buffer for constructing midi messages */
>  	struct snd_rawmidi_substream *substream;
> +	unsigned long flags;
> +	int err = 0;
>  	int len;
>  
>  	if (snd_BUG_ON(!msynth))
>  		return -EINVAL;
> +
> +	spin_lock_irqsave(&msynth->output_lock, flags);
>  	substream = msynth->output_rfile.output;
> -	if (substream == NULL)
> +	if (substream)
> +		snd_use_lock_use(&msynth->output_use_lock);
> +	spin_unlock_irqrestore(&msynth->output_lock, flags);
> +
> +	if (!substream)
>  		return -ENODEV;

Please use scoped_guard().  You can drop flags with it, and the return
-ENODEV can be right after substream assignment.

> @@ -229,12 +249,15 @@ static int midisynth_use(void *private_data, struct snd_seq_port_subscribe *info
>  	params.avail_min = 1;
>  	params.buffer_size = output_buffer_size;
>  	params.no_active_sensing = 1;
> -	err = snd_rawmidi_output_params(msynth->output_rfile.output, &params);
> +	err = snd_rawmidi_output_params(rfile.output, &params);
>  	if (err < 0) {
> -		snd_rawmidi_kernel_release(&msynth->output_rfile);
> +		snd_rawmidi_kernel_release(&rfile);
>  		return err;
>  	}
>  	snd_midi_event_reset_decode(msynth->parser);
> +	spin_lock_irqsave(&msynth->output_lock, flags);
> +	msynth->output_rfile = rfile;
> +	spin_unlock_irqrestore(&msynth->output_lock, flags);
>  	return 0;

Ditto, use guard() or scoped_guard().

> @@ -242,11 +265,20 @@ static int midisynth_use(void *private_data, struct snd_seq_port_subscribe *info
>  static int midisynth_unuse(void *private_data, struct snd_seq_port_subscribe *info)
>  {
>  	struct seq_midisynth *msynth = private_data;
> +	struct snd_rawmidi_file rfile = {};
> +	unsigned long flags;
>  
> -	if (snd_BUG_ON(!msynth->output_rfile.output))
> +	spin_lock_irqsave(&msynth->output_lock, flags);
> +	rfile = msynth->output_rfile;
> +	msynth->output_rfile = (struct snd_rawmidi_file){};
> +	spin_unlock_irqrestore(&msynth->output_lock, flags);
> +
> +	if (snd_BUG_ON(!rfile.output))
>  		return -EINVAL;

Same here, too.


thanks,

Takashi

  reply	other threads:[~2026-05-27  5:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 15:26 Zhang Cen
2026-05-27  5:34 ` Takashi Iwai [this message]
2026-05-27  6:22   ` Cen Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wlwpwh3u.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=2045gemini@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=rollkingzzc@gmail.com \
    --cc=zerocling0077@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®