[alsa-devel] [PATCH 24/44] fireworks: Add MIDI interface

Takashi Sakamoto o-takashi at sakamocchi.jp
Sun Apr 6 14:03:19 CEST 2014

Hi Clemens,

(Apr 4 2014 06:20), Clemens Ladisch wrote:
>> +++ b/sound/firewire/fireworks/fireworks_midi.c
>> +static int midi_capture_open(struct snd_rawmidi_substream *substream)
>> +{
>> +	struct snd_efw *efw = substream->rmidi->private_data;
>> +
>> +	efw->capture_substreams++;
> The MIDI .open callback is not synchronized with the PCM callbacks;
> this might race and must be protected with a mutex.

Exactly. And I've realized it.

The race appears between some processes to handle substream counter at 
the same time. The counter is changed by below operations:
  PCM  .hw_param/.hw_free
  MIDI .open/.close

I'm optimistic for this issue and I thought usual users rarely execute 
these operations at the same time. So I kept this issue pending for my 
future because I have some issues with higher priority than this issue.

Well, for this issue, I think it better to use atomic_t for substream 
counter than mutex. The way to use mutex is propper for MIDI 
.open/.close because these functions also execure stream_start_duplex() 
/ stream_stop_duplex() (then I must move mutex_lock/mutex_unlock from 
stream.c). But PCM .hw_param/.hw_free just increment / decrement 
substream counter. I think it consts expensive than such simple operation.


Takashi Sakamoto
o-takashi at sakamocchi.jp

More information about the Alsa-devel mailing list