* The parameters must be set before the stream is started, and must not be
  * changed while the stream is running.
  */
-void amdtp_stream_set_parameters(struct amdtp_stream *s,
-                                unsigned int rate,
-                                unsigned int pcm_channels,
-                                unsigned int midi_ports)
+int amdtp_stream_set_parameters(struct amdtp_stream *s,
+                               unsigned int rate,
+                               unsigned int pcm_channels,
+                               unsigned int midi_ports)
 {
        unsigned int i, sfc, midi_channels;
 
        if (WARN_ON(amdtp_stream_running(s)) |
            WARN_ON(pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM) |
            WARN_ON(midi_channels > AMDTP_MAX_CHANNELS_FOR_MIDI))
-               return;
+               return -EINVAL;
 
-       for (sfc = 0; sfc < ARRAY_SIZE(amdtp_rate_table); ++sfc)
+       for (sfc = 0; sfc < ARRAY_SIZE(amdtp_rate_table); ++sfc) {
                if (amdtp_rate_table[sfc] == rate)
-                       goto sfc_found;
-       WARN_ON(1);
-       return;
+                       break;
+       }
+       if (sfc == ARRAY_SIZE(amdtp_rate_table))
+               return -EINVAL;
 
-sfc_found:
        s->pcm_channels = pcm_channels;
        s->sfc = sfc;
        s->data_block_quadlets = s->pcm_channels + midi_channels;
         * (The value here is adjusted for midi_ratelimit_per_packet().)
         */
        s->midi_fifo_limit = rate - MIDI_BYTES_PER_SECOND * s->syt_interval + 1;
+
+       return 0;
 }
 EXPORT_SYMBOL(amdtp_stream_set_parameters);
 
 
                      enum cip_flags flags);
 void amdtp_stream_destroy(struct amdtp_stream *s);
 
-void amdtp_stream_set_parameters(struct amdtp_stream *s,
-                                unsigned int rate,
-                                unsigned int pcm_channels,
-                                unsigned int midi_ports);
+int amdtp_stream_set_parameters(struct amdtp_stream *s,
+                               unsigned int rate,
+                               unsigned int pcm_channels,
+                               unsigned int midi_ports);
 unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);
 
 int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed);
 
        index = get_formation_index(rate);
        pcm_channels = bebob->tx_stream_formations[index].pcm;
        midi_channels = bebob->tx_stream_formations[index].midi;
-       amdtp_stream_set_parameters(&bebob->tx_stream,
-                                   rate, pcm_channels, midi_channels * 8);
+       err = amdtp_stream_set_parameters(&bebob->tx_stream, rate,
+                                         pcm_channels, midi_channels * 8);
+       if (err < 0)
+               goto end;
+
        pcm_channels = bebob->rx_stream_formations[index].pcm;
        midi_channels = bebob->rx_stream_formations[index].midi;
-       amdtp_stream_set_parameters(&bebob->rx_stream,
-                                   rate, pcm_channels, midi_channels * 8);
+       err = amdtp_stream_set_parameters(&bebob->rx_stream, rate,
+                                         pcm_channels, midi_channels * 8);
+       if (err < 0)
+               goto end;
 
        /* establish connections for both streams */
        err = cmp_connection_establish(&bebob->out_conn,
 
                stream->double_pcm_frames = false;
        }
 
-       amdtp_stream_set_parameters(stream, rate, pcm_chs, midi_ports);
+       err = amdtp_stream_set_parameters(stream, rate, pcm_chs, midi_ports);
+       if (err < 0)
+               goto end;
+
        if (mode > 1) {
                pcm_chs /= 2;
 
 
                midi_ports = efw->midi_in_ports;
        }
 
-       amdtp_stream_set_parameters(stream, sampling_rate,
-                                   pcm_channels, midi_ports);
+       err = amdtp_stream_set_parameters(stream, sampling_rate,
+                                         pcm_channels, midi_ports);
+       if (err < 0)
+               goto end;
 
        /*  establish connection via CMP */
        err = cmp_connection_establish(conn,
 
                err = -EINVAL;
                goto end;
        }
-       amdtp_stream_set_parameters(stream, rate, pcm_channels, midi_ports);
+       err = amdtp_stream_set_parameters(stream, rate,
+                                         pcm_channels, midi_ports);
+       if (err < 0)
+               goto end;
 
        err = cmp_connection_establish(conn,
                                       amdtp_stream_get_max_payload(stream));