if (err < 0)
                goto end;
 
+       mutex_lock(&bebob->mutex);
        atomic_inc(&bebob->substreams_counter);
        err = snd_bebob_stream_start_duplex(bebob, 0);
+       mutex_unlock(&bebob->mutex);
        if (err < 0)
                snd_bebob_stream_lock_release(bebob);
 end:
        if (err < 0)
                goto end;
 
+       mutex_lock(&bebob->mutex);
        atomic_inc(&bebob->substreams_counter);
        err = snd_bebob_stream_start_duplex(bebob, 0);
+       mutex_unlock(&bebob->mutex);
        if (err < 0)
                snd_bebob_stream_lock_release(bebob);
 end:
 {
        struct snd_bebob *bebob = substream->rmidi->private_data;
 
+       mutex_lock(&bebob->mutex);
        atomic_dec(&bebob->substreams_counter);
        snd_bebob_stream_stop_duplex(bebob);
+       mutex_unlock(&bebob->mutex);
 
        snd_bebob_stream_lock_release(bebob);
        return 0;
 {
        struct snd_bebob *bebob = substream->rmidi->private_data;
 
+       mutex_lock(&bebob->mutex);
        atomic_dec(&bebob->substreams_counter);
        snd_bebob_stream_stop_duplex(bebob);
+       mutex_unlock(&bebob->mutex);
 
        snd_bebob_stream_lock_release(bebob);
        return 0;
 
        if (err < 0)
                return err;
 
-       if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
+       if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+               mutex_lock(&bebob->mutex);
                atomic_inc(&bebob->substreams_counter);
+               mutex_unlock(&bebob->mutex);
+       }
 
        amdtp_am824_set_pcm_format(&bebob->tx_stream, params_format(hw_params));
 
        if (err < 0)
                return err;
 
-       if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
+       if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+               mutex_lock(&bebob->mutex);
                atomic_inc(&bebob->substreams_counter);
+               mutex_unlock(&bebob->mutex);
+       }
 
        amdtp_am824_set_pcm_format(&bebob->rx_stream, params_format(hw_params));
 
 {
        struct snd_bebob *bebob = substream->private_data;
 
-       if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+       if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
+               mutex_lock(&bebob->mutex);
                atomic_dec(&bebob->substreams_counter);
+               mutex_unlock(&bebob->mutex);
+       }
 
        snd_bebob_stream_stop_duplex(bebob);
 
 {
        struct snd_bebob *bebob = substream->private_data;
 
-       if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)
+       if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) {
+               mutex_lock(&bebob->mutex);
                atomic_dec(&bebob->substreams_counter);
+               mutex_unlock(&bebob->mutex);
+       }
 
        snd_bebob_stream_stop_duplex(bebob);
 
 
        unsigned int curr_rate;
        int err = 0;
 
-       mutex_lock(&bebob->mutex);
-
        /* Need no substreams */
        if (atomic_read(&bebob->substreams_counter) == 0)
                goto end;
                }
        }
 end:
-       mutex_unlock(&bebob->mutex);
        return err;
 }
 
                master = &bebob->tx_stream;
        }
 
-       mutex_lock(&bebob->mutex);
-
        if (atomic_read(&bebob->substreams_counter) == 0) {
                amdtp_stream_pcm_abort(master);
                amdtp_stream_stop(master);
 
                break_both_connections(bebob);
        }
-
-       mutex_unlock(&bebob->mutex);
 }
 
 void snd_bebob_stream_update_duplex(struct snd_bebob *bebob)