Skip to content

Commit

Permalink
sound: rawmidi: fix double init when opening MIDI device with O_APPEND
Browse files Browse the repository at this point in the history
Commit 9a1b64c in 2.6.30 moved the
substream initialization code to where it would be executed every time
the substream is opened.

This had the consequence that any further opening would drop and leak
the data in the existing buffer, and that the device driver's open
callback would be called multiple times, unexpectedly.

Signed-off-by: Clemens Ladisch <[email protected]>
Cc: <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
cladisch authored and tiwai committed Nov 10, 2009
1 parent dede17b commit 8579d2d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sound/core/rawmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,19 @@ static int open_substream(struct snd_rawmidi *rmidi,
{
int err;

err = snd_rawmidi_runtime_create(substream);
if (err < 0)
return err;
err = substream->ops->open(substream);
if (err < 0)
return err;
substream->opened = 1;
if (substream->use_count++ == 0)
if (substream->use_count == 0) {
err = snd_rawmidi_runtime_create(substream);
if (err < 0)
return err;
err = substream->ops->open(substream);
if (err < 0)
return err;
substream->opened = 1;
substream->active_sensing = 0;
if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
substream->append = 1;
if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
substream->append = 1;
}
substream->use_count++;
rmidi->streams[substream->stream].substream_opened++;
return 0;
}
Expand Down

0 comments on commit 8579d2d

Please sign in to comment.